如何将DDL绑定在Repeater内部的网格中?

时间:2011-07-14 09:08:14

标签: asp.net

在网格中再次将DDl放在转发器内的网格中。我需要在网格行数据绑定事件中绑定DDl。在Rowdatabound中获取网格索引时遇到问题,因为它在转发器内部。

protected void gvTest_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (gvTest.EditIndex == e.Row.RowIndex && e.Row.RowType == DataControlRowType.DataRow)
    {
        DropDownList drpBuild = (DropDownList) e.Row.Cells[0].FindControl("ddlBuild");
    }
}

设计:

<asp:Repeater ID="rptParent" OnItemDataBound="rptParent_OnItemDataBound" runat="server">
    <ItemTemplate>
        <table id="Table1" runat="server" cellpadding="0" cellspacing="0" width="100%" border="0">
            <tr id="Tr3" runat="server">
                <td>
                    <asp:Label ID="lblFieldID23" runat="server" Visible="false" Text='<%# DataBinder.Eval(Container.DataItem,"FieldID")%>'>
                    </asp:Label>
                </td>
            </tr>
            <tr id="Tr1" runat="server">
                <td class="tdGRD" colspan="2">
                    <div class="divScrollGrid">
                        <tw:twGridView ID="gvLabtestFeilds" runat="server" OnRowDataBound="gvLabtestFeilds_RowDataBound">
                            <Columns>
                                <asp:TemplateField ItemStyle-Width="30%">
                                    <HeaderTemplate>
                                        <asp:Label ID="lblFieldName" runat="server" Text="Test">
                                        </asp:Label>
                                    </HeaderTemplate>
                                    <ItemTemplate>
                                        <asp:Label ID="lblgvFieldName" runat="server" Text='<%# Eval("FieldName") %>'>
                                        </asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField>
                                    <HeaderTemplate>
                                        <asp:Label ID="lblBatchno" runat="server" Text="Batch Number">
                                        </asp:Label>
                                    </HeaderTemplate>
                                    <ItemTemplate>
                                        <asp:Label ID="ddlBatchNo" runat="server" CssClass="cbo">
                                        </asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                        </tw:twGridView>
                    </div>
                </td>
            </tr>
        </table>
    </ItemTemplate>
</asp:Repeater>

1 个答案:

答案 0 :(得分:0)

试试这个。

protected void gvTest_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        DropDownList drpBuild = (DropDownList) e.Row.FindControl("ddlBuild");
    }
}

P.S:我的代码中没有看到任何ddlBuild