如何在转发器中获取dropdownlist值,以便插入方法中?

时间:2010-11-22 06:35:41

标签: c# asp.net repeater

我的.aspx页面上有这个转发器:

<asp:Repeater ID="RptCart" runat="server" OnItemDataBound="RptCart_ItemDataBound"
            OnItemCommand="RptCart_ItemCommand">
            <HeaderTemplate>
                <table class="style1" style="border-style: solid; border-width: 1px">
            </HeaderTemplate>
            <ItemTemplate>
                <tr>
                    <td colspan="2">
                        &nbsp;
                    </td>
                    <td valign="top">
                        NUMBER OF SHIRTS
                    </td>
                    <td>
                        &nbsp;
                    </td>
                    <td valign="top">
                        EXTRAS
                    </td>
                    <td>
                        &nbsp;
                    </td>
                    <td valign="top">
                        DISCOUNTS
                    </td>
                    <td>
                        &nbsp;
                    </td>
                    <td valign="top">
                        SUBTOTAL
                    </td>
                    <td>
                        &nbsp;
                    </td>
                    <td>
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td>
                        <%# Container.ItemIndex + 1 %>
                    </td>
                    <td style="text-align: center">
                        <asp:Image ID="imgFabric" runat="server" Width="55px" Height="55px" />
                    </td>
                    <td>
                        <br />
                        Quantity<br />
                        <asp:DropDownList ID="ddlQuantity" runat="server" AutoPostBack="true">
                            <asp:ListItem Value="1">1</asp:ListItem>
                            <asp:ListItem Value="2">2</asp:ListItem>
                            <asp:ListItem Value="3">3</asp:ListItem>
                            <asp:ListItem Value="4">4</asp:ListItem>
                            <asp:ListItem Value="5">5</asp:ListItem>
                            <asp:ListItem Value="6">6</asp:ListItem>
                            <asp:ListItem Value="7">7</asp:ListItem>
                            <asp:ListItem Value="8">8</asp:ListItem>
                            <asp:ListItem Value="9">9</asp:ListItem>
                            <asp:ListItem Value="10">10</asp:ListItem>
                        </asp:DropDownList>
                        <br />
                    </td>
                    <td>
                        &nbsp;
                    </td>
                    <td valign="top">
                        Supplement for monogram
                    </td>
                    <td valign="top">
                        0,00
                    </td>
                    <td valign="top">
                        Discount for short sleeves
                    </td>
                    <td valign="top">
                        0,00
                    </td>
                    <td valign="top">
                        Basic price<br />
                        Extras<br />
                        Discounts
                    </td>
                    <td>
                        &nbsp;
                    </td>
                    <td valign="top">
                        0,00<br />
                        0,00<br />
                        0,00
                    </td>
                </tr>
                <tr>
                    <td>
                        &nbsp;
                    </td>
                    <td style="text-align: center">
                        &nbsp;
                    </td>
                    <td>
                        <asp:LinkButton ID="lnkCancel" runat="server" Text="Cancel" CommandName="Cancel"></asp:LinkButton>
                    </td>
                    <td>
                        &nbsp;
                    </td>
                    <td>
                        <b>Total of extras</b>
                    </td>
                    <td>
                        <b>0,00</b>
                    </td>
                    <td>
                        <b>Total discount </b>
                    </td>
                    <td>
                        <b>0,00</b>
                    </td>
                    <td>
                        <b>Total per shirt </b>
                    </td>
                    <td>
                        &nbsp;
                    </td>
                    <td>
                        <b>0,00</b>
                    </td>
                </tr>
            </ItemTemplate>
            <FooterTemplate>
                </table></FooterTemplate>
        </asp:Repeater>

问题是,如何从转发器获取Dropdownlist值? dropdownlist值在方法中执行(比方说:“private void InsertDatabase()”)

此代码用于将Dropdownlist值插入数据库,并在单击Button时触发(我将“”private void InsertDatabase()“放在按钮的”Click“事件上。

提前致谢。

1 个答案:

答案 0 :(得分:1)

您可以使用下面提到的代码获取下拉列表值

foreach (RepeaterItem rptItem in RepeaterName.Rows)
{
         DropDownList ddlQuantity = (DropDownList)gvr.FindControl("ddlQuantity");
}

通过这种方式,您可以找到下拉列表并获得它的价值。