如何查找网格特定列值throgh复选框? [英] How to find grid particular column value throgh check box ?

查看:64
本文介绍了如何查找网格特定列值throgh复选框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何查找特定的网格列以单击复选框????





foreach(GridViewRow在gdvheader.Rows中增长) )

{



CheckBox chknav =(CheckBox)grow.FindControl(chksyncnav);



if(chknav.Checked)

{

int id = Convert.ToInt32(grow.Cells [1] .Text);



}

}



我的尝试:



How to find a Particular grid column to click on checkbox????


foreach (GridViewRow grow in gdvheader.Rows)
{

CheckBox chknav = (CheckBox)grow.FindControl("chksyncnav");

if (chknav.Checked)
{
int id = Convert.ToInt32(grow.Cells[1].Text);

}
}

What I have tried:

foreach (GridViewRow grow in gdvheader.Rows)
        {
            
           CheckBox chknav = (CheckBox)grow.FindControl("chksyncnav");
            
           if (chknav.Checked)
           {
               int id = Convert.ToInt32(grow.Cells[1].Text);
                
           }
        }

推荐答案

你的问题太不清楚我不完全确定如果我正确地跟着你如果您在检查 CheckBox 时尝试访问值,则可以执行以下操作:



ASPX:

You question is too unclear and I'm not entirely sure if I follow you correctly. If you are trying to access a Column value when a CheckBox is checked then you can do something like this:

ASPX:
<asp:TemplateField>
    <HeaderTemplate>
      <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" OnCheckedChanged="CheckBox1_CheckedChanged" />
    </HeaderTemplate>
</asp:TemplateField>





然后,您可以在 CheckedChanged 事件中投射发件人以获取对 CheckBox 的引用,例如:





You can then cast the sender to get reference to the CheckBox at CheckedChanged event like:

protected void CheckBox1_CheckedChanged(object sender, EventArgs e){
        CheckBox cb = (CheckBox)sender;
        if (cb.Checked){
            GridViewRow row = (GridViewRow)cb.NamingContainer;
	    //access whatever controls here
        }
        else {
            //do something else
        }
}


这篇关于如何查找网格特定列值throgh复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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