请问如何动态的显示或隐藏某行中的控件。现在设置控件的visible属性或者TableCell的display属性都行不通。请问是什么原因或者如果解决这个问题。

解决方案 »

  1.   

    OnRowDataBound="CustomersGridView_RowDataBound"
      

  2.   

    给你举个例子: DropDownList ddl = (DropDownList)this.GridView1.Rows[iRowIndex].Cells[1].Controls[0];
      

  3.   

    现在的具体情况是这样的:
    在GridViewRow中的某列有一个DropDownList和一个TextBox,如果点击DropDownList的最后一个元素“其它”的时候,TextBox显示;否则隐藏。对DropDownList加SelectedIndexChanged事件能执行,但是里面的TextBox.Visible = true(默认为隐藏)没有反应。网上有的说是PostBack的原因,但是不知道如何解决。敬请指导。
      

  4.   

    this.DropDownList1.AutoPostBack = true;试试
      

  5.   

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            for (int i = 0; i < this.GridView1.Rows.Count; i++)
            {
                DropDownList ddl = (DropDownList)this.GridView1.Rows[i].Cells[0].FindControl("DropDownList1");
                TextBox txt = (TextBox)this.GridView1.Rows[i].Cells[1].FindControl("TextBox1");
                if (ddl.SelectedValue == "基它")
                {
                    txt.Visible = false;
                }
                else
                {
                    txt.Visible = true;
                }
            }
        }
      

  6.   

    可以在GridView中的RowDataBound事件里if (e.Row.RowType == DataControlRowType.DataRow)
    {
       e.Row.FindControl("lab_Test").Visible = false;
    }
      

  7.   

    定义Grid的时候把控件都事前命名。然后FindControl()。
      

  8.   

    gridview 最后生成的是一个table可以用js 循环table的行 然后找到有控件的列 对控件设置display就可以了
      

  9.   

    protected void gvAllWord_RowCreated(object sender, GridViewRowEventArgs e)
            {
                if ((DataControlRowType.DataRow == e.Row.RowType) || (DataControlRowType.Header == e.Row.RowType))
                {
                    e.Row.Cells[7].Visible = false;
                }
            }
      

  10.   

    //WebUserControl.ascx.cs<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:DropDownList runat="server" ID="DropDownList1" 
        onselectedindexchanged="DropDownList1_SelectedIndexChanged" 
        AutoPostBack="true" >
                <asp:ListItem Value="1">Item 1</asp:ListItem>
                <asp:ListItem Value="2">Item 2</asp:ListItem>
                <asp:ListItem Value="3">Item 3</asp:ListItem>
                <asp:ListItem Value="其它">其它</asp:ListItem>
            </asp:DropDownList>
            <asp:TextBox ID="TextBox1" runat="server" Visible="false" />
        </ContentTemplate>
    </asp:UpdatePanel>protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
            if (DropDownList1.SelectedValue == "其它")
                TextBox1.Visible = true;
            else
                TextBox1.Visible = false;
    }<asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager><asp:TemplateField ShowHeader="False">
        <ItemTemplate>
              <uc1:WebUserControl ID="WebUserControl1" runat="server" />
        </ItemTemplate>
        <ItemStyle Width="200" />
    </asp:TemplateField>
      

  11.   

    也就是说DropDownList和TextBox都放在UserControl里。根据选项隐藏或显示的处理代码也放到UserContrl的.cs里。为了尽量避免闪烁,给UserControl套一个UpdatePanel,且设置UpdateMode为Conditional.然后在主页面放置一个ScriptManager, 在TemplateField里放置UserControl.