2009-09-23 60 views
0

我有以下的GridView問題的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> 

具有問題IM是當該組合框被改變的值是不是被更新是否有一些明顯的我錯過了?

回答

2

使用綁定而不是Eval。綁定用於雙向數據綁定:

<asp:DropDownList ID="DropDownList2" runat="server" SelectedValue='<%# Bind("ApprovalStatusID") %>' 
    DataSourceID="CommentStatusDataSource" DataTextField="Name" DataValueField="ID"> 
</asp:DropDownList> 
+0

是的,這個問題非常感謝! –