ASP GridView更新无法正常工作

时间:2014-03-05 14:35:04

标签: asp.net vb.net gridview

我有一个gridview,用户可以在其中编辑uniqueID,然后应该更新列REF是唯一标识符的位置

但是,这不起作用,没有错误,点击更新后页面只刷新,没有任何变化:

感谢任何帮助

<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>

2 个答案:

答案 0 :(得分: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.

答案 1 :(得分:0)

将ref参数添加为QueryStringParameter

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