你如何绑定在EditItemTemplate里场一个GridView一个DropDownList? [英] How do you bind a DropDownList in a GridView in the EditItemTemplate Field?
问题描述
下面是在运行时绑定的GridView我的code:
Here's my code in a gridview that is bound at runtime:
...
<asp:templatefield>
<edititemtemplate>
<asp:dropdownlist runat="server" id="ddgvOpp" />
</edititemtemplate>
<itemtemplate>
<%# Eval("opponent.name") %>
</itemtemplate>
</asp:templatefield>
...
我要DropDownList的ddgvOpp绑定,但我不知道怎么办。我应该,但我不知道。下面是我的,但我不断收到对象引用的错误,这是有道理的:
I want to bind the dropdownlist "ddgvOpp" but i don't know how. I should, but I don't. Here's what I have, but I keep getting an "Object reference" error, which makes sense:
protected void gvResults_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow) //skip header row
{
DropDownList ddOpp = (DropDownList)e.Row.Cells[5].FindControl("ddgvOpp");
BindOpponentDD(ddOpp);
}
}
其中, BindOpponentDD()
是DropDownList的被填充流向何方。我不能这样做在右边的事件吗?如果没有,这我需要把它吗?
Where BindOpponentDD()
is just where the DropDownList gets populated. Am I not doing this in the right event? If not, which do I need to put it in?
在此先感谢这么多...
Thanks so much in advance...
推荐答案
好吧,我想我只是哑巴。我想它了。
Ok, I guess I'm just dumb. I figured it out.
在RowDataBound事件,只需添加以下条件:
In the RowDataBound event, simply add the following conditional:
if (myGridView.EditIndex == e.Row.RowIndex)
{
//do work
}
这篇关于你如何绑定在EditItemTemplate里场一个GridView一个DropDownList?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!