I am trying to populate multiple DropDownList on same page using same stored procedure in asp .net
Following is my code:
1) Page Load Event
if(!Page.IsPostBack){
fillDropDown(SearchByBrand);
fillDropDown(SearchByBrand1);
}
2) fillDropDown Method
protected void fillDropDown(DropDownList list) {
try
{
cmd = new SqlCommand("fillDropdownWithBrandName", conn);
cmd.CommandType = CommandType.StoredProcedure;
reader = cmd.ExecuteReader();
list.DataSource = reader;
list.DataTextField = "BrandName";
list.DataValueField = "BrandID";
list.DataBind();
list.Items.Insert(0, new ListItem("--Select Brand--", "0"));
}
catch(Exception e){
errorMessage = e.StackTrace;
}
finally{
cmd.Dispose();
conn.Close();
}
}
3) DropdownList That I have used 1st DropDown
<asp:DropDownList ID="SearchByBrand" CssClass="form-control" runat="server">
</asp:DropDownList>
2nd Dropdown list is in UpdatePanel which is further inside bootstrap modal which gets open on button Click.
<asp:DropDownList ID="SearchByBrand1" CssClass="form-control" runat="server">
</asp:DropDownList>
Stored Procedure
ALTER PROCEDURE fillDropdownWithBrandName
AS
BEGIN
SELECT BrandID,BrandName FROM Brand
END
Only One DropdownList Gets populated. What could be the problem?