是否可以在“行命令"事件中获取数据键值 [英] is it possible to get a Datakey value in a Row Command event
本文介绍了是否可以在“行命令"事件中获取数据键值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我整个上午都在为这个问题而苦苦挣扎...可能,我需要为特定的数据行提供值
这是我尝试过的代码
Hi ive been struggling all morning over this issue...it it possible, i need the value to for a particular datarow
here is the code ive tried
protected void Get_RowData(object sender, GridViewCommandEventArgs e)
{
//int ind = GridView1.SelectedIndex;
//string id = GridView1.DataKeys[ind].Value.ToString();
if (e.CommandName == "Modify")
{
GridViewRow row = (GridViewRow)((LinkButton)e.CommandSource).NamingContainer;
int index = row.RowIndex;
int employeeID = Convert.ToInt32(GridView1.DataKeys[index].Value);
table1.Visible = true;
// int index = Convert.ToInt32(e.CommandArgument);
// string indextest = GridView1.DataKeys[Convert.ToInt32(e.CommandArgument)].Values["airid"].ToString();
SqlConnection con = new SqlConnection(connectionString);
con.Open();
//SqlDataAdapter da = new SqlDataAdapter("sp_GetAir", con);
DataSet ds2 = _ds.Copy();
// da.Fill(ds2);
DataTable dt = ds2.Tables[0];
DataRow dr = dt.Rows[employeeID];
txtairline.Text = dr["airlines"].ToString();
txtdepcity.Text = dr["depcity"].ToString();
txtdeptime.Text = dr["deptime"].ToString();
txtdepdate.Text = dr["depdate"].ToString();
txtarrvcity.Text = dr["arrvcity"].ToString();
txtarrvtime.Text = dr["arrvtime"].ToString();
txtarrvdate.Text = dr["arrvdate"].ToString();
}
}
推荐答案
这是您在代码中用于获取特定行中数据键值的行.
This is the line you have used in your code to get the datakey value in particular row.
int employeeID = Convert.ToInt32(GridView1.DataKeys[index].Value);
这篇关于是否可以在“行命令"事件中获取数据键值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文