2014-03-05 51 views
0

我有一個GridView,用戶可以編輯UNIQUEID,這應該然後更新其中列REF是唯一標識符ASP GridView控件更新不工作

但是,這是行不通的,沒有錯誤,頁面只是刷新時,點擊更新並沒有什麼變化:

任何幫助表示讚賞感謝

<asp:GridView ID="GridView3" runat="server" 
      AutoGenerateColumns="False" DataSourceID="SqlDataSource2" 
      ShowHeaderWhenEmpty="True" 
      showfooterwhenempty="true" 
      ShowFooter="True" AllowPaging="True" PageSize="20" 
     CssClass="pagination myTable" 
      BorderColor="#D9D9D9" 
      borderstyle="Solid" 
      BorderWidth="1px"   

      EnableModelValidation="True" GridLines="Both" AutoGenerateEditButton="True"> 
      <HeaderStyle cssClass="myheader" BackColor="#e6EEEE" /> 
    <rowstyle CssClass="myRow" HorizontalAlign="left" BorderColor="#D9D9D9" BorderStyle="Solid" BorderWidth="1px" /> 
    <alternatingrowstyle CssClass="myAltRow" backcolor="#F0F0F6" HorizontalAlign="left" BorderColor="#D9D9D9" BorderStyle="Solid" BorderWidth="1px" /> 

<Columns> 


    <asp:BoundField DataField="uniqueID" HeaderText="uniqueID" 
     SortExpression="uniqueID" /> 

    <asp:BoundField DataField="REF" HeaderText="REF" SortExpression="REF" ReadOnly="true" /> 

</Columns> 

<emptydatarowstyle backcolor="LightBlue" forecolor="Red"/> 
<EmptyDataTemplate> 
     Please enter a unique ID in the search box above. 
    </EmptyDataTemplate> 




</asp:GridView> 



    <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
     ConnectionString="<%$ ConnectionStrings:DGRecon_DevConnectionString %>" 



     SelectCommand=" SELECT 
         * 
          FROM postfinance 
          where uniqueID = @uniqueID" 



     Updatecommand="UPDATE postfinance SET uniqueID = @uniqueID WHERE REF = @REF"> 


    <UpdateParameters> 
     <asp:Parameter Name="uniqueID" Type="String" /> 
     <asp:Parameter Name="ref" Type="String" /> 
    </UpdateParameters> 

    <SelectParameters> 
      <asp:ControlParameter Name="uniqueID" ControlID="uniqueID" /> 
    </SelectParameters> 





</asp:SqlDataSource> 
</div> 

回答

1

您需要的DataKeyNames添加到您的GridView這樣的:

<asp:GridView ID="yourGridViewId" DataKeyNames="REF" ... > 
... 
</asp:GridView> 

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.datakeynames.aspx

You must set the DataKeyNames property in order for the automatic update and delete features of the GridView control to work. The values of these key fields are passed to the data source control in order to specify the row to update or delete.

0

添加ref參數作爲QueryStringParameter

<SelectParameters> 
    <asp:QueryStringParameter Name="ref" QueryStringField="ref" /> 
</SelectParameters>