selectステートメントで場所のドロップダウンをバインドしています
Select location_id, location_name,businessid from inventory.tbl_location order by location_name
最初の要素を「場所を選択」として配置したい。現在、すべての場所を取得しています。SQLステートメントでデータバインドされているasp.netページのドロップダウンで、初期値をSelectとして設定するにはどうすればよいですか?
In the aspx page :
<asp:DropDownList ID="ddlAllLocations" runat="server" DataSourceID="SqlDataSourceBusinessLocations"
DataTextField="Location_Name" DataValueField="Location_ID" AutoPostBack="True">
</asp:DropDownList>
と
<asp:SqlDataSource ID="SqlDataSourceBusinessLocations" runat="server" ConnectionString="<xxxxxx>"
ProviderName="<%$ zzzzz %>" SelectCommand="Select location_id, location_name,businessid from inventory.tbl_location order by location_name" FilterExpression="businessid in ({0})">
<FilterParameters>
<asp:SessionParameter DefaultValue="0" Name="BUID" SessionField="BusinessUnitIDs" />
</FilterParameters>
</asp:SqlDataSource>
page_load イベントで提案されているようにコードを追加しました。リスト項目に選択場所を追加するたびに、別の問題があります。
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If IsPostBack() Then
lblError.Text = ""
ddlAllLocations.Items.Insert(0, New ListItem("Select location"))
End If
End Sub