如何访问GridView单元格值 [英] How to access gridview cell value

查看:85
本文介绍了如何访问GridView单元格值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

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].文本没有帮助...

我在这里想念什么?任何帮助,谢谢



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...

What am I missing here? any help thanks

推荐答案

安迪,
感谢您的回复.它不是Gridview上的编辑/更新"按钮.
我为用户提供了选择他要更新的行的选项.
根据他通过复选框的选择,我只需要更新gridview中的一个单元格值并收集表中该行的主键,以便在后端更新数据源(我未包含的代码)

希望你能理解.更新一个单元格值不是强制性的,因为我正在更新数据源,并且可以重新绑定它.收集该行的主键(数据源表)是

"GridView1.Rows [i] .Cells [0] .Text"对于更新数据库很重要.


谢谢
Hi Andy,
Thanks for your reply. 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 havn''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.


Thanks


嗨Jayadheer,

我认为您在GridView中使用CommandField并单击此CommandField编辑GridRow,对吧?

如果这样做,请重新绑定GridView的数据源,因为当列中的模板控件变为编辑模式时,默认文本为空.因此,您必须重新绑定GridView

希望对您有帮助.

Andy
Hi Jayadheer,

I think you use CommandField in GridView and click on this CommandField to edit GridRow, right???

If you did that, please re-bind datasource for the GridView, because when the template control in the column turns to edit mode, the default text is empty. So you must re-bind the GridView

Hope it helps you.

Andy


在我的代码中,GridView1.Rows [i] .Cells [2] .Text正常,具有价值.请查看表格的第2列,它是否有价值?
In my code, GridView1.Rows[i].Cells[2].Text is OK, has value. Please see the column 2nd on the Grid, does it have value?


这篇关于如何访问GridView单元格值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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