Using Repeater Control as a command parameter for a nested gridview
I have a repeater which contains a nested gridview. Now I need to be able to retrieve a value databound in a label inside of a repeater and use it as an input parameter for the gridview.
Here is some code which will hopefully give you a better idea of what I'm trying to do.
enter code here
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="RepeaterDS" OnItemDataBound="Repeater1_SendRollNumber">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<table style="width: 615px;" id="Table1">
<tr>
<td>
<b>Roll #:</b>
<asp:Label runat="server" ID="RollIDLabel" Text='<%# Eval("RollID") %>' />
<asp:Label runat="server" ID="RollIDLabelCode" Text='<%# Eval("RollID") %>' Visible="false" />
</td>
</tr>
<tr>
<td>
<b>Address:</b>
<asp:Label runat="server" ID="AddressLabel" Text='<%# Eval("Address") %>' />
</table>
<asp:Label ID="Label1" runat="server"><b>Parties:</b></asp:Label>
<asp:GridView ID="GridView3" runat="server" BackColor="White" BorderColor="#DEDFDE"
BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Vertical"
AllowPaging="True" Width="620px" DataSourceID="AssessmentDetailsFromRollIDDS"
EmptyDataText="None Associated" AutoGenerateColumns="False" ShowFooter="true">
<asp:TemplateField HeaderText="Property Assessment" HeaderStyle-Font-Bold="true"
FooterStyle-BackColor="White">
开发者_如何学C <ItemTemplate>
<asp:Label ID="PropAssessType" runat="server" Width="90%" Text='<%# Eval("PropertyAssessmentType") %>'></asp:Label>
<asp:Label ID="PropAssessDsc" runat="server" Text='<%# Eval("PropertyAssessmentDesc") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:TemplateField>
<RowStyle BackColor="#F7F7DE" />
<FooterStyle BackColor="#CCCC99" />
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#3E4E4E" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</ItemTemplate>
</asp:Repeater>
<asp:ObjectDataSource ID="RepeaterDS" runat="server" OldValuesParameterFormatString="original_{0}"
SelectMethod="GetRollNumberbyAppealID" TypeName="BusinessLayer.BSO.Roll_AssessmentDetailsBSO">
<SelectParameters>
<asp:QueryStringParameter Name="AppealID" QueryStringField="appealID" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="AssessmentDetailsFromRollIDDS" runat="server" OldValuesParameterFormatString="original_{0}"
SelectMethod="GetAssessDetailsFromRollID" OnSelecting="AssessmentDetailsFromRollIDDS_Selecting" TypeName="BusinessLayer.BSO.Assessment_DetailsBSO">
<SelectParameters>
<asp:ControlParameter Name="RollID" ControlID="RollIDLabelCode" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
I've tried to cut out as much code as possible while leaving the guts of the problem in. So I basically want the label control RollIDLabelCode which is located in a repeater to also be an input into my gridview. The problem is that I keep getting errors such as can't find the control RollIDLabelCode. I've heard there is a bug in which you need to specify all naming containers. which I've tried with no luck.
Another route I've tried is doing this in the code behind.
enter code here
public void Repeater1_OnItemDataBound(Object Sender, RepeaterItemEventArgs e)
{
// Execute the following logic for Items and Alternating Items.
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
string test = ((Label)e.Item.FindControl("RollIDLabel")).Text;
}
}
public void AssessmentDetailsFromRollIDDS_OnSelecting(object sender, ObjectDataSourceSelectingEventArgs e)
{
e.InputParameters["RollID"] = "Need the Info here";
}
These functions are called on the repeater being databound and the objectdatasource onselecting function. And these work separately very well. I just need to know how to get the information from the string test in the Repeater1_OnItemDataBound function to the e.InputParameters["RollID"] in the OnSelecting function.
Hopefully someone knows how to do this. I am new to .net programming. I appreciate any help.
Thanks!
The RollIDLabelCode label is set visible=false which means it will not exist when rendered so trying to access the value won't be possible. You'll need to use a different control that is hidden but exists when rendered. For instance a GridView has a datakeys that exist within the control but are not rendered. It is used to retrieve a key value for the row to retreive more data, for example.
精彩评论