在Button上选择指定的单元格值,然后在Gridview中单击 [英] Selecting the specified cell value on Button click in Gridview

查看:118
本文介绍了在Button上选择指定的单元格值,然后在Gridview中单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从Gridview中的指定单元格获取单元格值?我尝试了很多方法,但仍然无法使用.

当我单击停止按钮时,它将转到代码隐藏页面中的rowcommand并执行代码.但是为了执行代码,我需要在相应的停止按钮行的第5个单元格中输入值.

这是我的gridview的屏幕截图:

屏幕截图

另一个问题:点击特定行后,如何禁用停止按钮?

请帮助我.

在此先感谢.

How do i get the cell value from specified cell in Gridview ? I have tried many methods but still not working.

When i click on stop button it will go to the rowcommand in the codebehind page and execute the code. But for executing the code i need the value in 5th cell of corresponding stop button row.

Here is the screenshot of my gridview:

Screenshot

One more question : How do i disable the stop button once clicked of the specific row ?

Please help me in this.

Thanks in Advance.

推荐答案

根据您的问题,我不喜欢这样...

GridView在所有行中都包含停止"按钮,并且固定行包含

这是我的解决方案

转到GridView设计

内部ItemTemplete声明名称为btnStop的按钮
和commandArgument为''%# Eval("col5") %''

在ItemTemplate内用eval声明所有5个合辑

因此,在GridView_Rowcommand 中,事件U可以轻松获得第5个col值
单击相应的停止按钮时
As per ur question I undestood like this...

A GridView Contains Stop Button in all rows and Fixed coloums

Here is My solution

Go to Design of GridView

Inside ItemTemplete declare button with name btnStop
and commandArgument as ''%# Eval("col5") %''

Declare all 5 coloums with eval inside ItemTemplate

So in GridView_Rowcommand Event U can get 5th col value easily
on clicking corresponding stop Button


HI

我无法打开您的屏幕截图.但是请按照我的流程操作

将自动生成的列设置为false
在gridview属性中选择或启用选择命令

转到设计视图后面的代码
并编写以下代码
HI

I could not open your screen shot.But follow my process

make autogenerate columns to false
Choose or enable select command in gridview properties

go to code behind of design view
and write the below code
<grid>
<columns>
<templatefield>
<itemtemplate>
5TH column data write here eg <#eval(''columnname'')>
</itemtemplate>
<edititem template="">
<asp:label id="lblgetdata'' runat=''server''>

</edititem></templatefield>
</columns>
</grid>


在RowCommand事件中


In RowCommand event

protected void gridview1_RowCommand(object sender, GridViewRowEventArgs e) 
{    
  Label l=(Label)e.FindControl(''lblgetdata'');
  string fifth_cellval=l.text;
}


将命令参数属性添加为停止按钮,
Add command argument property to stop button as,
CommandArgument=''<%#((Container)GridViewRow.RowIndex)%>''



然后可以通过
获取行索引 e.commandargument返回选定的行行索引

gridview1.rows [Convert.toint32(e.rowcommand)].cells [1] .text;将得出对应行的第一个单元格值...



Then you can get the row index by
e.commandargument returns the selected rows row index

gridview1.rows[Convert.toint32(e.rowcommand)].cells[1].text;will results the 1st cell value of corresponding row...


这篇关于在Button上选择指定的单元格值,然后在Gridview中单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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