Click here to Skip to main content
15,884,629 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have using in gridview in asp.net

i will bind to the one category images in gridveiw that images include 5 images

i was click view button that all images was display in datalist.

note:

that view button include in grid

pls help me any body
ASP.NET
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
     AllowPaging="True"  PageSize="30" 
   CssClass="table" GridLines="None" onrowcommand="GridView1_RowCommand">               
    <columns>
    <asp:TemplateField HeaderText="ID" Visible="false">
    <itemtemplate>
    <asp:Label ID="lblid" runat="server" Text='<%#Eval ("product_id") %>' >
      <%-- <asp:Label ID="lbl_productoffer" runat="server" Text='<%#Eval ("product_offer") %>' >--%>
  <%--  <asp:Label ID="lbl_productofferprice" runat="server" Text='<%#Eval ("product_offerprice") %>' >--%>
    <asp:Label ID="lbl_product_image2" runat="server" Text='<%#Eval ("product_image2") %>' >
    <asp:Label ID="lbl_product_image3" runat="server" Text='<%#Eval ("product_image3") %>' >
    <asp:Label ID="lbl_product_image4" runat="server" Text='<%#Eval ("product_image4") %>' >
    <asp:Label ID="lbl_product_image5" runat="server" Text='<%#Eval ("product_image5") %>' >
    </itemtemplate>
    
    <asp:TemplateField HeaderText="S.No">
    <itemtemplate><%#Container.DataItemIndex+1 %> </itemtemplate>
    
    <asp:TemplateField HeaderText="Product Name">
    <itemtemplate>
    <asp:Label ID="lblname" runat="server" Text='<%#Eval ("product_name") %>'>
    </itemtemplate>        
    
    <asp:TemplateField HeaderText="Product Price">
    <itemtemplate>
     Rs   <asp:Label ID="lblprice" runat="server" Text='<%#Eval ("product_price") %>'>
    </itemtemplate>        
    
    <asp:TemplateField HeaderText="Product Image">
    <itemtemplate>
       <asp:Image ID="Image1" runat="server" ImageUrl='<%#  Eval("small_image") %>'    rel="lightbox[Brussels]" Height="100px" Width="100px" />
    <asp:Label ID="lblimage" runat="server" Text='<%#Eval ("product_image") %>' Visible="false">
    <asp:Label ID="lblimage2" runat="server" Text='<%#Eval ("small_image") %>' Visible="false">
    </itemtemplate>        
    
    <asp:TemplateField HeaderText="Subcategory Name">
    <itemtemplate>
    <asp:Label ID="lblsubcategoryname" runat="server" Text='<%#Eval ("subcat_name") %>'>
    </itemtemplate>        
    
    <asp:TemplateField HeaderText="Category Name">
    <itemtemplate>
    <asp:Label ID="lblcategoryname" runat="server" Text='<%#Eval ("category_name") %>'>
    </itemtemplate>        
    
   <%-- <asp:TemplateField HeaderText="Product Description" Visible="false">
    <itemtemplate>
    <asp:Label ID="lbldesc" runat="server" Text='<%#Eval ("product_description") %>'>
    </itemtemplate>        
    --%>
    <asp:TemplateField HeaderText="Veiw"  >
     <itemtemplate>
    <asp:Button ID="Veiw" runat="server"   class="btn  btn-primary "
        rel="lightbox[Brussels]"              OnClientClick="return confirm('Are you sure want to Edit?');" 
             Text="Veiw" CommandName="view"/>
   </itemtemplate>
   
        </columns>
Posted
v3
Comments
Not clear. Please explain more with proper code snippets for reference.

1 solution

Inside the GridView1_RowCommand Event, see if the CommandName is "view" or not.

If it is true, then Find the Images and make them visible.
C#
void GridView1_RowCommand(Object sender, GridViewCommandEventArgs e)
{
    // If multiple buttons are used in a GridView control, use the
    // CommandName property to determine which button was clicked.
    if(e.CommandName=="view")
    {
        // Convert the row index stored in the CommandArgument
        // property to an Integer.
        int index = Convert.ToInt32(e.CommandArgument);
        
        // Retrieve the row that contains the button clicked 
        // by the user from the Rows collection.
        GridViewRow row = GridView1.Rows[index];

        Image image1 = (Image)row.FindControl("Image1");
        image1.Visible = true;
    
        // Do like this for other images too.....
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900