I have a Gridview control that returns rows from a table called workerID. I return 10 rows at a time and allow paging. What I would like to do is place a HiddenField
in a template within the Gridview. I want to assign or bind a value from the Gridview control to the HiddenField
. The value I want to bind is workerID.
I then want to be able to submit the value assigned to the HiddenField
to another page that that has a SqlDataSource
with a formfield parameter that is looking for the value of the HiddenField
to be passed. To do this I also put a submit button in the item template field along side the hidden field. My assumption is that the submit button would post the HiddenField
value of each row to my second page looking to receive the formfield parameter (Hiddenfield1).
I believe my assumption is wrong and there is some more coding or work that needs to be done. In summary I am trying to bind each row value in a GridView control (value of workerID) and then post that value to another page that will receive it. I find it easy to pass a url value from the gridview but in this case passing a url querystring is not an option.
Page 1 - With the hiddenfield:
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="workoutID" DataSourceID="SqlDataSource5">
<Columns>
<asp:BoundField DataField="workoutID" HeaderText="workoutID" InsertVisible="False" ReadOnly="True" SortExpression="workoutID" />
<asp:BoundField DataField="workoutTitle" HeaderText="workoutTitle" SortExpression="workoutTitle" />
<asp:BoundField DataField="UserID" HeaderText="UserID" SortExpression="UserID" />
<asp:BoundField DataField="description" HeaderText="description" SortExpression="description" />
<asp:BoundField DataField="exercisenotes" HeaderText="exercisenotes" SortExpression="exercisenotes" />
<asp:TemplateField>
<ItemTemplate>
<asp:HiddenField ID="HiddenField1" runat="server" Value='<%# Eval("workoutID") %>' />
<asp:Button ID="Button1" runat="server" PostBackUrl="~/postfromgridview.aspx" Text="Button" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Page 2 - With SQLdatasource and formfield parameter:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="workoutID" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="workoutID" HeaderText="workoutID" InsertVisible="False" ReadOnly="True" SortExpression="workoutID" />
<asp:BoundField DataField="workoutTitle" HeaderText="workoutTitle" SortExpression="workoutTitle" />
<asp:BoundField DataField="UserID" HeaderText="UserID" SortExpression="UserID" />
<asp:BoundField DataField="description" HeaderText="description" SortExpression="description" />
</Columns>
</asp:GridView>
</td>
<td>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:SQL2008R2_504887_golivefitnesConnectionString %>" SelectCommand="workout_testing" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:FormParameter FormField="Hiddenfield1" Name="workoutID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>