日期:2014-05-18 浏览次数:20601 次
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowIndex != -1) { int id = e.Row.RowIndex; Button btnDel = (Button)e.Row.FindControl("btnDel"); //找刪除按鈕 HtmlButton btnEdit = (HtmlButton)e.Row.FindControl("btnEdit"); btnDel.CommandArgument = id.ToString(); } } protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Del") { int rowIndex = Convert.ToInt32(e.CommandArgument); string id = this.GridView1.Rows[rowIndex].Cells[0].Text.ToString(); string sql_del = "刪除的sql語句"; //執行刪除操作 } }
------解决方案--------------------
GridViewRow gr = this.GridView1.SelectedRow;
string a = gr.Cells["name"].Text.ToString();
------解决方案--------------------
string name = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
------解决方案--------------------
为什么不把主键设上
GridView1.DataKeys="storeid";
id=GridView1.DataKeys[e.Index].value;
------解决方案--------------------
设置DataKeyNames
然后用DataKeys