当前位置:编程学习 > C#/ASP.NET >>

gridview rowcommand 如何获取当前行的值

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {

if (e.CommandName == "AAA")
        {
             string a = e.CommandArgument.ToString();
             string sql= "select * from abc where id ='" + a + "'";
             SqlCommand command = new SqlCommand(sql, Connection);
             SqlDataReader Dr = command.ExecuteReader();
             while (Dr.Read())
             {
                 a.Text = Dr["a"].ToString();
                 b.Text = Dr["b"].ToString();
             }
             Dr.Close();
             Connection.Close();
        }
}

我现在用的是从数据库读出来的方法,但是效率很差,很慢,能否有方法直接读取呢? --------------------编程问答-------------------- 为什么不从gridview中取呢。
给CommandArgument赋值的时候,就应该把行号传进来。
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = GridView1.Rows[index];
--------------------编程问答-------------------- CommandArgument='<%# Eval("id") %>'  


这是我取ID的
怎么取行号?
id 对我后面还有用,取id的不影响情况下能取行号么?
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,