先边的是我自己定义的方法,你得在HTML里头添加如下东西
<asp:datagrid id="DataGridList" runat="server" Width="92%" Height="98%" AllowPaging="True" AutoGenerateColumns="False"
BackColor="White" OnDataBinding="DataGrid1" >
然后在程序行写这个public void DataGrid1(object sender, DataGridCommandEventArgs e)
{   


this.strSQL="UPDATE t_d_消息 set 接收操作=0 where ID="+Convert.ToInt32(e.Item.Cells[0].Text);
this.strSQL=" delete t_d_消息 where ID="+Convert.ToInt32(e.Item.Cells[0].Text)+" and 已发操作=0 and 接收操作=0";
this.dc.ExeSqlNoQuery(this.strSQL);
this.BindGrid();
this.ShowStats();///重要的是这个e.item.Cells[0].Text  你可以把Cells[0]的0改成linkbutton的所在位置,就好了。


}

解决方案 »

  1.   

    OnItemCommand事件中
    string Test = ((TextBox)e.Item.FindControl("textbox1")).Text;这样就可以取得对应行的textbox1的值了,然后再写其它的就行
      

  2.   

    补充下楼上的
    给你的LinkButton的CommandName赋值
    比如说赋值为"View";
    在ItemComand里面
    if(e.CommandName == "View")
    {
       e.Item.Cell[0].Text..........
       e.Item.Cell[1].Text..........
       string Test = ((TextBox)e.Item.FindControl("textbox1")).Text;
       。
    }
      

  3.   

    添加这段代码后
    if(e.CommandName=="Test")
    {

    string Test = ((TextBox)e.Item.FindControl("TextBox3")).Text;

    }
    显示错误:未将对象引用设置到对象的实例。
    这个是什么问题呢?还有如果我想点一个批复linkbutton,把相应行第一个单元格的内容读到TextBox1.text应该怎么写代码?在同一页面操作
    谢谢初学编程请多指教