本文介绍了如何查找网格特定列值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);
                
           }
        }

推荐答案

<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复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 05:16