How to Add LinkButton ControlJSjon smit15yAsked Aug 26, 2011, 12:08 AM3k.NETHi,How can i Add LinkButton Control to GridView in asp.net.Thanks, in advance
Purushottam Rathore15y agoPosted Aug 26, 2011, 12:55 AMDear JonWrite 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; } }}
MSMittal Sejpal15y agoPosted Aug 26, 2011, 12:26 AMMake the column in which you want to add grid control as template field.then in that templatein Item template add link button from tool box...try it....
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....