我有以下gridview
<asp:GridView ID="GridView3" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="CommentsDataSource">
<Columns>
<asp:BoundField DataField="Firstname" HeaderText="Firstname" SortExpression="Firstname" />
<asp:BoundField DataField="Surname" HeaderText="Surname" SortExpression="Surname" />
<asp:BoundField DataField="Comment" HeaderText="Comment" />
<asp:BoundField DataField="DateAdded" HeaderText="DateAdded" SortExpression="DateAdded" />
<asp:TemplateField HeaderText="Approval">
<ItemTemplate>
<%#Eval("NewsCommentStatus.Name") %>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="DropDownList2" runat="server" SelectedValue='<%# Eval("ApprovalStatusID") %>'
DataSourceID="CommentStatusDataSource" DataTextField="Name" DataValueField="ID">
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="true" EditImageUrl="~/Admin/Theme/images/Icons/pencil.png"
EditText="Edit" />
</Columns>
</asp:GridView>
</ContentTemplate>
,数据源为:
<asp:LinqDataSource ID="CommentsDataSource" runat="server" ContextTypeName="CMSSystem.Models.CMSDatabaseDataContext"
TableName="NewsComments" Where="NewsID == @NewsID" EnableUpdate="True">
<WhereParameters>
<asp:SessionParameter Name="NewsID" SessionField="NewsItemID" Type="Int32" />
</WhereParameters>
</asp:LinqDataSource>
<asp:LinqDataSource ID="CommentStatusDataSource" runat="server" ContextTypeName="CMSSystem.Models.CMSDatabaseDataContext"
TableName="NewsCommentStatus">
</asp:LinqDataSource>
我遇到的问题是当组合框被更改时,值没有被更新是否有一些明显的我错过了?
答案 0 :(得分:2)
使用绑定代替 Eval 。绑定用于双向数据绑定:
<asp:DropDownList ID="DropDownList2" runat="server" SelectedValue='<%# Bind("ApprovalStatusID") %>'
DataSourceID="CommentStatusDataSource" DataTextField="Name" DataValueField="ID">
</asp:DropDownList>