datagrid里面有3列,一列是手机号码,一列是短信内容,第三列是一个按钮,现在想通过电机按钮把该行的手机号码和短信内容分别赋值给两个不同的文本筐,请问如何通过点击按钮来获得对应的手机号码和短信内容,谢谢。

解决方案 »

  1.   

    假如你的按钮是编辑按钮,则对datagrid加事件:
    private void yourDataGrid_EditCommand(object source, 
                  System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
    this.Textbox1.text= e.Item.Cells[0].Text;   //取当前行第一列
    this.Textbox1.text= e.Item.Cells[1].Text;   //取当前行第二列
    }如果是一般按钮,则实现ItemCommand事件,但要判断一下CommandName,
    private void yourDataGrid_ItemCommand(object source, 
                  System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
           if (e.CommandName=="YourName")
           {
    this.Textbox1.text= e.Item.Cells[0].Text;   //取当前行第一列
    this.Textbox1.text= e.Item.Cells[1].Text;   //取当前行第二列
           }
    }
      

  2.   

    如果是模版列的话,在DataGrid1_ItemDataBound事件中写代码,先判断是哪一行的button被点中,然后e.Item.Cells[0].Text获取值,将值附给文本框
      

  3.   

    最好能用findcontrol方法来定位文本框控件,然后将取出来的值给文本框,至于怎么取值上面的人都说了
      

  4.   

    也可以在页面上取
    如果直接是Grid的值
    function selectvalue(objcmd){
    window.document.getElementById("TextBox1").value=objcmd.parentElement.parentElement.cells[0].innerText;
    window.document.getElementById("TextBox2").value=objcmd.parentElement.parentElement.cells[1].innerText;
    }在控件 <asp:Button id=Selectone onclick=javascript:SelectOneRow(this); runat="server" Text="选择">
    </asp:Button >