解决方案 »

  1.   

    GridView1.Rows[e.NewSelectedIndex].Cells[4].Text
      

  2.   

    您给的这个案例好像跟我问的对不上号啊一样的!!!also refer these:
    http://www.cnblogs.com/insus/archive/2011/06/30/2094151.html
    http://www.cnblogs.com/insus/p/3201720.html
    http://www.cnblogs.com/insus/p/3680461.html
      

  3.   

    e.NewSelectedIndex 
    你这个不是获取当前选择的行号吗?
      

  4.   

    获取GridView里某行某列的值示例
    //GridView设置
    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                                                    CellPadding="4" Font-Size="9pt" ForeColor="#333333" GridLines="None" 
                                                    Width="500px" OnRowDeleting="GridView1_RowDeleting" 
                                                    OnPageIndexChanging="GridView1_PageIndexChanging" 
                                                    OnRowDataBound="GridView1_RowDataBound" PageSize="6" Height="1px">
                                                    <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                                                    <RowStyle BackColor="#E3EAEB" />
          <Columns>//codego.net/tags/11/1/
                                                        <asp:BoundField DataField="ST_n_id" HeaderText="文章ID" />
                                                        <asp:BoundField DataField="ST_n_title" HeaderText="文章主题" />
                                                        <asp:BoundField DataField="ST_n_hit" HeaderText="人气指数" />
                                                        <asp:BoundField DataField="ST_n_re" HeaderText="评论" />
                                                        <asp:HyperLinkField DataNavigateUrlFields="ST_n_id" DataNavigateUrlFormatString="ViewContent.aspx?id={0}"
                                                            HeaderText="查看信息" Text="查看信息" />
                                                        <asp:CommandField HeaderText="删除" ShowDeleteButton="True" />
                                                        <asp:TemplateField HeaderText="选择">
                                                            <ItemTemplate>
                                                                <asp:CheckBox ID="CheckBox1" runat="server" Font-Size="9pt" Width="9px" />
                                                            </ItemTemplate>
                                                        </asp:TemplateField>
                                                    </Columns>
                                                    <SelectedRowStyle BackColor="#C5BBAF" ForeColor="#333333" Font-Bold="True" />
                                                    <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
                                                    <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                                                    <EditRowStyle BackColor="#7C6F57" />
                                                    <AlternatingRowStyle BackColor="White" />
                                                </asp:GridView>
    //加载数据库数据
      SqlData da = new SqlData();
        private static string ID;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                /*判断是否登录*/
                ST_check_Login();
            }
            //定义一个查询用户信息的SQL语句
            string sqlstr = "select * from tb_Blog where UserName='" + Session["UserName"] + "'";
            //调用公共类中的GetDataSet方法执行SQL语句,并返回DataSet类型的数据集
            DataSet mydataset = da.GetDataSet(sqlstr, "tb_Blog");
            //创建数据表的视图
            DataRowView rowview1 = mydataset.Tables["tb_Blog"].DefaultView[0];
            //获取注册博客的编号
            ID = rowview1["BlogID"].ToString();
            //调用自定义绑定方法绑定数据
            ST_Article_Bind();
        }
    //绑定数据库显示数据
      public void ST_Article_Bind()
        {
            //根据获取的用户ID查询其所有文章
            string sqlstr = "select * from ST_news where BlogID='" + ID + "'";
            //调用公共类中的ExceDS方法,返回一个DataSet类型的数据集,并作为GridView控件的数据源
            GridView1.DataSource = da.ExceDS(sqlstr);
            //获取GridView控件中的主键字段
            GridView1.DataKeyNames = new string[] { "ST_n_id" };
            //从数据库中绑定数据到列表控件中
            GridView1.DataBind();
        }
    //查看某行某列信息跳转ViewContent.aspx
    <asp:Label ID="labSubject" runat="server" Width="316px" Font-Size="9pt" ></asp:Label>//显示主题
    <asp:TextBox ID="txtContent" runat="server" Font-Size="9pt" Height="257px" TextMode="MultiLine"
                Width="405px"></asp:TextBox>//显示内容
    //加载绑定数据库内容显示数据
     protected void Page_Load(object sender, EventArgs e)
    {
                    if (!IsPostBack)
            {
                try
                {
                    string str;
                    string str2 = Page.Request["id"].ToString();
                    //此处用来实现将数据绑定到前台
                    SqlConnection mycon = new SqlConnection(ConfigurationManager.AppSettings["conStr"]);
                    mycon.Open();
                    SqlDataAdapter myada = new SqlDataAdapter("select * from ST_news where ST_n_id='" + str2 + "'", mycon);
                    DataSet ds = new DataSet();
                    myada.Fill(ds, "ST_news");
                    //创建DataRowView对象的一个实例
                    DataRowView rowview = ds.Tables["ST_news"].DefaultView[0];
                    //将文章主题读取到labSubject文本框中
                    this.labSubject.Text = rowview["ST_n_title"].ToString();
                    //将文章内容读取到txtContent文本框中
                    this.txtContent.Text = rowview["ST_n_content"].ToString();
                    mycon.Close();
                }
                catch (Exception ex)
                {
                    Response.Write(ex.Message);
                }
            }
    }