我正在尝试ASP Repeater控件。
我正在使用3个标签(在转发器内部)显示数据库中的值,
我也可以在按钮的点击事件(也在转发器内)获取一个标签的值
但是,
我想点击相同按钮
获取所有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");
}
}
请建议可以做些什么并帮助我访问所有3个标签。
答案 0 :(得分: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];
}
这很好用:)