Wednesday, 2 October 2013

How to pass an ID from a repeater row to a nested gridview?

How to pass an ID from a repeater row to a nested gridview?

QUESTION
If you have a gridview inside a repeater, how do you pass a primary key ID
to the gridview where the primary key relates to the repeaters item
template row?
I am currently attempting to do this by using a hiddenfield that contains
the PK and a control parameter to detect it and bind it to the gridview.
CURRENT ERROR
Could not find control 'hidPK' in ControlParameter 'PK'.
ABBREVIATED CODE
<asp:Repeater ID="rpt" RunAt="Server">
<ItemTemplate>
<asp:HiddenField ID="hidPK" runat="server" Value='<%#
DataBinder.Eval(Container.DataItem, "PK") %>'/>
<asp:GridView DataSourceID="sqlSource"></asp:GridView>
</ItemTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="sqlSource" RunAt="Server"
SelectCommand="spPopulateGridview" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter Type="Int32" Name="PK" DefaultValue="0"
ControlID="hidPK"/>
</SelectParameters>
</asp:SqlDataSource>

No comments:

Post a Comment