在网格视图的标题模板中查找控件 [英] Finding control inside the header template of a grid view

查看:85
本文介绍了在网格视图的标题模板中查找控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的网格...



 <   asp:GridView     ID   =  gdv    runat   =  server >  
< >
< asp:TemplateField >
< HeaderTemplate >
< asp:TextBox ID = txt runat = server < span class =code-keyword>> < / asp:TextBox < span class =code-keyword>>
< / HeaderTemplate >
< ItemTemplate >
< asp:标签 ID = lbl runat = server 文本 =' <%#DataBinder.Eval(Container.DataItem, col1%> ' > < / asp:标签 >
< / ItemTemplate < span class =code-keyword>>
< / asp:TemplateField >
< asp:TemplateField >
< ItemTemplate >
< asp:DropDownList ID = ddl runat = server < span class =code-attribute>
DataTextField = <温泉n class =code-attribute> DataValueField = value > < / asp:DropDownList >
< / ItemTemplate >
< / asp:TemplateField >
< /列 >
< / asp:GridView >











怎么样找到后面代码中的一个头模板中的TextBox控件(C#代码)?

解决方案

通过处理gridview的RowDataBound()事件,你可以找到标题模板内的文本框控件。



 受保护  void  gdv_RowDataBound( object  sender,GridViewRowEventArgs e)
{
if (gdv.HeaderRow!= null
{
TextBox txt =(TextBox)gdv.HeaderRow.FindControl( txt);
}
}


大家好,请访问此链接,了解在网格视图的标题模板中查找控件



如何查找ASP.Net中的Repeater控件的HeaderTemplate或FooterTemplate中存在的控件 - Nitesh Luharuka [ ^ ]



GridView ASP.Net(嵌套GridView)中的GridView内部 [ ^ ]



c# - 如何访问我的GridView的HeaderTemplate中的控件 - Stack Overflow [ ^ ]


  protected   void  chkSelectAll_CheckedChanged( object  sender,EventArgs e)
{
CheckBox chk;

foreach (GridViewRow rowItem GridView1.Rows)
{
chk =(CheckBox)(rowItem.Cells [ 0 ]。FindControl( chk1));
chk.Checked =((CheckBox)sender).Checked;
}
}


I have a grid like this...

<asp:GridView ID="gdv" runat="server">
            <Columns>
                <asp:TemplateField>
                    <HeaderTemplate>
                        <asp:TextBox ID="txt" runat="server"></asp:TextBox>
                    </HeaderTemplate>
                    <ItemTemplate>
                        <asp:Label ID="lbl" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "col1") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:DropDownList ID="ddl" runat="server" DataTextField="item" DataValueField="value"></asp:DropDownList>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>






How can find the TextBox control which is there inside one of the header template in code behind(C# code) ?

解决方案

By handling RowDataBound() event of the gridview you can find Textbox control inside header template.

protected void gdv_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (gdv.HeaderRow != null)
        {
            TextBox txt = (TextBox)gdv.HeaderRow.FindControl("txt");
        }
    }


Hi guys visit this link about Finding control inside the header template of a grid view

How To Find Controls present in HeaderTemplate or FooterTemplate of Repeater Control in ASP.Net - Nitesh Luharuka[^]

GridView inside GridView in ASP.Net (Nested GridView)[^]

c# - How do I access a control in the HeaderTemplate of my GridView - Stack Overflow[^]


protected void chkSelectAll_CheckedChanged(object sender, EventArgs e)
    {
        CheckBox chk;

        foreach (GridViewRow rowItem in GridView1.Rows)
        {
            chk = (CheckBox)(rowItem.Cells[0].FindControl("chk1″));
            chk.Checked =((CheckBox)sender).Checked;
        }
    }


这篇关于在网格视图的标题模板中查找控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆