Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从ListView控件获取索引项_C#_Asp.net_Listview - Fatal编程技术网

C# 从ListView控件获取索引项

C# 从ListView控件获取索引项,c#,asp.net,listview,C#,Asp.net,Listview,ASPX 这里,主题5是Listview。每个listview项中都有一个标签和imgbutton。 我想传递imgbutton click事件上的标签值。 这里的问题是我无法识别listview项的行索引。您可以使用listview中的和ImageButton。您可以从活动中访问相应的项目 您可以在ListView中使用和的ImageButton。您可以从活动中访问相应的项目 <asp:SqlDataSource ID="SqlDataSource5" runat="server"

ASPX

这里,主题5是Listview。每个listview项中都有一个标签和imgbutton。 我想传递imgbutton click事件上的标签值。 这里的问题是我无法识别listview项的行索引。

您可以使用listview中的和ImageButton。您可以从活动中访问相应的项目

您可以在ListView中使用和的ImageButton。您可以从活动中访问相应的项目

<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");
}
<asp:ImageButton ID="imgbtn5" runat="server" ImageUrl="images/book_nw.png"  
        OnClick="imgbtn5_Click" AlternateText="get_quote"
        CommandName="YOUR_COMMAND_NAME" 
        CommandArgument='<%#Eval("ANY_COLUMN_OF_SOURCE") %>' />
protected void theme5_OnItemCommand(object sender, ListViewCommandEventArgs e)
{
  if (String.Equals(e.CommandName, "YOUR_COMMAND_NAME"))
  {
   string arg = e.CommandArgument; // do whatever you want
   ListViewDataItem dataItem = (ListViewDataItem)e.Item;

 }
}