gridview rowcommand 如何获取当前行的值

xzf_fancy 2013-11-20 04:23:55
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();
}
}

我现在用的是从数据库读出来的方法,但是效率很差,很慢,能否有方法直接读取呢?
...全文
273 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
xzf_fancy 2013-11-20
  • 打赏
  • 举报
回复
CommandArgument='<%# Eval("id") %>' 这是我取ID的 怎么取行号? id 对我后面还有用,取id的不影响情况下能取行号么?
feiniao19830822 2013-11-20
  • 打赏
  • 举报
回复
为什么不从gridview中取呢。 给CommandArgument赋值的时候,就应该把行号传进来。 int index = Convert.ToInt32(e.CommandArgument); GridViewRow row = GridView1.Rows[index];

111,097

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧