0

したがって、2つのドロップダウンリストがあります。最初のドロップダウンリストには、GUIDと静的アイテムの値を持つデータソースからのアイテムが含まれています。

<asp:DropDownList runat="server" ID="CategoryDDL" DataSourceID="SqlDataSource1" DataTextField="Name" DataValueField="categoryID" AutoPostBack="True" AppendDataBoundItems="True" >
     <asp:ListItem Value="(Select Category)">(New Category)</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionString%>" SelectCommand="SELECT categoryID, Name FROM category"></asp:SqlDataSource>

他のドロップダウンリストは非常に似ていますが、最初の値を読み取るように設定された制御パラメーターとして、静的アイテムが含まれています。

<asp:DropDownList runat="server" ID="itemDDL" DataSourceID="SqlDataSource2" DataTextField="item" DataValueField="itemID">
      <asp:ListItem Value="(Select Item)">(New Question)</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionString%>" SelectCommand="SELECT itemID, categoryID, item FROM Items WHERE (categoryID = @categoryID)">
    <SelectParameters>
            <asp:ControlParameter ControlID="CategoryDDL" Name="categoryID" PropertyName="SelectedValue" />
      </SelectParameters>
</asp:SqlDataSource>

ドロップダウンリストで最初の値が2番目の値に存在しない場合、その値を無視するようにするにはどうすればよいですか。または、さらに良いことに、コードからSQLデータソースを呼び出してドロップダウンリストに入力する方法はありますか?

4

2 に答える 2

1

2番目のドロップダウンリストに追加OnSelecting="SqlDataSource2_Selecting"され、有効なGUIDを取得できない場合に選択コマンドがキャンセルされるようになりました。

Dim GUIDRef As Guid

Protected Sub SqlDataSource2_Selecting(sender As Object, e As SqlDataSourceSelectingEventArgs) Handles SqlDataSource2.Selecting
    If Not Guid.TryParse(CategoryDDL.SelectedValue, GUIDRef) Then
        e.Cancel = True
    End If

End Sub
于 2012-08-15T09:04:51.673 に答える
0

あなたの質問を明確に理解していませんが、ドロップダウンリストの SelectedIndexChanged を使用する必要があると思います

private void itemDDL_SelectedIndexChanged()
{
      // check the item in the first dropdown and do your work
} 
于 2012-08-08T19:42:10.007 に答える