将 EditItemTemplate DropDownList 保存到数据库吗?
我有一个实体数据模型,它抽象了底层的 MSSQL 数据库。我有一个连接到 GridView 的 EntityDataSource。 GridView 有许多列 - 大多数是 BoundField,但其中一列是 EditItemTemplate。在此模板内部,我放置了以下内容:
<asp:EntityDataSource ID="EditRoleDataSource" runat="server"
ConnectionString="name=pbu_checklistEntities"
DefaultContainerName="pbu_checklistEntities" EnableFlattening="false"
EntitySetName="Roles" />
<asp:DropDownList ID="ddlRoles" runat="server" DataSourceID="EditRoleDataSource"
DataTextField="RoleName" DataValueField="ID" OnInit="ddlRoles_Init" />
代码执行正常,我可以单击“编辑”并更改选定的下拉列表,但是当我单击 GridView 中的“更新”按钮时,它不会使用 datavaluefield 值更新数据库中的值来自编辑项目模板。如何才能将 edititemtemplate 中的选定值保存到数据库中?
I have a Entity Data Model which abstracts an underlying MSSQL database. I have an EntityDataSource which is wired up to a GridView. The GridView has a number of columns - most are BoundFields, but one is an EditItemTemplate. Inside of this template I've placed the following:
<asp:EntityDataSource ID="EditRoleDataSource" runat="server"
ConnectionString="name=pbu_checklistEntities"
DefaultContainerName="pbu_checklistEntities" EnableFlattening="false"
EntitySetName="Roles" />
<asp:DropDownList ID="ddlRoles" runat="server" DataSourceID="EditRoleDataSource"
DataTextField="RoleName" DataValueField="ID" OnInit="ddlRoles_Init" />
The code executes okay and I can click edit and change the selected dropdownlist, but when I click the Update button in the GridView it doesn't update the value in the database with the datavaluefield value from the edititemtemplate. How can I get it to save the selected value from the edititemtemplate to the database?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为 DropDownList 的
SelectedValue
的绑定丢失。假设您在网格或表单中编辑一个User
,该用户具有一个RoleID
属性来引用分配的角色,这可能如下所示:I think that the binding of the DropDownList's
SelectedValue
is missing. Assuming that you are in a grid or form to edit aUser
which has aRoleID
property to refer to the assigned role, this could look like:EntityDataSource 必须指定 EnableUpdate="true"。检查 MSDN。
The EntityDataSource has to specify EnableUpdate="true". Check MSDN.