Reputation: 355
I have a gridview with edit button which generated by "AutoGenerateEditButton". Now I need to add my button with new event near this edit button.
How to put button there:
Upvotes: 0
Views: 1459
Reputation: 135
Use gridview's Template field to add your editbutton.
<asp:GridView ID="gvproddet" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="imgmodify" runat="server" ImageUrl="~/database/images/edit.jpg"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Remove">
<ItemTemplate>
<asp:ImageButton ID="imgbtnDelete" runat="server" ImageUrl="~/database/images/DeleteRed.jpg" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
NOTE:Use AutoGenerateColumns property as false.If U want both the buttons in same column put in same <td>
.
Upvotes: 0
Reputation: 17019
You can create a TemplateField
and place your button inside the ItemTemplate
.If you want the Edit link button and another control to be in the same column simply place them in one <td>
element. Just note that when using this approach you can no longer have AutoGenerateEditButton="true"
you will need to implement this manually. If you want to keep the existing functionality (AutoGenerateEditButton="true"
) then consider implementing this using javascript
ASPX:
<asp:GridView ID="GridView1" AutoGenerateColumns="false" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<table>
<tr>
<td>
<asp:LinkButton ID="lnkEdit" runat="server" Text="Edit" /> <br />
<asp:Button ID="btnGreet" runat="server" OnCommand="Greet" CommandArgument='<%# Eval("Name") %>'
Text="Greet" />
</td>
<td>
<asp:Label ID="lblName" runat="server" Text='<%# Eval("Name") %>' />
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Code behind:
protected void Greet(object sender, CommandEventArgs e)
{
Response.Write("Hello " + e.CommandArgument);
}
Upvotes: 3
Reputation: 15478
You can create your own template. the easiest way is to go to the gridview editor and find the auto button section and right click and say "convert to template". you'll end see all your buttons individually and you can add what ever you want there.
Upvotes: 0