<asp:Repeater ID="rptHotels" runat="server" OnItemDataBound="rptHotels_ItemDataBound">
<ItemTemplate>
<div class="hotel-box">
<div class="hotel-img">
<asp:HiddenField ID="hdnHotelCode" runat="server" Value='<%#Eval("HotelCode")%>' />
<a class="preview" href='<%#Eval("ImageURL_Text") %>' title='<%#Eval("HotelName")%>' target="_blank">
<img src='<%#Eval("ImageURL_Text") %>' alt='<%#Eval("HotelName")%>' height="75px"
width="100px" />
</a>
</div>
<div class="hotel_heeading_content">
<div class="hotel_heading">
<h2>
<asp:LinkButton ID="lnkHotelDetail" runat="server" OnClick="lnkHotelDetail_Click">
<%#Eval("HotelName")%>
(
<%#Eval("boardType")%>)
</asp:LinkButton>
</h2>
</div>
<div class="stars">
<span class="stars">
<%#Eval("StarRating")%></span>
</div>
<div class="hotel_text">
<%#Eval("HotelAddress")%>,
<%#Eval("Destination")%>
,<%#Eval("Country")%>
<img src="images/ico_point2.png" alt="" id="mapicon" class="mapicon" />
<input type="hidden" id="hdnLatitude" class="hdnLatitude" runat="server" value='<%#Eval("Latitude")%>' />
<input type="hidden" id="hdnLongitude" class="hdnLongitude" runat="server" value='<%#Eval("Longitude")%>' />
<input type="hidden" id="hdnInfoWindow" class="hdnInfoWindow" runat="server" />
</div>
</div>
<p>
<asp:Literal ID="ltDes" runat="server"></asp:Literal>
</p>
<p>
<a href="#">more info</a>
</p>
<div class="btn">
<asp:LinkButton ID="lnkPrice" runat="server" Text=' <%#Eval("totalPrice")%>' OnClick="lnkHotelDetail_Click" ></asp:LinkButton>
</div>
<div class="roominfo">
<asp:Repeater ID="rptRooms" runat="server">
<HeaderTemplate>
<div class="rooms">
<div class="roominfoheader">
<div class="roomheaderlbl">
Room Name</div>
<div class="roomheaderlbl">
Total Room Rate</div>
<div class="roomheaderlbl">
Book Now</div>
</div>
</div>
</HeaderTemplate>
<ItemTemplate>
<div class="rooms">
<div class="roominforow">
<div class="roominforowlbl">
<asp:Label ID="lblRoomName" runat="server" Text='<%#Eval("roomCategory") %>'></asp:Label></div>
<div class="roominforowlbl">
$
<asp:Label ID="Label1" runat="server" Text='<%#Eval("totalRoomRate") %>'></asp:Label></div>
<div class="roominforowlbl">
<asp:LinkButton ID="lnkBookNow" runat="server" Text="Book Now" OnClick="lnkBookNow_Click"></asp:LinkButton></div>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
我有上面嵌套中继器的 HTML。我可以通过以下方法找到包含酒店代码的隐藏字段值
protected void lnkHotelDetail_Click(object sender, EventArgs e)
{
LinkButton btn = (LinkButton)sender;
var item = (RepeaterItem)btn.NamingContainer;
HiddenField hdnHotelCode = (HiddenField)item.FindControl("hdnHotelCode");
}
但问题是现在我必须在单击嵌套中继器项目模板链接按钮时找到隐藏字段值。您可以检查 lnkBookNow 是rptRooms
中继器内部的链接按钮。
protected void lnkBookNow_Click(object sender, EventArgs e)
{
LinkButton btn = (LinkButton)sender;
var item = (RepeaterItem)btn.NamingContainer;
HiddenField hdnHotelCode = (HiddenField)item.FindControl("hdnHotelCode");
}
我尝试了类似的方法,但没有找到隐藏字段。