Reputation: 2000
I have a gridview where the user can edit a uniqueID, this should then update where the column REF is the unique identifier
However, this isn't working, there are no errors, the page just refreshes when update is clicked and nothing changes:
Any help is appreciated thanks
<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>
Upvotes: 1
Views: 4280
Reputation: 860
Add the ref parameter as a QueryStringParameter
<SelectParameters>
<asp:QueryStringParameter Name="ref" QueryStringField="ref" />
</SelectParameters>
Upvotes: 0
Reputation: 6586
You need to add DataKeyNames to your gridview like this:
<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.
Upvotes: 3