Hello everyone,
In this post, i'm going to share to code-sample for bind country list in dropdownlist in asp.net using C#.
This example is simple and easily understandable DropDownList code-sample using asp.net with c#
Table of Contents
1. In the 1st steps, code-sample for aspx page
2. In the 2nd steps, code-sample for C# (.cs page)
In the 1st step, we write the code for view in asp.net page i.e. .aspx
In the 2nd step, we write the code for cs file in asp.net page i.e. .aspx.cs
In this post, i'm going to share to code-sample for bind country list in dropdownlist in asp.net using C#.
This example is simple and easily understandable DropDownList code-sample using asp.net with c#
Table of Contents
1. In the 1st steps, code-sample for aspx page
2. In the 2nd steps, code-sample for C# (.cs page)
In the 1st step, we write the code for view in asp.net page i.e. .aspx
<asp:DropDownList ID="DDLLocation" runat="server" OnSelectedIndexChanged="DDLLocation_SelectedIndexChanged"
AutoPostBack="true">
<asp:ListItem Text="Select
Location" Selected="true"></asp:ListItem>
<asp:ListItem Value="Nda">Utter
Pradesh</asp:ListItem>
<asp:ListItem Value="chi">Delhi</asp:ListItem>
<asp:ListItem Value="Ambd">Ranchi</asp:ListItem>
<asp:ListItem Value="us">USA</asp:ListItem>
<asp:ListItem Value="kral">Kerela</asp:ListItem>
</asp:DropDownList>
/// <summary>
/// DropdownList Selected Index Changed evets.
/// </summary>
protected void
DDLLocation_SelectedIndexChanged(object sender,
EventArgs e)
{
getRecordbyLocation();
}
/// <summary>
/// Get the Country details and bind the data in
grid view.
/// </summary>
public void
getRecordbyLocation()
{
String connString =
ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
SqlDataAdapter da = new SqlDataAdapter("SP_getRecords", connString);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
da.SelectCommand.Parameters.AddWithValue("@Location",
DDLLocation.SelectedItem.Text);
DataSet dsObj = new
DataSet();
da.Fill(dsObj);
GridViewID.DataSource = dsObj.Tables[0];
GridViewID.DataBind();
}