Reputation: 305
I have a drop down menu that retrieved ID from database and four labels. From the user id, the labels will display data that belongs to the ID. In my case, the ID only has 1 value which it makes the auto post back not refresh the page. Is there any ways to make the labels show the data?
<asp:DropDownList ID="DropDownList5" runat="server"
DataSourceID="SqlDataSource3" DataTextField="Id" DataValueField="Id"
Height="16px" Width="145px" AutoPostBack="True"
onselectedindexchanged="DropDownList5_SelectedIndexChanged">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:Connection %>"
SelectCommand="SELECT [Id] FROM [Rsvp] WHERE (([Model] = @Model) AND ([Username] = @Username))">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList2" Name="Model"
PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="DropDownList3" Name="Username"
PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
Upvotes: 2
Views: 577
Reputation: 103365
Set the AppendDataBoundItems
property to true
on the dropdown list and the items from the data source will appear after any ListItems you add in the markup e.g.
<asp:DropDownList ID="DropDownList5" runat="server"
DataSourceID="SqlDataSource3" DataTextField="Id" DataValueField="Id"
Height="16px" Width="145px" AutoPostBack="True" OnSelectedIndexChanged="DropDownList5_SelectedIndexChanged" AppendDataBoundItems="true">
<asp:ListItem Value="-" Text="Select an option" Selected="True"/>
</asp:DropDownList>
Upvotes: 1
Reputation: 2921
Insert a new Item at 0, at the top:
DropDownList5.Items.Insert(0,new ListItem("Select an option","-"));
Upvotes: 2