this my code in aspx..

<asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound" OnRowEditing="GridView1_RowEditing" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnRowCommand="GridView1_RowCommand" >
        <asp:TemplateField ShowHeader="False">
               <asp:CheckBox ID="allgc" runat="server" />
        <asp:TemplateField HeaderText="Action" ShowHeader="False">
               <asp:LinkButton ID="gdviewlnk" runat="server" >View</asp:LinkButton>   / 
               <asp:LinkButton ID="LinkButton1" runat="server">Edit</asp:LinkButton>


when i going to click the view linkbutton get the id ..

so which function and where i can use the aspx.cs file

plz send any code....

commented: Learn how to use [code] tags. -1
commented: [code] tags please. -1

I hope this link will help you, but it is not about a linkbutton but you can use hyperlink insteed of linkbutton and that link helps you.


you can do something like this

GridViewRow selectedRow = (GridViewRow)((LinkButton)e.CommandSource).NamingContainer;
//to get the value in the first column
string st = selectedRow.Cells[0].Text;

thank u i was solved the issues...

i need to pass the selected row in the grid view to the next page in textboxes and display the values in that textboxes. could you please help me

You Can do a very simple thing, try this
you can put the id in the commandArgument of the linkbutton and then get the ID from the code behind, something like this:

<asp:LinkButton ID="gdviewlnk" runat="server" CommandArgument='<%#Eval("ID") %>' >View </asp:LinkButton>

Then in the Code behind to get the ID do this :

protected void gdviewlnk_Click(object sender, EventArgs e)
 int ID = Convert.ToInt32(((LinkButton)sender).CommandArgument);

need it possible if i use datakey as a trigger to open a pop up window??and get the value of the selected row in gridview?? what will i use row databound or rowcommand??please.. help me..if u have a code in my problem..

where u show ur values...???

i need to show the values to another gridview and textboxes.
when u click a column in gridview it will pop up another window and inside of it is another gridview and textboxes.. and there's a submit button that when you click the button it will save the value in textboxes and gridview at the same time in sql database..

I am no expert but this worked for me, I hope it helps:
In your asp GridView keep OnRowCommand="GridView1_RowCommand", in the codebehind

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
                      GridViewRow row = (GridViewRow)((LinkButton)e.CommandSource).NamingContainer;
                      string FirstName = row.Cells[0].Text;
                      string LastName = row.Cells[1].Text;
                      //etc..., the number in the [] refers to the cell placement in the gridview, 0 is the 1st
                      Page.Session["FirstName"] = FirstName;
                      Page.Session["LastName"] = LastName;

The 2nd page:

protected void Page_Load(object sender, EventArgs e)
        TextBox1.Text = Session["FirstName"].ToString();
        TextBox2.Text = Session["LastName"].ToString();