C# GridView, RowDataBound(object sender, GridViewRowEventArgs e)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1134549/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 09:02:44  来源:igfitidea点击:

GridView, RowDataBound(object sender, GridViewRowEventArgs e)

c#.netgridview

提问by flavour404

Firing a RowDataBound event, my question is how do I pull out the DataKey for GridviewRowEventArgs e?

触发 RowDataBound 事件,我的问题是如何为 GridviewRowEventArgs e 拉出 DataKey?

I have a table of Publications and surprisingly enough the key is PublicationID, however I do not have a boundfield to publication id but have it specified as a datakeyname. I can get the information using:

我有一个出版物表,令人惊讶的是,关键是出版物 ID,但是我没有出版物 ID 的绑定字段,但将其指定为数据键名。我可以使用以下方法获取信息:

int pID =Convert.ToInt32(DataBinder.Eval(e.Row.DataItem,"PublicationID"));

But was wondering if there is a more elegant way of getting the information?!

但是想知道是否有更优雅的获取信息的方式?!

Also, if I investigate e, i can see the underlying table (publication) which also has a child table owner, does anybody know how I could, from the point in the app i.e. inside the RowDataBound event pull information out of the child table?

另外,如果我调查 e,我可以看到也有一个子表所有者的基础表(出版物),有谁知道我如何从应用程序中即 RowDataBound 事件内的点从子表中提取信息?

This is all .Net 3.0, C#.

这都是 .Net 3.0,C#。

Thanks, R.

谢谢,R。

回答by JBrooks

((GridView)sender).DataKeys[e.Row.RowIndex].Value.ToString();

((GridView)sender).DataKeys[e.Row.RowIndex].Value.ToString();