ASPX
<asp:SqlDataSource ID="SqlDataSource5" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [Themes] WHERE ([Theme] = @Theme) ORDER BY [Price]">
<SelectParameters>
<asp:Parameter DefaultValue="Dubai-and-Beyond" Name="Theme" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:ListView ID="theme5" runat="server" DataSourceID="SqlDataSource5">
<LayoutTemplate>
<div id="itemPlaceHolderContainer" runat="server">
<span id="itemPlaceHolder" runat="server"></span>
</div>
</LayoutTemplate>
<ItemTemplate>
<div>
<asp:Image ID="Destinationimage" runat="server"
ImageUrl='<%# Eval("ID", "~/CMS/ThemesHandler.ashx?ID={0}")+"&img=1"%>'
AlternateText="Destination_Image" Height="140px" Width="179px" />
<asp:Label ID="lblcountry" runat="server" Text='<%#Eval("Country") %>' />
</div>
<div class="hotel_name">
<asp:Label ID="lblcountry" runat="server" Text='<%#Eval("Country") %>' /></div>
<asp:ImageButton ID="imgbtn5" runat="server" ImageUrl="images/book_nw.png"
OnClick="imgbtn5_Click" AlternateText="get_quote"/></div>
</ItemTemplate>
</asp:ListView>
背后的代码
protected void imgbtn5_Click(object sender, EventArgs e)
{
ListViewItem item = theme5.Items[0];
Label country = (Label)item.FindControl("lblcountry");
string con = country.Text.ToString();
Session["country"] = con.ToString();
Response.Redirect("Get_Quote.aspx");
}
在这里,Theme5 是 Listview。每个列表视图项中都有一个标签和 imgbutton。我想在 imgbutton 点击事件上传输标签值。这里的问题是我无法识别列表视图项的行索引。