[英]How to Get cell index in gridview
I'm using a website(asp.net,C#) to view some details in gridview.我正在使用网站(asp.net,C#)在 gridview 中查看一些详细信息。 In that gridview I have generated checkboxes dynamically.在那个gridview中,我动态地生成了复选框。 So it will be placed any cell inside of that gridview.因此它将被放置在该网格视图内的任何单元格中。 I find that control in grdview by using FindControl(), but I cant get that cell index... now I want to get that excact cell index which placed that checkbox.我通过使用 FindControl() 在 grdview 中找到了该控件,但我无法获得该单元格索引......现在我想获得放置该复选框的那个精确单元格索引。 How shall I get that cell index?我该如何获得该单元格索引?
Please anyone Tell me the solution of this problem.请任何人告诉我这个问题的解决方案。
Thanks in advance.提前致谢。
My code for getting that Control is:我获取该控件的代码是:
if (HeaderCell.Text.Contains(strColumnName))
{
CheckBox chk = GrdDynamicControls.Rows[index].FindControl(chkCheckBox1.ID) as CheckBox;
chk.Checked = true;
strCelValue = chk.Checked.ToString();
}
Try this:尝试这个:
int theCellNumberWhatINeed = -1;
for (int cellNumber = 0; cellNumber < GridView1.Rows[index].Cells.Count; cellNumber++)
{
foreach (Control ctrl in GridView1.Rows[index].Cells[cellNumber].Controls)
{
if (ctrl.ID == "aCheckBox") // or compare by clientid... etc
{
theCellNumberWhatINeed = cellNumber;
break;
}
}
}
if (theCellNumberWhatINeed > -1)
{
// ...
}
Not the most elegant solution but works with the builtin gridview control without creating your own.不是最优雅的解决方案,但可以与内置的 gridview 控件一起使用,而无需创建自己的。
You can use Event Args e您可以使用事件参数 e
e.Item.ItemIndex e.Item.ItemIndex
it will return an integer它将返回一个整数
Hope this will help希望这会有所帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.