Hi,
How can i Add LinkButton Control to GridView in asp.net.
Thanks, in advance
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Purushottam RathorePosted Aug 26, 2011, 12:55 AM
Write the following code for using Link button in gridview.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="100%" OnRowCommand="GridView1_RowCommand">
<Columns>
<asp:TemplateField HeaderText="Approve" ItemStyle-Width="150px">
<ItemTemplate>
<asp:LinkButton ID="LinkButtonDelete" Text="Delete" CommandName="Delete" runat="server" CommandArgument='<%#DataBinder.Eval(Container.DataItem, "id")%>'/>
ItemTemplate>
asp:TemplateField>
Columns>
asp:GridView>
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Delete")
{
try
{
int id= int.Parse(e.CommandArgument.ToString());
//Delete statement;
//.................
}
catch (Exception ex)
{
ErrorMessage.Text = ex.Message;
}
}
}
Mittal SejpalPosted Aug 26, 2011, 12:26 AM
then in that template
in Item template add link button from tool box...
try it....