Click here to Skip to main content
16,004,860 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there,

Can you tel me, how to create a GridView edit button for each row manually and write code for it (in its click event)?

Thank you in advance...
Posted
Updated 12-Jun-10 5:54am
v2

Add this code in you gridview columns.
Add template field in your gridview.

XML
<asp:TemplateField >
                                       <ItemTemplate>
                                           <asp:Button id="btnEdit" runat="server" Text="Edit" CommandName="Edit" CssClass="btn" CausesValidation="false"/>
                                       </ItemTemplate>
                                   </asp:TemplateField>
                                   <asp:TemplateField >



----------------------------
In Codebehind

C#
protected void gv_RowEditing(object sender, GridViewEditEventArgs e)
  {
      Int32 iID = Convert.ToInt32((gv.DataKeys[e.NewEditIndex].Value));
      EditMethod(iID)         // now you can send ID and retrieve data.
  }


Please write this code in code behind.

You can get Id of editing element. This can fetch data of specific row.
This is final solution.
 
Share this answer
 
v3
I'm not quite sure what it is you're after.
In the Properties of the DataGridView you can set it's EditMode.
 
Share this answer
 
v2
Comments
aswathy.s.88 10-Jun-10 23:38pm    
Ya It's possible to add buttons in each row...but I don't know how to add coding for the click event...

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