how to set delete and edit button in gridview

Posted by Klbaiju under ASP.NET on 8/5/2012 | Points: 10 | Views : 11020 | Status : [Member] | Replies : 3
hi

this is my gridview
<asp:GridView ID="GridView1" AutoGenerateColumns="False" runat="server"
AutoGenerateDeleteButton="True"
onrowcancelingedit="GridView1_RowCancelingEdit"
onrowdeleting="GridView1_RowDeleting" onrowediting="GridView1_RowEditing"
onrowupdating="GridView1_RowUpdating"
onrowdatabound="GridView1_RowDataBound" AutoGenerateEditButton="True" >
<Columns>
<asp:BoundField DataField="id" ReadOnly="true" HeaderText="Id" />
<asp:BoundField DataField="name" HeaderText="Name" />
<asp:BoundField DataField="department" HeaderText="Department" />
<asp:BoundField DataField="age" HeaderText="Age" />
<asp:BoundField DataField="salary" HeaderText="Salary" />



</Columns>
</asp:GridView>

--------------------------------------------------
problem is edit button is displaying first .i need to display delete button first. how it is possible

regards

baiju




Responses

Posted by: Rajkatie on: 8/5/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
For that you have to use <asp:TemplateField> field in <<Columns> section.
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server"
CommandArgument='<%# Eval("biInvitationId") %>'
CommandName="dele">Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="id" ReadOnly="true" HeaderText="Id" />
<asp:BoundField DataField="name" HeaderText="Name" />
...
</Columns>

Rajesh Patel
.Net Trainer(M.C.S.A | MCT)
Brainbench (Asp.Net 4.5 and C# 5.0)

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Srilu.Nayini577 on: 8/6/2012 [Member] Starter | Points: 25

Up
0
Down
Write this code :

<Columns>

<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server"
CommandArgument='<%# Eval("Id") %>'
CommandName="dele">Delete</asp:LinkButton>

<asp:LinkButton ID="LinkButton2" runat="server"
CommandArgument='<%# Eval("Id") %>'
CommandName="Edit">Edit</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Id" ReadOnly="true" HeaderText="Id" />
<asp:BoundField DataField="Name" HeaderText="Name" />

</Columns>

SRILATHA

SRILATHA
.Net Developer

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 8/6/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
hi
read this article.
you will find your solution.
http://www.dotnetfunda.com/articles/article1616-how-to-generate-edit-delete-update-and-select-buttons-automatically.aspx

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response