0

我正在尝试 ASP 中继器控件。

我正在使用 3labels(在中继器内部)显示我的数据库中的值,

我也可以在按钮的单击事件上获取一个标签的值(这也在中继器内)

但,

我想在单击同一个按钮时获取所有 3 个标签的值

我的 aspx 文件是:

<asp:Repeater ID="rptrHotel" runat="server" 
                                onitemcommand="rptrHotel_ItemCommand">
                                <HeaderTemplate>
                                    <table width="500px"  class="bidTab">
                                        <tr class="bidHeading">
                                            <th>
                                                Hotel Name
                                            </th>
                                            <th>
                                                Room Type
                                            </th>
                                            <th>
                                                Bid
                                            </th>
                                        </tr>
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <tr>
                                        <td>
                                            <asp:Label ID="lblHotelName" runat="server" Text='<%#Eval("hotel_name")%>'></asp:Label>
                                        </td>
                                        <td>
                                            <asp:Label ID="lblRoomType" runat="server" Text='<%#Eval("room_type_name")%>'></asp:Label>
                                        </td>
                                        <td>
                                            <asp:Label ID="lblBaseBidAmt" runat="server" Text='<%#Eval("base_bid_ammount")%>'></asp:Label>
                                        </td>
                                        <td>
                                            <asp:Button ID="btnBidNow" runat="server" Text="Bid Now" CommandName="BidNow" CommandArgument='<%#Eval("hotel_name") %>'/>
                                        </td>
                                    </tr>
                                </ItemTemplate>
                                <FooterTemplate>
                                    </table>
                                </FooterTemplate>
                            </asp:Repeater>

我在 aspx.cs 文件中尝试过的代码是:

protected void rptrHotel_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "BidNow")
        {
            Label hotel_name = e.Item.FindControl("lblHotelName") as Label;
            hotel_name.Text = e.CommandArgument.ToString();

            Label room_type_name = e.Item.FindControl("lblRoomType") as Label;
            room_type_name.Text = e.CommandArgument.ToString();

            Label base_bid_ammount = e.Item.FindControl("lblBaseBidAmt") as Label;
            base_bid_ammount.Text = e.CommandArgument.ToString();

            lblhotelresult.Text = lblhotelresult.Text;
            lblRoomResult.Text = room_type_name.Text;
            lblBaseamtresult.Text = base_bid_ammount.Text;

            //Session["hotel_name"] = hotel_name.Text;
            //Session["room_type_name"] = room_type_name.Text;
            //Session["base_bid_ammount"] = base_bid_ammount.Text;

            //Response.Redirect("BidRoomCustomer.aspx");
        }
    }

请建议可以做什么并帮助我访问所有 3labels。

4

1 回答 1

1

我自己做的。

需要处理多个参数。

将我的 .aspx 文件更改为:

<asp:Repeater ID="rptrHotel" runat="server" OnItemCommand="rptrHotel_ItemCommand">
                                <HeaderTemplate>
                                    <table width="500px" class="bidTab">
                                        <tr class="bidHeading">
                                            <th>
                                                Hotel Name
                                            </th>
                                            <th>
                                                Room Type
                                            </th>
                                            <th>
                                                Bid
                                            </th>
                                        </tr>
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <tr>
                                        <td>
                                            <asp:Label ID="lblHotelName" runat="server" Text='<%#Eval("hotel_name")%>'></asp:Label>
                                        </td>
                                        <td>
                                            <asp:Label ID="lblRoomType" runat="server" Text='<%#Eval("room_type_name")%>'></asp:Label>
                                        </td>
                                        <td>
                                            <asp:Label ID="lblBaseBidAmt" runat="server" Text='<%#Eval("base_bid_ammount")%>'></asp:Label>
                                        </td>
                                        <td>
                                            <asp:Button ID="btnBidNow" runat="server" Text="Bid Now" CommandName="BidNow" CommandArgument='<%#Eval("hotel_name")+","+ Eval("room_type_name")+","+Eval("base_bid_ammount")%>'>
                                            </asp:Button>

                                        </td>
                                    </tr>
                                </ItemTemplate>
                                <FooterTemplate>
                                    </table>
                                </FooterTemplate>
                            </asp:Repeater>

我的 .aspx.cs 文件是:

protected void rptrHotel_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "BidNow" )
        {

            string[] arguments = e.CommandArgument.ToString().Split(new char[] { ',' });
            string hotel_name = arguments[0];
            string hotel_room_type = arguments[1];
            string base_bid_amt=arguments[2];

        }

这很好用:)

于 2013-04-03T13:13:19.717 回答