how can i take link butoon under each record in gridview

Posted by Chanti444 under ASP.NET on 12/16/2011 | Points: 10 | Views : 903 | Status : [Member] | Replies : 3
hi,

i designed gridview that contains user information details.here my requirement is each record first column inserted with link butoon and when i click on link button at the time i need to open separate page with edit that record can u help how can i take link butoon under each one record ........

satya


Responses

Posted by: Hmanjarawala on: 12/16/2011 [Member] Bronze | Points: 25

Up
0
Down
Hi,

You can do this by adding Template column in GridView

<TemplateColumn>

<ItemTemplate>
<asp:LinkButton: id="<urID" runat="server" />
</ItemTemplate>
</TemplateColumn>


Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

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

Posted by: Varung on: 12/16/2011 [Member] Starter | Points: 25

Up
0
Down
in aspx page:

<asp:GridView ID="gvinsert" runat="server" onrowcommand="gvinsert_RowCommand" 

onselectedindexchanged="gvinsert_SelectedIndexChanged">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkedit" Text="edit record" CommandName="recordedit" CommandArgument='<%# Container.DataItemIndex %>' runat="server"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>


in .cs file

 protected void gvinsert_RowCommand(object sender, GridViewCommandEventArgs e)

{
int index =Convert.ToInt32(e.CommandArgument);
if (e.CommandName == "recordedit")
{
//write your code here
}
}


G.Varun

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

Posted by: Sksamantaray on: 12/16/2011 [Member] Silver | Points: 25

Up
0
Down
you can have a linkbutton or hyperlink as a template field.Then in gridview's rowdatabound event , you need to find the control and its corresponding datakey value(unique)/unique field value
DataBinder.Eval(e.Row.DataItem, "fieldname").ToString().Trim();
then you can pass this value to the target page to fetch appropriate record for updation

Thanks,
Sanjay

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

Login to post response