0

我在页面中有一个转发器控件,在转发器控件中有一个 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;
    }
4

1 回答 1

0

使用Literal控件显示 FirstName,如下所示:

<asp:TemplateField>
    <ItemTemplate>
        <asp:Literal ID="FirstNameLiteral" runat="server" Text='<%# Eval("FirstName") %>'></asp:Literal>
    </ItemTemplate>
    ....
</asp:TemplateField>
于 2012-08-23T12:50:41.087 回答