• GridView中两个DropDownList联动


    GridView中两个DropDownList联动

    http://www.cnblogs.com/qfb620/archive/2011/05/25/2057163.html

    Html:

    <asp:UpdatePanel runat="server" ID="AccountUpdate" UpdateMode="Conditional"  >
                            <ContentTemplate>
                            <asp:GridView ID="gridAccount" runat="server" Width="100%" AutoGenerateColumns="False">
                                <Columns>

                                    <asp:TemplateField HeaderText="选择一" ItemStyle-Width="15%">
                                        <ItemTemplate>
                                        <asp:DropDownList ID="ddlA" OnSelectedIndexChanged="ddlA_SelectedIndexChanged" AutoPostBack="true" runat="server" Width="50px">
                                        <asp:ListItem Value="">全部</asp:ListItem>
                                        <asp:ListItem Value="1">是</asp:ListItem>
                                        <asp:ListItem Value="0">否</asp:ListItem>
                                    </asp:DropDownList>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="选择二" ItemStyle-Width="15%">
                                        <ItemTemplate>
                                        <asp:DropDownList ID="ddlB" runat="server" Width="50px">
                                        <asp:ListItem Value="">全部</asp:ListItem>
                                        <asp:ListItem Value="1">是</asp:ListItem>
                                        <asp:ListItem Value="0">否</asp:ListItem>
                                    </asp:DropDownList>
                                        </ItemTemplate>
                                    </asp:TemplateField>

    </Columns>
                           </asp:GridView>
                            </ContentTemplate>
                            </asp:UpdatePanel>

    CS:

    public void ddlA_SelectedIndexChanged(object sender, EventArgs e)
            {

     DropDownList ddlA= (DropDownList)sender;//获取现在的事件触发者:

                GridViewRow gvr = (GridViewRow)ddlA.NamingContainer;//ddlA同属于在一个NamingContainer下

                DropDownList ddlB= (DropDownList)gvr.FindControl("ddlB");//找到ddlA的DropDownList

                ddlB.Enabled = false;

    }

     
     
  • 相关阅读:
    一起谈.NET技术,抛砖引玉:我看微软.NET各子技术领域之应用前景 狼人:
    一起谈.NET技术,Windows Mobile 6.5的开始菜单 狼人:
    一起谈.NET技术,ASP.NET MVC 验证方式(1) 狼人:
    一起谈.NET技术,强烈推荐体验VisualStudio2010 RC 狼人:
    【华安php入门系列】第1天php的执行方式、执行过程
    败者树Java实现
    Android INSTALL_FAILED_ACWF_INCOMPATIBLE
    《构建高质量的C#代码》,新书上市,欢迎交流!
    oracle中的左右连接
    VS2012 UPDATE 2 发布了离线包
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/3712902.html
Copyright © 2020-2023  润新知