无法访问GridView单元格值 [英] Unable to access gridview cell value
问题描述
大家好,
protected void update_Status_Click(object sender, EventArgs e)
{
List<int> id = new List<int>();
foreach (GridViewRow row in GridView1.Rows)
{
int i = row.RowIndex;
CheckBox cb = (CheckBox)row.FindControl("SelectCashout");
if (cb != null && cb.Checked)
{
if (GridView1.Rows[i].Cells[2].Text == "Requested")
{
int x = Convert.ToInt32(GridView1.Rows[i].Cells[0].Text);
id.Add(x);
}
}
}
}
当我调试它时,我得到"GridView1.Rows [i] .Cells [2] .Text"值为空字符串.
这不是Gridview事件,它是gridview之外的按钮事件.
我尝试了row.Cells[2].Text
它没有帮助.目前,gridview显示10行,所有列中的所有数据.
它不是Gridview上的编辑/更新"按钮.
我为用户提供了选择他要更新的行的选项.
根据他通过复选框的选择,我只需要更新gridview中的一个单元格值并收集表中该行的主键,以便在后端更新数据源(我未包含的代码)
希望你能理解.更新一个单元格值不是强制性的,因为我正在更新数据源,并且可以重新绑定它.收集该行的主键(数据源表)是
"GridView1.Rows [i] .Cells [0] .Text"对于更新数据库很重要.
我在这里想念什么?任何帮助,谢谢
When I debug it I am getting "GridView1.Rows[i].Cells[2].Text" value as empty string.
This is not a Gridview event, it is button event out side the gridview.
I tried row.Cells[2].Text
it doesn''t help. At the moment gridview showing 10 rows with all the data in all the columns.
It''s not Edit/Update button on Gridview.
I am giving option to the user to select which rows he wants to update.
Based on his selection through checkbox I have to update just one cell value in the gridview and collect primary key of that row in the table so I will update datasource at backend(That code I haven''t included)
Hope you understood. updating one cell value is not mandatory because I am updating datasource and I can rebind it. Collecting that row''s Primary key(Datasource Table''s) is
"GridView1.Rows[i].Cells[0].Text" important to update database.
What am I missing here? any help thanks
推荐答案
下面的代码可能会帮助您
Below code may help you
LinkButton lbtnID= (LinkButton)sender;
int index = ((GridViewRow)lbtnID.NamingContainer).RowIndex;
Label lblID= ((Label)gdDiscount.Rows[index].Cells[1].FindControl("lblID"));
int value= Convert.ToInt32(lblID.Text.ToString());
将此链接写在gridview的内部链接按钮中..希望这会给您一些想法..让我知道您是否仍然有问题
Write this inside link button in gridview.. Hope this will give you some idea..Let me know if you have still problem
这篇关于无法访问GridView单元格值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!