0

如何将我的数据源绑定到 GridView 上的自定义控件

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" >
    <Columns>
        <asp:TemplateField >
            <ItemTemplate>
                <uc1:DVDBox ID="DVDBox1" runat="server" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField >
            <ItemTemplate>
                <uc1:DVDBox ID="DVDBox2" runat="server" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField >
            <ItemTemplate>
                <uc1:DVDBox ID="DVDBox3" runat="server" />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

我正在尝试将其与通常的绑定

        GridView1.DataSource = Results;
        GridView1.DataBind();

但它不起作用!

我是否必须解决每个自定义控件出现的每个元素的每个元素以获取要呈现的数据,还是我遗漏了什么?

4

1 回答 1

0

OK I had to answer this for myself.

So just for future reference.

        <asp:TemplateField>
        <ItemTemplate>
        <uc1:DVDBox ID="DVDBox1" runat="server" 
                    controlNameInCustomControl='<%# Bind("NameOfColumnOnSource") %>'
                    />
        </ItemTemplate>
        </asp:TemplateField>

Now I just need to work out to repeat this for several GridView Columns with the same custom control

于 2013-04-10T13:07:58.610 回答