如何使用asp.net获取listview中动态下拉列表的数据

时间:2014-04-08 06:07:52

标签: asp.net listview

我有一个列表视图,其中包含两列类型' dropdown'。从第一个下拉列表中选择值应相应地加载第二个下拉列表的值。 为此,我有下面的aspx:

<InsertItemTemplate>
            <tr style="" class="tblB">
                <td class="tblB">
                    <asp:Button ID="InsertButton" runat="server" CommandName="Insert" CssClass="iBtn"
                        Text="Insert" />
                    <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" CssClass="iBtn"
                        Text="Clear" />
                </td>
                <td class="tblB">
                    <asp:HiddenField ID="hidFilter" runat="server" Value='<%# Eval("Filter") %>' />
                    <asp:TextBox ID="FilterTextBox" runat="server" Text='<%# Bind("Filter") %>' Width="100%"></asp:TextBox>
                </td>
                <td class="tblB">
                    <asp:HiddenField ID="hidFilterDesc" runat="server" Value='<%# Eval("FilterDesc") %>' />
                    <asp:TextBox ID="FilterDescTextBox" runat="server" Width="100%" Text='<%# Bind("FilterDesc") %>' />
                </td>
                <td class="tblB" align="center">
                    <asp:DropDownList ID="ddlActiveFlag" runat="server" SelectedValue='<%# Bind("ActiveFlag") %>'
                        Font-Size="9pt" Font-Names="Calibri">
                        <asp:ListItem Text="Y" Value="Y" />
                        <asp:ListItem Text="N" Value="N" />
                    </asp:DropDownList>
                </td>
                <td class="tblB" align="center">
                    <asp:DropDownList ID="ddlBizCriticality" runat="server" SelectedValue='<%# Bind("BizCriticality") %>'
                        Font-Size="9pt" Font-Names="Calibri">
                        <asp:ListItem Text="Critical" Value="H" />
                        <asp:ListItem Text="Important" Value="M" />
                        <asp:ListItem Text="Info" Value="L" />
                        <asp:ListItem Text="False" Value="F" />
                    </asp:DropDownList>
                </td>
                <td class="tblB" align="center">
                    <asp:DropDownList ID="ddlCategory" runat="server" DataSourceID="Sqlacat" DataTextField="ClassificationName"
                        DataValueField="ClassificationId" SelectedValue='<%# Bind("ClassificationId") %>'
                        Font-Size="9pt" Font-Names="Calibri">
                    </asp:DropDownList>
                </td>
                <td class="tblB" width="35%">
                    <asp:TextBox ID="SupportLinkTextBox" runat="server" Width="100%" Text='<%# Bind("SupportLink") %>' />
                </td>
                <td>
                    <asp:DropDownList ID="drpMainCategory" runat="server" DataSourceID="SqlCategory"
                        DataTextField="CategoryName" DataValueField="CategoryId" SelectedValue='<%# Bind("CategoryId") %>'
                        Font-Size="9pt" Font-Names="Calibri" OnSelectedIndexChanged="drpMainCategory_SelectedIndexChanged"
                        AutoPostBack="true">
                    </asp:DropDownList>
                </td>
                <td>
                    <asp:DropDownList ID="drpSubCategory" runat="server" DataSourceID="SqlSubCat" DataTextField="SubCategoryName"
                        DataValueField="SubCategoryId" SelectedValue='<%# Bind("SubCategoryId") %>' Font-Size="9pt"
                        Font-Names="Calibri">
                    </asp:DropDownList>
                </td>
            </tr>
        </InsertItemTemplate>
And the code behind is:
protected void drpMainCategory_SelectedIndexChanged(object sender, EventArgs e)
    {

        DropDownList d = (DropDownList)sender;
        string id = d.ID;
        string drpCat = (string)d.SelectedValue;

        SqlSubCat.SelectCommand = "SELECT '00000000-0000-0000-0000-000000000000' as SubCategoryId, '--Select--' as SubCategoryName from SubCategory UNION SELECT SubCategoryId, SubCategoryName FROM SubCategory inner join Category on Category.CategoryId=SubCategory.CategoryId where SubCategory.CategoryId='" + drpCat + "'";

        ListView1.DataBind();

    }
protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
    {
        if (Page.IsPostBack)
        {
            if (e.Item.ItemType == ListViewItemType.DataItem)
            {
            }
        }
    }

任何人都可以帮助我如何解决这个问题。请恢复以获取更多信息。

0 个答案:

没有答案