asp.net – Gridview行编辑 – 动态绑定到DropDownList
发布时间:2020-05-27 22:01:21 所属栏目:asp.Net 来源:互联网
导读:我正在尝试获取一个ASP.NET 3.5 GridView在显示时显示选定的值作为字符串,并显示一个DropDownList,以允许我在编辑时从给定的选项列表中选择一个值。看起来很简单? 我的gridview看起来像这样(简化): asp:GridView ID=grvSecondaryLocations runat=server D
|
我正在尝试获取一个ASP.NET 3.5 GridView在显示时显示选定的值作为字符串,并显示一个DropDownList,以允许我在编辑时从给定的选项列表中选择一个值。看起来很简单? 我的gridview看起来像这样(简化): <asp:GridView ID="grvSecondaryLocations" runat="server"
DataKeyNames="ID" OnInit="grvSecondaryLocations_Init"
OnRowCommand="grvSecondaryLocations_RowCommand"
OnRowCancelingEdit="grvSecondaryLocations_RowCancelingEdit"
OnRowDeleting="grvSecondaryLocations_RowDeleting"
OnRowEditing="grvSecondaryLocations_RowEditing"
OnRowUpdating="grvSecondaryLocations_RowUpdating" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lblPbxTypeCaption" runat="server"
Text='<%# Eval("PBXTypeCaptionValue") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddlPBXTypeNS" runat="server"
Width="200px"
DataTextField="CaptionValue"
DataValueField="OID" />
</EditItemTemplate>
</asp:TemplateField>
</asp:GridView>
当不在编辑模式时,网格显示为OK – 所选PBX类型在asp:Label控件中显示其值。没有惊喜 在表单的OnLoad事件中,将DropDownList的值加载到名为_pbxTypes的本地成员中。我验证了这个 – 它的作品,价值在那里。 现在我的挑战是:当网格进入特定行的编辑模式时,我需要绑定存储在_pbxTypes中的PBX列表。 很简单,我想 – 只需在RowEditing事件中抓住下拉列表对象并附加列表: protected void grvSecondaryLocations_RowEditing(object sender,GridViewEditEventArgs e)
{
grvSecondaryLocations.EditIndex = e.NewEditIndex;
GridViewRow editingRow = grvSecondaryLocations.Rows[e.NewEditIndex];
DropDownList ddlPbx = (editingRow.FindControl("ddlPBXTypeNS") as DropDownList);
if (ddlPbx != null)
{
ddlPbx.DataSource = _pbxTypes;
ddlPbx.DataBind();
}
.... (more stuff)
}
麻烦是 – 我从来没有得到任何东西从FindControl调用 – 似乎ddlPBXTypeNS不存在(或不能找到)。 我还缺少什么?必须是非常愚蠢的东西….但到目前为止,我所有的谷歌搜索,阅读GridView控件,并询问好友没有帮助。 谁能找到缺少的链接? (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – 通知面板类似于stackoverflow的
- asp.net-web-api – 我可以在WebAPI messageHandler中使用A
- asp.net-mvc – 在ControllerInstanceFilterProvider的Filt
- MvcBuildViews真实与实体框架在ASP.NET MVC 2
- asp.net – 更改用户登录名后的身份验证错误
- asp.net – 如何通过LINQ获得第一级的孩子
- asp.net – 如何使用自定义CSS与我的Sharepoint WebPart?
- asp.net-mvc – ASP MVC3 – 如何从数据库加载页面的自定义
- asp.net – HTTPS停止使用IIS express
- asp.net-mvc – ASP.NET MVC下拉列表
