如何点击按钮获取gridview中的某一列的值!

2024-10-31 19:15:43
有3个网友回答
网友(1):

要将gridview的列转换成模板。。。。
这样才方便取值
取值方法如下:
string id = (GridView1.Rows[e.RowIndex].FindControl("TextBox2") as TextBox).Text;
为什么是textbox
将gridview的列转换成模板以后,你在VS里面查看源代码,看你的gridview,就知道为什么了

网友(2):

前台Gridview中:

'
OnClientClick="return Show()" Text='<%# Eval("Day_StartShut")%>' >



后台方法:
if (e.CommandName == "MyCommandList")
{
LinkButton btn = (LinkButton)e.CommandSource;
GridViewRow row = (GridViewRow)btn.Parent.Parent;
string MacID = e.CommandArgument.ToString();

string sql = "SELECT MacID,Day_StartUp,Day_ShutDown,ABS(Day_StartUp-Day_ShutDown) AS Day_StartShut,col_date";
sql += " From DW10048 WHERE (col_date>='" + txtStartDay.Value + "' and col_date <='" + txtEndDay.Value + "') and macid = '" + MacID + "'";
sql +=" order by col_date desc";

DataTable dtlist = l_Help.GetDataTable(sql);

DataView view = dtlist.DefaultView;

GvList1.DataSource = view;
GvList1.DataBind();

}
另外,虚机团上产品团购,超级便宜

网友(3):

this.GridView1.Rows[e.NewEditIndex].Cells[0].Text