当选择第一个DropDownList时,如何在Gridview中启用DropDownList

时间:2016-12-05 01:32:58

标签: asp.net vb.net gridview drop-down-menu

我在ASP.Net中使用我的GridView表。 首先,当我单击GridView中的编辑链接按钮时,我将能够使用文本框和下拉列表对其进行编辑。

这是我的GridView的图像。

GridView

因此,业务部门已启用,但分部,分部,分类和次分类则未启用。 我的问题是,当我选择业务单位时,应该启用下拉列表部门,并且能够根据我选择的业务单位选择值,依此类推。因此,下一个下拉列表将取决于您选择的第一个下拉列表。我已经在互联网上搜索了这个并尝试了不同的解决方案,但我仍然感到困惑,不知道它是如何工作的。

这是我在ASP.Net中的代码

 <asp:GridView ID="gvGroup" runat="server" AllowPaging="false" 
                                AllowSorting="true" AutoGenerateColumns="False" BorderColor="Silver" 
                                BorderWidth="1px" Height="104px" ShowFooter="true" ShowHeader="true" 
                                style="margin-right: 0px" Width="77%">
                                <RowStyle Font-Names="Arial" Font-Size="9pt" HorizontalAlign="Center" />
                                <Columns>
                                    <asp:TemplateField HeaderStyle-BackColor="#666666" 
                                        HeaderStyle-ForeColor="White" HeaderStyle-Width="10px" HeaderText="" 
                                        ItemStyle-Width="10px">
                                        <ItemTemplate>
                                            <%# Container.DataItemIndex + 1 %>
                                        </ItemTemplate>
                                        <HeaderStyle BackColor="#666666" ForeColor="White" />
                                        <ItemStyle Width="10px" />
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="" ItemStyle-Width="140px" Visible="false">
                                        <ItemTemplate>
                                            <asp:Label ID="lblMasterID" runat="server" Text='<%#Bind("MASTERID") %>'></asp:Label>
                                        </ItemTemplate>
                                        <ItemStyle Width="140px" />
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="" ItemStyle-Width="140px" Visible="false">
                                        <ItemTemplate>
                                            <asp:Label ID="lblSEQID" runat="server" Text='<%#Bind("SEQID") %>'></asp:Label>
                                        </ItemTemplate>
                                        <ItemStyle Width="140px" />
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderStyle-BackColor="#666666" HeaderStyle-Font-Size="9pt" 
                                        HeaderStyle-ForeColor="White" HeaderText="Job Title" ItemStyle-Font-Size="9pt" 
                                        ItemStyle-Width="140px">
                                        <ItemTemplate>
                                            <asp:Label ID="lblJobTitle" runat="server" Text='<%#Bind("JOBTITLE") %>' 
                                                Width="140px"></asp:Label>
                                        </ItemTemplate>
                                        <EditItemTemplate>
                                            <asp:TextBox ID="txtJT" runat="server" CssClass="ehr_textbox" 
                                                Text='<%#BIND("JOBTITLE") %>' Width="140px"></asp:TextBox>
                                        </EditItemTemplate>
                                        <FooterTemplate>
                                            <asp:TextBox ID="txtJobTitleAdd" runat="server" Width="110px">
                                            </asp:TextBox>
                                        </FooterTemplate>
                                        <HeaderStyle BackColor="#666666" Font-Size="9pt" ForeColor="White" />
                                        <ItemStyle Font-Size="9pt" Width="140px" />
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderStyle-BackColor="#666666" HeaderStyle-Font-Size="9pt" 
                                        HeaderStyle-ForeColor="White" HeaderText="Business Unit" 
                                        ItemStyle-Font-Size="9pt" ItemStyle-Width="140px">
                                        <ItemTemplate>
                                            <asp:Label ID="lblBusinessUnit" runat="server" 
                                                Text='<%#Bind("BUSINESS_UNIT") %>' Width="140px"></asp:Label>
                                        </ItemTemplate>
                                        <EditItemTemplate>
                                            <asp:DropDownList ID="ddl_gvBusinessUnit" runat="server" CssClass="ehr_dropdown" 
                                                Width="140px">
                                            </asp:DropDownList>
                                        </EditItemTemplate>
                                        <FooterTemplate>
                                            <asp:DropDownList ID="ddlBusinessUnitAdd" runat="server" Width="110px">
                                            </asp:DropDownList>
                                        </FooterTemplate>
                                        <HeaderStyle BackColor="#666666" Font-Size="9pt" ForeColor="White" />
                                        <ItemStyle Font-Size="9pt" Width="140px" />
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderStyle-BackColor="#666666" HeaderStyle-Font-Size="9pt" 
                                        HeaderStyle-ForeColor="White" HeaderText="Division" ItemStyle-Font-Size="9pt" 
                                        ItemStyle-Width="140px">
                                        <ItemTemplate>
                                            <asp:Label ID="lblDivision" runat="server" Text='<%#Bind("DIVISION") %>' 
                                                Width="140px"></asp:Label>
                                        </ItemTemplate>
                                        <EditItemTemplate>
                                            <asp:DropDownList ID="ddl_gvDivision" Enabled="false" runat="server" CssClass="ehr_dropdown" 
                                                Width="140px">
                                            </asp:DropDownList>
                                        </EditItemTemplate>
                                        <FooterTemplate>
                                            <asp:DropDownList ID="ddlDivisionAdd" runat="server" Width="110px">
                                            </asp:DropDownList>
                                        </FooterTemplate>
                                        <HeaderStyle BackColor="#666666" Font-Size="9pt" ForeColor="White" />
                                        <ItemStyle Font-Size="9pt" Width="140px" />
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderStyle-BackColor="#666666" HeaderStyle-Font-Size="9pt" 
                                        HeaderStyle-ForeColor="White" HeaderText="Sub-Division" 
                                        ItemStyle-Font-Size="9pt" ItemStyle-Width="140px">
                                        <ItemTemplate>
                                            <asp:Label ID="lblSubDivision" runat="server" Text='<%#Bind("SUB_DIVISION") %>' 
                                                Width="140px"></asp:Label>
                                        </ItemTemplate>
                                        <EditItemTemplate>
                                            <asp:DropDownList ID="ddl_gvSubDivision" Enabled="false" runat="server" CssClass="ehr_dropdown" 
                                                Width="140px">
                                            </asp:DropDownList>
                                        </EditItemTemplate>
                                        <FooterTemplate>
                                            <asp:DropDownList ID="ddlSubDivisionAdd" runat="server" Width="110px">
                                            </asp:DropDownList>
                                        </FooterTemplate>
                                        <HeaderStyle BackColor="#666666" Font-Size="9pt" ForeColor="White" />
                                        <ItemStyle Font-Size="9pt" Width="140px" />
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderStyle-BackColor="#666666" HeaderStyle-Font-Size="9pt" 
                                        HeaderStyle-ForeColor="White" HeaderText="Classification" 
                                        ItemStyle-Font-Size="9pt" ItemStyle-Width="140px">
                                        <ItemTemplate>
                                            <asp:Label ID="lblClassification" runat="server" 
                                                Text='<%#Bind("CLASSIFICATION") %>' Width="140px"></asp:Label>
                                        </ItemTemplate>
                                        <EditItemTemplate>
                                            <asp:DropDownList ID="ddl_gvClassification" Enabled="false" runat="server" 
                                                CssClass="ehr_dropdown" Width="140px">
                                            </asp:DropDownList>
                                        </EditItemTemplate>
                                        <FooterTemplate>
                                            <asp:DropDownList ID="ddlClassification" runat="server" Width="110px">
                                            </asp:DropDownList>
                                        </FooterTemplate>
                                        <HeaderStyle BackColor="#666666" Font-Size="9pt" ForeColor="White" />
                                        <ItemStyle Font-Size="9pt" Width="140px" />
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderStyle-BackColor="#666666" HeaderStyle-Font-Size="9pt" 
                                        HeaderStyle-ForeColor="White" HeaderText="Sub-Classification" 
                                        ItemStyle-Font-Size="9pt" ItemStyle-Width="140px">
                                        <ItemTemplate>
                                            <asp:Label ID="lblSubClassification" runat="server" 
                                                Text='<%#Bind("SUB_CLASSIFICATION") %>' Width="140px"></asp:Label>
                                        </ItemTemplate>
                                        <EditItemTemplate>
                                            <asp:DropDownList ID="ddl_gvSubClassification" Enabled="false" runat="server" 
                                                CssClass="ehr_dropdown" Width="140px">
                                            </asp:DropDownList>
                                        </EditItemTemplate>
                                        <FooterTemplate>
                                            <asp:DropDownList ID="ddlSubClassification" runat="server" Width="110px">
                                            </asp:DropDownList>
                                        </FooterTemplate>
                                        <HeaderStyle BackColor="#666666" Font-Size="9pt" ForeColor="White" />
                                        <ItemStyle Font-Size="9pt" Width="140px" />
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderStyle-BackColor="#666666" ItemStyle-Font-Size="9pt">
                                        <ItemTemplate>
                                            <asp:LinkButton ID="lnkRemove" runat="server" CommandName="Delete" 
                                                OnClientClick="return confirm('Do you want to delete?')" Text="Delete"></asp:LinkButton>
                                        </ItemTemplate>
                                        <FooterTemplate>
                                            <asp:LinkButton ID="btnAdd" runat="server" CommandName="Add" 
                                                OnClick="AddgvGroup" Text="Add"></asp:LinkButton>
                                        </FooterTemplate>
                                        <HeaderStyle BackColor="#666666" />
                                        <ItemStyle Font-Size="9pt" />
                                    </asp:TemplateField>
                                    <asp:CommandField HeaderStyle-BackColor="#666666" HeaderStyle-Width="10px" 
                                        ItemStyle-Font-Size="9pt" ItemStyle-Width="10px" ShowEditButton="True">
                                        <HeaderStyle BackColor="#666666" />
                                        <ItemStyle Font-Size="9pt" />
                                    </asp:CommandField>
                                </Columns>
                                <PagerStyle Font-Size="9pt" HorizontalAlign="Right" />
                                <EmptyDataTemplate>
                                    <div style="width: 100%; font-size: 10pt; text-align: center; color: Red;">
                                        No record found.
                                    </div>
                                </EmptyDataTemplate>
                                <HeaderStyle BackColor="DarkGray" Font-Bold="True" Font-Names="Arial" 
                                    Font-Size="9pt" ForeColor="White" HorizontalAlign="Center" />
                                <AlternatingRowStyle BackColor="Gainsboro" />
                            </asp:GridView>

这是我在VB.Net中的代码

Protected Sub gvGroup_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvGroup.RowDataBound

    If e.Row.RowType = DataControlRowType.DataRow Then
        If (e.Row.RowState And DataControlRowState.Edit) > 0 Then
            Dim ddlBusinessUnit As DropDownList = DirectCast(e.Row.FindControl("ddl_gvBusinessUnit"), DropDownList)
            'bind dropdown-list
            Dim sqlstr As String
            Dim dt As DataTable = New DataTable()
            sqlstr = "Select BUSINESS_UNIT from BUSINESS_UNIT_TBL"
            dt = ehr_utils.DataTable(sqlstr)
            ddlBusinessUnit.DataSource = dt
            ddlBusinessUnit.DataTextField = "BUSINESS_UNIT"
            ddlBusinessUnit.DataValueField = "BUSINESS_UNIT"
            ddlBusinessUnit.DataBind()
            Dim dr As DataRowView = TryCast(e.Row.DataItem, DataRowView)
            ddlBusinessUnit.SelectedValue = dr("BUSINESS_UNIT").ToString()
        End If
    End If

End Sub

我怎么能这样做呢?我还尝试了OnSelectedIndexChanged

0 个答案:

没有答案