参考一下:
 public void myDataGrid_ItemCommand(object sender,DataGridCommandEventArgs e)
{   
int row =e.Item.ItemIndex;
if(e.CommandName=="Select")
{
    txtno.Text   = myDataGrid.Items[row].Cells[1].Text;
    txtname.Text = myDataGrid.Items[row].Cells[2].Text; }
}

解决方案 »

  1.   

    e.Item.Cells[0].Text //你具体想在什么事件里调用
      

  2.   

    foreach(DataGridItem item in DGTableProperty1.Items)
    { ProNo = item.Cells[0].Text.Trim();
    ProName = item.Cells[1].Text.Trim();
    }
      

  3.   

    html:
    <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication2.WebForm1" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>WebForm1</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" Content="C#">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server">
    <FONT face="宋体">
    <asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 40px" runat="server"
    AutoGenerateColumns="False" Width="288px" Height="216px">
    <Columns>
    <asp:TemplateColumn>
    <ItemTemplate>
    <asp:LinkButton runat="server" Text="选择" CommandName="Select" CausesValidation="false"></asp:LinkButton>
    </ItemTemplate>
    </asp:TemplateColumn>
    <asp:TemplateColumn HeaderText="au_id">
    <ItemTemplate>
    <asp:Label id=L_au_id runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.au_id") %>'>
    </asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox id=TextBox1 runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.au_id") %>'>
    </asp:TextBox>
    </EditItemTemplate>
    </asp:TemplateColumn>
    <asp:TemplateColumn HeaderText="title_id">
    <ItemTemplate>
    <asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.title_id") %>'>
    </asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.title_id") %>'>
    </asp:TextBox>
    </EditItemTemplate>
    </asp:TemplateColumn>
    </Columns>
    </asp:DataGrid></FONT>
    </form>
    </body>
    </HTML>cs:
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;namespace WebApplication2
    {
    /// <summary>
    /// WebForm1 的摘要说明。
    /// </summary>
    public class WebForm1 : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.DataGrid DataGrid1;
    protected System.Web.UI.HtmlControls.HtmlForm Form1; SqlConnection sc=new SqlConnection("server=localhost;database=pubs;uid=zxy;pwd=zxy");

    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    if (!this.IsPostBack)
    {
    BindData();
    }
    } private void BindData()
    {
    SqlDataAdapter sp=new SqlDataAdapter("select au_id,title_id from titleauthor order by au_id,title_id",sc);
    DataSet ds=new DataSet();
    sp.Fill(ds,"titleauthor");
    DataGrid1.DataSource=ds.Tables[0].DefaultView;
    DataGrid1.DataBind();
    } #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.DataGrid1.SelectedIndexChanged += new System.EventHandler(this.DataGrid1_SelectedIndexChanged);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
    {
     this.Response.Write(((Label)DataGrid1.SelectedItem.FindControl("L_au_id")).Text);
    }
    }
    }
      

  4.   

    liuvb(宝宝) 
    int row =e.Item.ItemIndex;
    可以的
      

  5.   

    在客户端我是这样操作的:grid1为datagrid,采用模板列
    Grid1.rows(row1).cells(0).all(0).value取得row1行第一列的数据
      

  6.   

    int row =e.Item.ItemIndex;
    if(e.CommandName=="Select")
    {
        txtno.Text   = myDataGrid.Items[row].Cells[1].Text;
        txtname.Text = myDataGrid.Items[row].Cells[2].Text; }
    上边说的很清楚哦
      

  7.   

    (1)假如在页面DataGrid中用了选择命令,参考如下:
    ------------------------------------------------
    <asp:ButtonColumn CommandName="Select" SortExpression="xmdm" DataTextField="xmdm" HeaderText="项目代码"></asp:ButtonColumn>
    ------------------------------------------------那么,在"选择"事件中可以:
    ————————————————————————
    private void DataGridMe_SelectedIndexChanged(object sender, System.EventArgs e)
    {
    txtItemCode.Text=DataGridMe.SelectedItem.Cells[2].Text;
    this.txtItemName.Text= DataGridMe.SelectedItem.Cells[3].Text;........ }
    -------------------------------------------------
    (2)其他方式的选中,如使用摸板列(checkBox)等,完全可以参考上面各位师兄的方法。
      

  8.   

    点击一行后,获得该行某一列的值:在窗体中添加html控件hidden,并runat=server
    在DataGrid1_ItemDataBound中添加onclick属性。
    e.Item.Attributes.Add("onclick","window.form1.hidden1.value=" & e.item.itemindex.tostring & ";window.Form1.submit();")
    为DataGrid1_Load事件添加如下代码:
    If Hidden1.Value <> "" Then
                DataGrid1.SelectedIndex = CInt(Hidden1.Value)
            End If
    此时DataGrid1.SelectedItem.Cells(?).Text就是你所想要的。
      

  9.   

    private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
    {
    TextBox1.Text=DataGrid1.SelectedItem.Cells[0].Text.Trim();
    TextBox2.Text=DataGrid1.SelectedItem.Cells[1].Text.Trim();
    }
      

  10.   

    我再贴另一个:
    html:
    <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication2.WebForm1" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>WebForm1</title>
    <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
    <meta content="C#" name="CODE_LANGUAGE">
    <meta content="JavaScript" name="vs_defaultClientScript">
    <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server">
    <FONT face="宋体">
    <asp:datagrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 80px" runat="server"
    AutoGenerateColumns="False" Width="200px" Height="88px">
    <Columns>
    <asp:TemplateColumn>
    <ItemTemplate>
    <asp:LinkButton runat="server" Text="选择" CommandName="Select" CausesValidation="false"></asp:LinkButton>
    </ItemTemplate>
    </asp:TemplateColumn>
    <asp:TemplateColumn HeaderText="au_id">
    <ItemTemplate>
    <asp:Label id=L_au_id runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.au_id") %>'>
    </asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox id=TextBox1 runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.au_id") %>'>
    </asp:TextBox>
    </EditItemTemplate>
    </asp:TemplateColumn>
    <asp:TemplateColumn HeaderText="title_id">
    <ItemTemplate>
    <asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.title_id") %>'>
    </asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.title_id") %>'>
    </asp:TextBox>
    </EditItemTemplate>
    </asp:TemplateColumn>
    </Columns>
    </asp:datagrid><INPUT id="text1" style="Z-INDEX: 103; LEFT: 8px; POSITION: absolute; TOP: 48px" type="text"></FONT></form>
    </body>
    </HTML>cs:
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Configuration;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;namespace WebApplication2
    {
    /// <summary>
    /// WebForm1 的摘要说明。
    /// </summary>
    public class WebForm1 : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.DataGrid DataGrid1; SqlConnection sc=new SqlConnection("server=localhost;database=pubs;uid=zxy;pwd=zxy");

    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    if (!this.IsPostBack)
    {
    BindData();
    }
    } private void BindData()
    {
    SqlDataAdapter sp=new SqlDataAdapter("select au_id,title_id from titleauthor order by au_id,title_id",sc);
    DataSet ds=new DataSet();
    sp.Fill(ds,"titleauthor");
    DataGrid1.DataSource=ds.Tables[0].DefaultView;
    DataGrid1.DataBind();
    } #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.DataGrid1.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.DataGrid1_ItemDataBound);
    this.DataGrid1.SelectedIndexChanged += new System.EventHandler(this.DataGrid1_SelectedIndexChanged);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
    {
     this.Response.Write(((Label)DataGrid1.SelectedItem.FindControl("L_au_id")).Text);
    } private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
    e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
    e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='LightGoldenrodYellow';Form1.text1.value='"+((Label)e.Item.FindControl("L_au_id")).Text+"';") ;
    e.Item.Style["cursor"] = "hand";
    } }
    }
    }