我在页面中有一个转发器控件,在转发器控件中有一个 gridview。我想绑定gridview。但我不能。当我运行它时,我的页面是空的。并且 viewsource 也是空的。这是我的代码:
<asp:Repeater ID="DataRepeater" runat="server"
onitemdatabound="DataRepeater_ItemDataBound">
<ItemTemplate>
<asp:GridView ID="DataGridView" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<%#Eval("FirstName") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="FirstNameTextbox" runat="server"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ItemTemplate>
</asp:Repeater>
protected void DataRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
DataCodeClass dc = new DataCodeClass();
if (e.Item.ItemType == ListItemType.Item)
{
GridView gvID = e.Item.FindControl("DataGridView") as GridView;
dc.GetData(gvID);
gvID.DataBind();
}
}
public void GetData(GridView gv)
{
var get_data = from a in dataContext.GetTable<PersonalDetailTable>() select a;
gv.DataSource = get_data;
}