Monday, 26 August 2013

How to populate a combobox with SQL Server stored procedure

How to populate a combobox with SQL Server stored procedure

Using: asp.net and C#
I'm trying to populate a combobox with values from a SQL Server stored
procedure. I have the combobox loading and working, but I don't know how
to make the values show up as a drop down list for the customer to choose.
Also is ListItem the correct way to load the drop down menu?
Here is what I have so far:
.aspx page:
<asp:ToolkitScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ComboBox ID="ComboBox1" runat="server" DataSourceID="SQL"
DataTextField="DataText" DataValueField="DataValue" MaxLength="0"
style="display: inline;">
<asp:ListItem Value="0">Please Choose an
Item......</asp:ListItem>
//What do I put here to load and display the stored procedure
in a list
</asp:ComboBox>
<asp:SqlDataSource ID="SQL1" runat="server"
ConnectionString="<%$ CompanyConnectionString %>"
SelectCommand="CompanyStoredProcedure"
SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter Name="ParameterID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</asp:ToolkitScriptManager>

No comments:

Post a Comment