Click here to Skip to main content
15,898,374 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

In my Gridview I have added an image button column in templatefield. When I click the image button that record details are displayed on another form. This is working fine. But to select a record, I have to double click image button instead single click.

How can I get details by single click on image button?

Regards,
Sneha
Posted
Comments
hitech_s 15-Sep-11 3:50am    
are u using row command or not?

1 solution

<asp:templatefield xmlns:asp="#unknown">
  <itemtemplate>
    <asp:button id="AddButton" runat="server">
      CommandName="AddToCart" 
      CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"
      Text="Add to Cart" />
  </asp:button></itemtemplate> 
</asp:templatefield>


protected void GridView1_RowCommand(object sender, 
  GridViewCommandEventArgs e)
{
  if (e.CommandName == "AddToCart")
  {
    // Retrieve the row index stored in the 
    // CommandArgument property.
    int index = Convert.ToInt32(e.CommandArgument);
    // Retrieve the row that contains the button 
    // from the Rows collection.
    GridViewRow row = GridView1.Rows[index];
    // Add code here to add the item to the shopping cart.
  }
  }


Hope this will help you...
 
Share this answer
 
Comments
sgjoshi85 15-Sep-11 5:33am    
Not working :(

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