Passing value through path using postback url - asp.net

I am using a datalist on customer page to list all customers. There is a page named "view" where I want to show the details of the particular selected customer. Here is the image button code:
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl='<%# GetImageURL(Eval("image")) %>' PostBackUrl='<%# Eval("id", "view.aspx?id={0}") %>'/></tr>
id is the unique field of the customer table. Now how should I retrieve the customer data on view.aspx, using the particular ID passed from the customer page. I use this code but it's not working:
Dim mycommand As New SqlCommand("SELECT * FROM customer where id = #id", con)
Int(ID = Request.QueryString("id"))
con.Open()
ProfileData.DataSource = mycommand.ExecuteReader
ProfileData.DataBind()
con.Close()
I just want to do that. In the customer page all customers are displayed with their image and when I click on any one of them then the details of the particular customer should be displayed on view.aspx page ..

you are using #id as CommandParameter to add this id as value to command parameter..
as
Dim mycommand As New SqlCommand("SELECT * FROM customer where id = #id", con)
mycommand.Parameters.Add("#id", SqlDbType.Int)
mycommand.Parameters("#id").Value = Convert.ToInt32( Request.QueryString("id"))
con.Open()
ProfileData.DataSource = mycommand.ExecuteReader
ProfileData.DataBind()
con.Close()
check these link to know about the parameter..
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.parameters.aspx
http://msdn.microsoft.com/en-us/library/yy6y35y8%28v=vs.80%29.aspx

Related

Send email to multiple users from listview

I want to get users email id in listview and whatever email generated by listview according to query. Now on send click I want all email id generated by listview to get that email.
I know how to bind listview but how can I get email to send mail?
Private Sub BindListView()
Dim constr As String = ConfigurationManager.ConnectionStrings("conio2").ConnectionString
Using con As New MySqlConnection(constr)
Using cmd As New MySqlCommand()
cmd.CommandText = "SELECT email FROM users where city = 'new york' order by ID asc"
cmd.Connection = con
Using sda As New MySqlDataAdapter(cmd)
Dim dt As New DataTable()
sda.Fill(dt)
emailList.DataSource = dt
emailList.DataBind()
End Using
End Using
End Using
End Sub
Suppose if you have ListView defined as below in the HTML part:
<asp:ListView ID="emailList" runat="server" ConvertEmptyStringToNull="False">
<ItemTemplate>
<asp:Label Text='<%# Eval("Email") %>' runat="server" ID="lblEmail"></asp:Label>
</ItemTemplate>
</asp:ListView>
You can enumerate over all the ListViewItems, get the Email IDs from the Label, and join it into a string str separated by comma (,) which can then be directly utilized for sending the email to multiple recipients.
Dim str As String = ""
For Each li As ListViewItem In emailList.Items
Dim lbl As Label = CType(li.FindControl("lblEmail"), Label)
If lbl.Text <> "" Then
str = str + lbl.Text + ","
End If
Next
str = str.Substring(0, str.Length - 1)
Use str within the message sending code as message.cc.Add(str)
where message is the object of System.Net.Mail.MailMessage
From what I understand you have some function (or sub), that sends e-mails and you just need to provide data to that function.
For simplicity let's name this:
Private Sub SendEmail(address as string, title as string, body as string)
I have also added two TextBoxes:
TextBoxTitle for holding e-mail title and
TextBoxBody for holding e-mail body
Here's the code:
Private Sub SendEmail_Click(sender As Object, e As EventArgs) Handles SendEmail.Click
For Each item As ListViewItem In emailList.Items
SendEmail(item.SubItems.Item(0).Text, TextBoxTitle.Text, TextBoxBody.Text)
Next
End Sub

Radsearchbox not displaying selected text

I am using radsearchbox in my application. The data source is working and showing the values in dropdown but when I select an item in the dropdown the textbox is not populating. My code is
<telerik:RadSearchBox ID="RadSearchBox1" runat="server"
Filter="StartsWith" EnableAutoComplete="true" DataTextField="Name">
</telerik:RadSearchBox>
and in code
string comtext = "select Name from tblcustomer";
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString);
SqlCommand cmd = new SqlCommand(comtext, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
RadSearchBox1.DataSource = ds;
RadSearchBox1.DataBind();
Your issue might be that you are not using a SearchContext. But I think that you just need to specify the key field for the search box. Note below, the parameter DataValueField pointed at the ID for your table. (Change to your particular table id field)
<telerik:RadSearchBox ID="RadSearchBox1"
runat="server"
DataTextField="Name"
DataValueField="TableID" >
</telerik:RadSearchBox>
You would also need to change your query string to include the ID in the dataset.
string comtext = "select Name, TableID from tblcustomer";
Telerik's RadSearch demo page can give examples of how to use SearchContext if needed.

vb.net: Why does Email-form return the ID of the value in a dropdown list as oppose to the text

I have a form written in vb.net. Upon clicking the submit button, the information in the form is emailed over to a specific email address. The form successfully captures the information from my text-box controls, but for the Dropdownlist controls, it brings back the ID of the list-item as oppose to the text.
Hypertext:
<asp:DropDownList ID="ddlCarrier" runat="server" DataTextField="Carrier_Name"
DataValueField="Carrier_ID">
</asp:DropDownList>
The original developer has it set to where the list-items are bind to the dropdown-list via the following code snippet, which uses a global variable: "dl" to access another function stored in a dataLayer file:
Dim dl As New DataLayer
Me.ddlCarrier.DataSource = dl.GetCarriers
Me.ddlCarrier.DataBind()
Me.ddlCarrier.DataTextField = "carrier_name"
Me.ddlCarrier.DataValueField = "carrier_id"
...Function that is stored in the dataLayer file:
Public Function GetCarriers() As DataTable
Dim connectionString As String = ConfigurationManager.ConnectionStrings("ShipperNotificationConnectionString").ConnectionString
Dim myCommand As SqlDataAdapter
myCommand = New SqlDataAdapter("SELECT carrier_id,carrier_code,carrier_name,active from Carrier", connectionString)
Dim dtCarriers As DataTable = New DataTable()
myCommand.Fill(dtCarriers)
Return dtCarriers
End Function
lastly, the code snippet used the in the email function:
"<tr><td><b>Carrier:</b>" + ddlCarrier.SelectedValue.ToString() + "</td></tr>" & _
...The dropdownlist successfully populates the text, but when submitted via the form, I get the ID instead of the text itself. Could I get some help as to what I'm missing?
Instead of ddlCarrier.SelectedValue try ddlCarrier.SelectedItem.Text

Hyperlink in DataField of GridView ASP.net

I have a GridView with rows and lines. In lines i've put names (e.g. John, Jack, Paul,...) and in the rows the statistics (e.g work hours, salary, status,...). I don't know how to set an hyperlink on the name in order to open a page with the entire profile of the person selected. I want to click on Paul and be redirected to another page with the entire profile plus the photo and other info. Each name must have a different hyperlink. I tried to do it through Access directly but didn't work.
Thank You
Richard
you should use this line of code in the gridview.Add the hyperlink in gridview and edit this code to make it functioning.
<asp:hyperlinkfield text="Name?"
datanavigateurlfields="Id"
datanavigateurlformatstring="~\Persondetails.aspx?id={0}" //passing the Id to new page
headertext="Name"
target="_blank" />
at the second page you should write the code like this to make sure display the selected nama display all detail in second page.
Dim nameID As String
nameID = Request.QueryString("id")
Dim nameqstring As Integer = Convert.ToInt32(nameID)
to display data from selected second page use this one
Using sqlComm As New MySqlCommand()
sqlComm.Connection = sqlConn
With sqlComm
.CommandText = "select * From table where NameId=#nameId"
.Parameters.AddWithValue("#nameId", nameID)
Try
Dim sqlReader As MySqlDataReader = sqlComm.ExecuteReader()
While sqlReader.Read()
Label1.Text = sqlReader("Name").ToString()
Label2.Text = sqlReader("Job").ToString()
Label3.Text = sqlReader("Salary").ToString()
Label4.Text = sqlReader("Workhours").ToString()
Label5.Text = sqlReader("Status").ToString()
End While End Using End Using
hope this can help you alot.

Add values from DB (Select Query) in a text. Asp.net

On my Homepage i made i Visual Studio i want to have some welcome text on my firstpage.
The Thing is that i want in the middle of the text present some values that i grab from my db with a select query.
Lets say for example:
Welcome to my Homepage!
Currently there are (Select Count(UserID) FROM users where Status = 'active') Users active on my page and (Select Count(UserID) FROM users where Status = 'inactive') that are inactive.
Im really new to this but somehow i Need to run the my questions on Page_load and then be able to take that value and present it in a Label or something?
Thanks for your help
Using ADO.NET:
1: Create a connection object, set it's connection string property
2: Create a command object and set its text property to
Select Count(UserID) FROM users where Status = 'active'
3: Use ExecuteScalar method of the command object to find the result you want and set the label text property equal to that result.
Procedure
create procedure select
#activity
as
Begin
Select Count(UserID) FROM users where Status = #activity
end
C# Page Load
string activity1="active";
string activity2="Inactive";
sqlconnection con=new sqlconnection("give your connection string");
sqlcommand cmd=new sqlcommand();
cmd=new sqlcommand("select",con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("#activity",activity1);
String result1=cmd.ExecuteNonQuery();
sqlcommand cmd1=new sqlcommand();
cmd1=new sqlcommand("select",con);
cmd1.CommandType = CommandType.StoredProcedure;
cmd1.Parameters.AddWithValue("#activity",activity2);
String result2=cmd.ExecuteNonQuery();
Label1.Text=result1;
Label2.Text=result2;
.aspx page
Welcome to my HomePage
Currently there are <asp:label id="Label1" runat="server"></asp:Label> Users active on my page and <asp:label id="Label2" runat="server"></asp:Label> that are inactive.
If you find this as useful and it solved your issue mark it as answer and give upvote.
Try this
if (!IsPostBack)
{
SqlConnection con = new SqlConnection(#"MY CONNECTION");
SqlCommand com = new SqlCommand("Select Count(UserID) FROM users where Status = 'active'", con);
SqlDataReader dr;
con.Open();
while (dr.Read())
{
Debug.WriteLine(dr[0].ToString());
}
con.Close();
}

Resources