I have a dropdown location see markup below.
<asp:DropDownList ID="ddllocation" runat="server" AppendDataBoundItems="true" AutoPostBack="true"
CssClass="form-control pro-edt-select form-control-primary" Width="100%" >
<asp:ListItem Text="--Select Location--" />
<asp:ListItem>Branch1</asp:ListItem>
<asp:LinkButton ID="btlocation" runat="server" CssClass="btn btn-default" OnClick="btlocation_Click" >Call Location</asp:LinkButton>
The dropdown ddllocation when selected it supposed to pull names from database base on location and then display the name on ddlprocessedby but is not working.
<asp:DropDownList ID="ddlprocessedby" runat="server" AppendDataBoundItems="true"
CssClass="form-control pro-edt-select form-control-primary" Width="100%" >
</asp:DropDownList>
see code below
protected void btlocation_Click(object sender, EventArgs e)
{
string constr = ConfigurationManager.ConnectionStrings["DB"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
SqlCommand command = new SqlCommand("SELECT Name FROM User3 WHERE [Location]='@Branch1'", con);
command.Parameters.AddWithValue("@Branch1", ddllocation.Text);
con.Open();
SqlDataReader sdr = command.ExecuteReader();
if (sdr.Read())
{
ddlprocessedby.SelectedItem.Text = sdr["Name"].ToString();
}
}
}
In database table i have this below
UserId Name, Location
----------------------
1 Jake Branch1
2 Mary Branch2
3 John Branch1
So the idea is when location dropdown is selected and button pull location is clicked the names in those locations will be displayed on the dropdown ddlprocessedby.