2

データベースから ID を取得するドロップダウン メニューと 4 つのラベルがあります。ユーザー ID から、ラベルには ID に属するデータが表示されます。私の場合、ID には値が 1 つしかないため、自動ポストバックでページが更新されません。ラベルにデータを表示させる方法はありますか?

  <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>
4

2 に答える 2

2

上部の 0 に新しいアイテムを挿入します。

DropDownList5.Items.Insert(0,new ListItem("Select an option","-"));
于 2012-09-14T08:32:29.660 に答える
1

AppendDataBoundItemsプロパティをtrueドロップダウン リストに設定すると、データ ソースの項目が、マークアップに追加した ListItems の後に表示されます。

<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>
于 2012-09-14T08:41:12.373 に答える