如何在按钮单击中获取gridview单元格值? [英] How to get the gridview cell value in button click?
本文介绍了如何在按钮单击中获取gridview单元格值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I bind the datatable in gridview in this grid view checkbox also have
if any check box is selected then get the cell value of the check box selected row i use some methods but not working
我尝试过的方法:
What I have tried:
protected void btnUpdate_Click(object sender, EventArgs e)
{
TextBox TextBox1 = new TextBox();
foreach (GridViewRow gr in GridView1.Rows)
{
bool isChecked = ((CheckBox)gr.FindControl("chkBxSelect")).Checked;
if (isChecked)
{
//first method
string myvalue = GridView1.Rows[1].Cells[1].ToString();
// second method
GridViewRow row = GridView1.SelectedRow;
TextBox1.Text = row.Cells[0].Text;
try
{
// dt1.Rows.Add(Convert.ToString(GridView1.Cells[1].Text), "", "", "", "");
}
catch (Exception ex)
{
continue;
}
}
}
}
推荐答案
使用GridViewRow
对象
useGridViewRow
object
if (isChecked)
{
string value = gr.Cells[1].Text;
}
这篇关于如何在按钮单击中获取gridview单元格值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文