I have a repeater on my page, linked with a datasource who fills the repeater with teams. My goal is to create a header for each team and a gridview for each team to modify the players in each team.
Problem: the datasource of the gridview needs a PK of the team to get the appropriate players out of the database. How can I pass them?
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="odsTeam">
<ItemTemplate>
<h1>
<%# Eval("name") %>
with maximum of
<%# Eval("st_max") %>
players.</h1>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="participant_id"
DataSourceID="odsParticipant">
<Columns>
<asp:BoundField DataField="participant_id" HeaderText="participant_id" InsertVisible="False"
ReadOnly="True" SortExpression="participant_id" />
<asp:BoundField DataField="participant_category_id" HeaderText="participant_category_id"
SortExpression="participant_category_id" />
<asp:BoundField DataField="team_id" HeaderText="team_id" SortExpression="team_id" />
<asp:BoundField DataField="room_id" HeaderText="room_id" SortExpression="room_id" />
<asp:BoundField DataField="delegation_id" HeaderText="delegation_id" SortExpression="delegation_id" />
<asp:BoundField DataField="first_name" HeaderText="first_name" SortExpression="first_name" />
<asp:BoundField DataField="last_name" HeaderText="last_name" SortExpression="last_name" />
<asp:BoundField DataField="date_of_birth" HeaderText="date_of_birth" SortExpression="date_of_birth" />
<asp:BoundField DataField="gender" HeaderText="gender" SortExpression="gender" />
<asp:BoundField DataField="identification_number" HeaderText="identification_number"
SortExpression="identification_number" />
<asp:BoundField DataField="photo_url" HeaderText="photo_url" SortExpression="photo_url" />
<asp:BoundField DataField="squad_number" HeaderText="squad_number" SortExpression="squad_number" />
<asp:BoundField DataField="length" HeaderText="length" SortExpression="length" />
<asp:BoundField DataField="weight" HeaderText="weight" SortExpression="weight" />
</Columns>
</asp:GridView>
</ItemTemplate>
</asp:Repeater>
<asp:ObjectDataSource ID="odsTeam" runat="server" OldValuesParameterFormatString="original_{0}"
OnSelecting="odsTeam_Selecting" SelectMethod="GetTeamsByDelegationID" TypeName="TeamBLL">
<SelectParameters>
<asp:Parameter Name="delegation_id" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="odsParticipant" runat="server" DeleteMethod="Dele开发者_高级运维te" InsertMethod="Insert"
OldValuesParameterFormatString="original_{0}" SelectMethod="GetParticipantsByTeamID"
TypeName="ERASTableAdapters.tbl_participantTableAdapter"
UpdateMethod="Update" onselecting="odsParticipant_Selecting">
<DeleteParameters>
<asp:Parameter Name="Original_participant_id" Type="Int32" />
<asp:Parameter Name="Original_participant_category_id" Type="String" />
<asp:Parameter Name="Original_team_id" Type="Int32" />
<asp:Parameter Name="Original_room_id" Type="Int32" />
<asp:Parameter Name="Original_delegation_id" Type="Int32" />
<asp:Parameter Name="Original_first_name" Type="String" />
<asp:Parameter Name="Original_last_name" Type="String" />
<asp:Parameter Name="Original_date_of_birth" Type="DateTime" />
<asp:Parameter Name="Original_gender" Type="String" />
<asp:Parameter Name="Original_identification_number" Type="String" />
<asp:Parameter Name="Original_photo_url" Type="String" />
<asp:Parameter Name="Original_squad_number" Type="Int32" />
<asp:Parameter Name="Original_length" Type="Decimal" />
<asp:Parameter Name="Original_weight" Type="Decimal" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="participant_category_id" Type="String" />
<asp:Parameter Name="team_id" Type="Int32" />
<asp:Parameter Name="room_id" Type="Int32" />
<asp:Parameter Name="delegation_id" Type="Int32" />
<asp:Parameter Name="first_name" Type="String" />
<asp:Parameter Name="last_name" Type="String" />
<asp:Parameter Name="date_of_birth" Type="DateTime" />
<asp:Parameter Name="gender" Type="String" />
<asp:Parameter Name="identification_number" Type="String" />
<asp:Parameter Name="photo_url" Type="String" />
<asp:Parameter Name="squad_number" Type="Int32" />
<asp:Parameter Name="length" Type="Decimal" />
<asp:Parameter Name="weight" Type="Decimal" />
<asp:Parameter Name="Original_participant_id" Type="Int32" />
<asp:Parameter Name="Original_participant_category_id" Type="String" />
<asp:Parameter Name="Original_team_id" Type="Int32" />
<asp:Parameter Name="Original_room_id" Type="Int32" />
<asp:Parameter Name="Original_delegation_id" Type="Int32" />
<asp:Parameter Name="Original_first_name" Type="String" />
<asp:Parameter Name="Original_last_name" Type="String" />
<asp:Parameter Name="Original_date_of_birth" Type="DateTime" />
<asp:Parameter Name="Original_gender" Type="String" />
<asp:Parameter Name="Original_identification_number" Type="String" />
<asp:Parameter Name="Original_photo_url" Type="String" />
<asp:Parameter Name="Original_squad_number" Type="Int32" />
<asp:Parameter Name="Original_length" Type="Decimal" />
<asp:Parameter Name="Original_weight" Type="Decimal" />
</UpdateParameters>
<SelectParameters>
<asp:Parameter Name="team_id" Type="Int32" />
</SelectParameters>
<InsertParameters>
<asp:Parameter Name="participant_category_id" Type="String" />
<asp:Parameter Name="team_id" Type="Int32" />
<asp:Parameter Name="room_id" Type="Int32" />
<asp:Parameter Name="delegation_id" Type="Int32" />
<asp:Parameter Name="first_name" Type="String" />
<asp:Parameter Name="last_name" Type="String" />
<asp:Parameter Name="date_of_birth" Type="DateTime" />
<asp:Parameter Name="gender" Type="String" />
<asp:Parameter Name="identification_number" Type="String" />
<asp:Parameter Name="photo_url" Type="String" />
<asp:Parameter Name="squad_number" Type="Int32" />
<asp:Parameter Name="length" Type="Decimal" />
<asp:Parameter Name="weight" Type="Decimal" />
</InsertParameters>
</asp:ObjectDataSource>
I know one work around that I have used one time...
First of all put your hidden field in your repeater and bind your id and then in your gridview datasource provide a hidden field control as a select parameter:
<h1>
<%# Eval("name") %>
with maximum of
<%# Eval("st_max") %>
players.</h1>
<asp:HiddenField runat="server" ID="hdfId" Value='<%# Eval("TeamId") %>' />
<asp:ObjectDataSource ID="odsTeam" runat="server" OldValuesParameterFormatString="original_{0}"
OnSelecting="odsTeam_Selecting" SelectMethod="GetTeamsByDelegationID" TypeName="TeamBLL">
<SelectParameters>
<asp:ControlParameter PropertyName="value" Name="delegation_id" ControlID="hdfId" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
精彩评论