gridview单元格值 [英] gridview cell value

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

问题描述

我有一个包含5个列的gridview,其中一列是图像按钮字段.当我单击图像按钮时,我需要第一列当前行索引的值.

I have a gridview with 5 coulumns out of which one column is an image button field. When I click the image button I need the value of first column current row index.

推荐答案

选中此选项将对您有所帮助
Check this it will help you
//Image Button is inside in the grid
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        ImageButton imgBtn = (ImageButton)sender;
        GridViewRow gridRow = (GridViewRow)imgBtn.NamingContainer;
        int selectedIndex = gridRow.DataItemIndex;  
        //get the cell text from current index
        string item = GridView1.Rows[selectedIndex].Cells["your desired cell index"].Text;
    }


您可以将该ImageButton的CommandName设置为选择".之后,当您单击ImageButton时,将触发Gridview的SelectedIndexChanged事件.

在SelectedIndexChanged事件中,您可以获取所选行的第一列的值,如下所示:

//考虑该gridview的ID是GridView1
字符串requiredValue = GridView1.SelectedRow.Cells [0] .Text;

如果对您有帮助,请将此答案标记为正确,以便像您这样的其他人可以轻松获得他们的解决方案.
You can set the CommandName of that ImageButton To "Select". after this, when you click the ImageButton,the Gridview''s SelectedIndexChanged Event will fire.

in SelectedIndexChanged event, you can get the value of the first column of the selected row as shown below:

//Considering Id of that gridview is GridView1
string desiredValue= GridView1.SelectedRow.Cells[0].Text;

please mark this answer correct if it helped you, so that others like you can get their solutions easily.


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

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