在gridview中获取单元格值 [英] get cell value within gridview

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

问题描述

我有一个gridview,每行的最后一个单元格中都有一个按钮。我想从单元格1中获取单击该按钮的行的文本。


如果我的gridview看起来像这样:


N-12宝马[选择]

N-35梅赛德斯[选择]


如果我的用户点击第2行,我想看梅赛德斯,我该怎么做?


我有一个buttonClick事件为我的选择按钮,我正在尝试使用DataKeyName拉取值,但我不断将''对象引用设置为对象的实例。


here我正在尝试


select_Click()

{

string make = grid1.SelectedDataKey.Values [" CarMake"]。toString();


}


关于如何获取我所选行的单元格1文本的任何建议Select_Click()?

I have a gridview that has a button in the last cell of each row. I want to get the text from cell 1 for that row the button was clicked on.

So if my gridview looks like this:

N-12 BMW [select]
N-35 Mercedes [select]

if my user clicks row 2, I want to see Mercedes, How can I do that?

I have a buttonClick event for my select button, I''m trying to pull the values using the DataKeyName, but I keep getting ''object reference not set to an instance of an object.

here is what i''m trying

select_Click()
{
string make = grid1.SelectedDataKey.Values["CarMake"].toString();

}

any suggestions on how I can get the cell 1 text for the selected row within my Select_Click()?

推荐答案

10月18日上午10:18,Mike < M ... @ community.nospam.comwrote:
On Oct 18, 10:18 am, "Mike" <M...@community.nospam.comwrote:

我有一个gridview,每行的最后一个单元格中都有一个按钮。我想从单元格1中获取单击该按钮的行的文本。


因此,如果我的gridview看起来像这样:


N-12宝马[选择]

N-35梅赛德斯[选择]


如果我的用户点击第2排,我想看梅赛德斯,我怎么能那样做了吗?


我的select按钮有一个buttonClick事件,我正在尝试使用DataKeyName来拉取值,但我不断将''对象引用设置为一个对象的实例。


这里是我正在尝试的


select_Click()

{

string make = grid1.SelectedDataKey.Values [" CarMake"]。toString();


}


关于如何在Select_Click()中获取所选行的单元格1文本的任何建议?
I have a gridview that has a button in the last cell of each row. I want to get the text from cell 1 for that row the button was clicked on.

So if my gridview looks like this:

N-12 BMW [select]
N-35 Mercedes [select]

if my user clicks row 2, I want to see Mercedes, How can I do that?

I have a buttonClick event for my select button, I''m trying to pull the values using the DataKeyName, but I keep getting ''object reference not set to an instance of an object.

here is what i''m trying

select_Click()
{
string make = grid1.SelectedDataKey.Values["CarMake"].toString();

}

any suggestions on how I can get the cell 1 text for the selected row within my Select_Click()?



尝试使用GridView.SelectedIndex值指向所选的

行。

然后使用GridView1 .Rows [SelectedIndex] .Cells [1] .Text获取单元格内的

值。


我希望有帮助!


Steve

Try using the GridView.SelectedIndex value to point to the selected
row.
Then use the GridView1.Rows[SelectedIndex].Cells[1].Text to get the
value inside the cell.

I hope that helps!

Steve


" Mike" < Mi ** @ community.nospam.com写信息

新闻:e3 ************** @ TK2MSFTNGP06.phx.gbl ...
"Mike" <Mi**@community.nospam.comwrote in message
news:e3**************@TK2MSFTNGP06.phx.gbl...

关于如何获取所选行的单元格1文本的任何建议

在我的Select_Click()中?
any suggestions on how I can get the cell 1 text for the selected row
within my Select_Click()?



grid1.SelectedRow.Cells [1] .Text;

-

Mark Rae
ASP.NET MVP
http://www.markrae.net

grid1.SelectedRow.Cells[1].Text;
--
Mark Rae
ASP.NET MVP
http://www.markrae.net


我试过了,它给了我这个错误:


索引超出了范围。必须是非负数且小于集合的大小

。参数名称:index


" S_K" < st *********** @ yahoo.com写了留言

新闻:11 ******************* ***@v23g2000prn.googlegr oups.com ...
I tried that and it gave me this error:

Index was out of range. Must be non-negative and less than the size
of the collection. Parameter name: index

"S_K" <st***********@yahoo.comwrote in message
news:11**********************@v23g2000prn.googlegr oups.com...

10月18日上午10:18,Mike < M ... @ community.nospam.comwrote:
On Oct 18, 10:18 am, "Mike" <M...@community.nospam.comwrote:

>我有一个gridview,每行的最后一个单元格中有一个按钮。我希望
从单元格1中获取单击该按钮的文本。

如果我的gridview看起来像这样:

N-12 BMW [选择]
N-35梅赛德斯[选择]

如果我的用户点击第2排,我想看梅赛德斯,我该怎么做?

我我的选择按钮有一个buttonClick事件,我正在尝试使用DataKeyName来拉取
值,但我不断将对象引用设置为对象的实例。

这就是我正在尝试的

select_Click()
{/ /> string make = grid1.SelectedDataKey.Values [" CarMake"]。toString( );

}

有关如何在Select_Click()中获取所选行的单元格1文本的任何建议?
>I have a gridview that has a button in the last cell of each row. I want
to get the text from cell 1 for that row the button was clicked on.

So if my gridview looks like this:

N-12 BMW [select]
N-35 Mercedes [select]

if my user clicks row 2, I want to see Mercedes, How can I do that?

I have a buttonClick event for my select button, I''m trying to pull the
values using the DataKeyName, but I keep getting ''object reference not
set to an instance of an object.

here is what i''m trying

select_Click()
{
string make = grid1.SelectedDataKey.Values["CarMake"].toString();

}

any suggestions on how I can get the cell 1 text for the selected row
within my Select_Click()?



尝试使用GridView.SelectedIndex值指向所选的

行。

然后使用GridView1 .Rows [SelectedIndex] .Cells [1] .Text获取单元格内的

值。


我希望有帮助!


史蒂夫


Try using the GridView.SelectedIndex value to point to the selected
row.
Then use the GridView1.Rows[SelectedIndex].Cells[1].Text to get the
value inside the cell.

I hope that helps!

Steve



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

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