where are you handling the event? in ItemCommand or LinkButton's own handler?in ItemCommand handler for the DataGrid, void DataGrid_ItemCommand(Object sender, DataGridCommandEventArgs e) 
 {
   //e.Item.Cells[0].Text, e.Item.Cells[2].Text 
 }in LinkButton's own handlervoid LinkButton_Click(Object sender, EventArgs e) 
{
  DataGridItem dgi = (DataGridItem)((LinkButton))sender).Parent.Parent;
  //dgi.Cells[0].Text, dgi.Cells[2].Text 
 }

解决方案 »

  1.   

    新建一个项目,将DataGrid控件拖到页面上,然后使用模板进行编辑;
      接下来,编写一个函数,起作用是合并数据:
            public string joinString(object obj1,object obj2)
                   {
                         return (string)obj1 + (string)obj2;
                    }
      再在HTML代码中想要使用连接的地方写入以下代码:
           a.使用DataReader绑定数据:
           NavigateURL = <%#joinString(((System.Data.Common.DbDataRecord)Container.DataItem)["字段名1"],((System.Data.Common.DbDataRecord)Container.DataItem)["字段名2"])%>
           b.使用DataTable或DataView绑定数据:
           NavigateURL = <%#joinString(((System.Data.DataRowView)Container.DataItem)["字段名1"],((System.Data.DataRowView)Container.DataItem)["字段名2"])%>另外可参考:
    http://www.tek-tips.com/gfaqs.cfm/pid/855/fid/4372
      

  2.   

    1 指定linkbutton的Command名称
    void DataGrid_ItemCommand(Object sender, DataGridCommandEventArgs e) 
     {
        if(e.Item.Command=="xxx")
    {
       //e.Item.Cells[0].Text, e.Item.Cells[2].Text 取值
    }
     }
      

  3.   

    1 指定linkbutton的Command名称为 "xxx"
    void DataGrid_ItemCommand(Object sender, DataGridCommandEventArgs e) 
    {
        if(e.Item.Command=="xxx")
        {
            //string sItem0 = e.Item.Cells[0].Text;
            //string sItem2 = e.Item.Cells[2].Text;
        }
    }
      

  4.   

    把这段代码放在项目中,编译无法通过,提示System.Web.UI.WebControls.DataGridItem并不包含对"command"的定义!!!什么原因???在线等!!急,解决马上给分!!!!!!!!!!!!!!!!!!!!
      

  5.   

    e.Item.Command,其他地方没有command啊
      

  6.   

    hanxi077(月黑风高) 
    把这段代码放在项目中,编译无法通过,提示System.Web.UI.WebControls.DataGridItem并不包含对"command"的定义!!!什么原因???在线等!!急,解决马上给分!!!!!!!!!!!!!!!!!!!!------------------双击你的Datagrid 让它自动生成事件句柄或从code视图下选DataGrid的ItemCommand事件
    不用自己手写
      

  7.   

    还是提示System.Web.UI.WebControls.DataGridItem并不包含对"command"的定义,搞不定啊!!!
      

  8.   

    e.Item.Cells[i].Text datagrid.item.cell[i].text
      

  9.   

    <asp:LinkButton id="LinkButton2" 
               Text="Order Item 10002"
               CommandName="abc" 
          .....
               Runat="server"/>    if (((LinkButton)e.CommandSource).CommandName == "abc")
        {
    ........
        }
      

  10.   

    hanxi077(月黑风高) 
    你确认生成DataGrid_ItemCommand事件了吗 而且有句柄吗
      

  11.   

    如果你找到了DataGrid1_ItemCommand事件,将一下代码加进去:
    假设第三列的CommandName是Add
    if((((LinkButton)e.CommandSource).CommandName == "Add"))
    {
             string s = e.Items.Cell[0].Text;
             …………
    }