asp.net – Gridview行编辑 – 动态绑定到DropDownList
发布时间:2020-12-15 18:41:53 所属栏目:asp.Net 来源:网络整理
导读:我正在尝试获取一个ASP.NET 3.5 GridView在显示时显示选定的值作为字符串,并显示一个DropDownList,以允许我在编辑时从给定的选项列表中选择一个值。看起来很简单? 我的gridview看起来像这样(简化): asp:GridView ID="grvSecondaryLocations" runat="serv
我正在尝试获取一个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控件,并询问好友没有帮助。 谁能找到缺少的链接? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- .net – 一键更新所有WCF服务参考(两次点击也可以!)
- 在子文件夹中运行MVC的Asp.net WebForms应用程序
- asp.net – Microsoft.Jet.OLEDB.4.0未在本地系统中注册
- 如何以编程方式找到一个ASP.NET App_Data文件夹路径
- xamarin – ASP.NET核心Web API与ASP.NET核心应用程序
- .Net平台开发的技术规范与实践精华
- asp.net-mvc – ASP.NET MVC:与非移动视图一起使用的移动布
- Dapper和MVC VNext中的问题
- 用于高级搜索/过滤的.Net WebAPI URI约定
- ASP.NET linkbutton两次提高onBeforeUnload事件
推荐文章
站长推荐
- 如何在ASP.net中获取页面中的主页?
- ASP.NET ViewState的工作原理
- asp.net – .NET应用程序服务器与Java应用程序服
- .net – 带有数据绑定控件的“无效的回发或回调参
- asp.net – DirectoryServicesCOMException 8007
- asp.net-mvc – 强大的自托管服务器的最佳选择:
- asp.net-mvc – ASP.NET MVC WebApi:没有为此对
- asp.net-mvc – 使用复杂类型嵌套对象的bind属性
- asp.net-mvc – 在ASP.NET MVC应用程序中放置数据
- 在servicestack中使用asp.net身份验证
热点阅读