【问题标题】:how to search a control in an asp.net gridview and access it?如何在 asp.net gridview 中搜索控件并访问它?
【发布时间】:2011-06-03 07:09:48
【问题描述】:

我有一个网格视图:

<asp:GridView ID="gvAppRejProfiles" runat="server" AutoGenerateColumns="false">
                        <Columns>
                            <asp:TemplateField>
                                <HeaderTemplate>
                                    Resumes
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <asp:LinkButton ID="lbtnResumes" runat="server"></asp:LinkButton>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>

我有一个简历名称列表(字符串格式),我想将其添加为链接按钮“lbtnResumes”的文本,用于字符串数组中的所有简历名称。

【问题讨论】:

    标签: c# asp.net gridview findcontrol


    【解决方案1】:

    利用FindControl()方法...搜索控件

    void gvAppRejProfiles_RowDataBound(object sender, GridViewRowEventArgs e)
    {
    
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            LinkButton bl = 
             (LinkButton)e.Row.FindControl("lbtnResumes");
    
    
        }
    }
    

    【讨论】:

    • 我这样做了:LinkBut​​ton lbtnFound = (LinkBut​​ton)gvAppRejProfiles.FindControl("lbtnResumes");但不工作
    • 你错了你需要LinkBut​​ton lbtnFound = (LinkBut​​ton)gvAppRejProfiles.Rows[rowindex].FindControl("lbtnResumes");
    • 你需要在网格的行中找到控件,否则你将一无所获......希望你明白我的意思
    • 网格的行返回 null,我刚刚检查了 rowbound 事件及其工作
    【解决方案2】:
    for (int count = 0; count < gvAppRejProfiles.Rows.Count; count++)
                    {
                        LinkButton lbtnResumes = (LinkButton)gvAppRejProfiles.Rows[count].FindControl("lbtnResumes");
                        if (lbtnResumes.Text == "resume")
                        {
                            // Store and perform any operation
                        }
                    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-09-10
      • 2015-07-31
      • 2013-09-10
      • 2010-10-11
      • 2013-05-09
      • 2011-07-12
      • 1970-01-01
      相关资源
      最近更新 更多