简单的Gridview RowDataBound问题 [英] Simple Gridview RowDataBound question
本文介绍了简单的Gridview RowDataBound问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨.
我已经搜索了一段时间,但找不到这个非常简单的问题的答案!
我有一个gridview,我手动填充了字段.
然后我有这种方法:
Hi.
I´ve been searching for a while now, but cant find the answer for this very simple question!
I have a gridview, which I populate with fields manually.
And then I have this method:
protected void GridViewResults_RowDataBound(object sender, GridViewRowEventArgs e) {
if (e.Row.RowType==DataControlRowType.DataRow) {
}
}
现在,我要在其中键入什么,以使用名为"ID"的列中的ID参数来调用同一代码隐藏文件中的方法?
例如,此方法:
Now what do I type in there, to make a call to a method in the same codebehind file, with an ID parameter from a column called "ID" ?
For an example this method:
protected void CallMe(int Id) {
}
希望您能提供帮助:)
hope you can help :)
推荐答案
如果使用e.Row.DataItem
,您将获得绑定的对象.
[更新]
如果您的数据源是List<Employee>
,那么您将使用此属性获得Employee
对象.然后从该对象获取所需的任何属性.
If you usee.Row.DataItem
you''ll get the bound object.
[UPDATE]
If your DataSource isList<Employee>
then you''ll getEmployee
object using this property. And then get whatever property you want from that object.
尝试一下...
try this...
protected void GridViewResults_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType==DataControlRowType.DataRow)
{
string str="";
/*if you have "ID" Column as BOUNDCOLUMN*/
str = e.Row.Cells["ID Column Index"].Text;
/*else if You have "ID" Column as TEMPLATECOLUMN then You must get the reference to the Control which you have given in "ItemTemplate", i am assuming that you have given Label with ''ID="Label1"'' in the ItemTemplate*/
Label tempLabel = (Label)e.Row.Cells["ID Column Index"].FindControl("Label1")/*finding control with ID in Particular Cell*/
if(tempLabel!=null)
str=tempLabel.Text;
/*Now You got the text to pass in "str" in both types "BOUNDCOLUMN" and "TEMPLATECOLUMN".. just pass it now*/
CallMe(str);
}
}
我已经更新了此问题.
此处:
http://www.codeproject.com/Questions/99790/Bind-a-call-to-codebehind-method-AND-javascript-jq.aspx
谢谢! :)
I´ve updated this question.
Here:
http://www.codeproject.com/Questions/99790/Bind-a-call-to-codebehind-method-AND-javascript-jq.aspx
Thanks! :)
这篇关于简单的Gridview RowDataBound问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文