需要有关绑定问题的帮助

时间:2012-08-23 12:28:59

标签: asp.net data-binding gridview asprepeater

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

1 个答案:

答案 0 :(得分:0)

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

<asp:TemplateField>
    <ItemTemplate>
        <asp:Literal ID="FirstNameLiteral" runat="server" Text='<%# Eval("FirstName") %>'></asp:Literal>
    </ItemTemplate>
    ....
</asp:TemplateField>