I want to bind gridview which is inside a repeater. My code is
<asp:Repeater ID="rep_UnAssignComps" runat="server">
<ItemTem开发者_Go百科plate>
<asp:GridView ID="rep_DataSimilarToBacthid" runat="server" Style="text-align: center;
width: 375px;" AutoGenerateColumns="false">
<Columns>
<asp:BoundField HeaderText="Test" DataField="Test" />
</Columns>
</asp:GridView>
</ItemTemplate>
</asp:Repeater>
you have to fire repeater's ItemDataBound event. In which you have to find gridview then bind it as following:-
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
Dim grd As GridView = TryCast(e.Item.FindControl("rep_DataSimilarToBacthid"), GridView)
grd.DataSource = dt
grd.DataBind()
end if
If your entity whitch is bounded to the repeate have necessare data source (list of entities for example) just specify to the DataSource of the GridView with this property.
<asp:GridView ID="rep_DataSimilarToBacthid" runat="server" Style="text-align: center;
width: 375px;" AutoGenerateColumns="false" DataSource='<%# Eval("GridDataSource") %>'>
where GridDataSource is collection of items.
Also you can define the method witch will specify the datasource at the codebehind and call it:
Page.aspx
<asp:GridView ID="rep_DataSimilarToBacthid" runat="server" Style="text-align: center;
width: 375px;" AutoGenerateColumns="false" DataSource='<%# GetGridViewData(Container.DataItem) %>'>
CodeBehind.cs
public List<GridViewDataItem> GetGridViewData(Object repeaterObject)
{
// define what you need here
}
Also, check the posts:
Binding gridview inside a repeater
Adding Gridview nested in Repeater in ASP.NET 2.0
Repeater within Gridview in C# ASP.NET 2.0 - the concept the same in your case
Bind Repeater's DataRow to GridView's DataSource
加载中,请稍侯......
精彩评论