You must Sign In to post a response.
  • Category: ASP.NET

    get selected row cell value in gridview using c#

    hi to all!.

    am having gridview on my webpage,

    have binded the values with paging,i have three fields,
    e.g;-
    student_id,name,age.
    i made invisible the coloumn student_id in gridview,but binded.

    in selectedIndexChanged event,i want to get the student_id coloumn,because i want edit/update the current row details on to the textboxes in the same form.,
    so if i get the student_id coloumn value of the selected row,it is easy to update/edit the row based on the student_id in database.

    how could i do this.

    Thanks in Advance.
  • #304100
    from where, i have to calll this method,how it will take the cureent selected row coloumn value i.e,
    student_id from the invisible column.,
    i want to show that value in to TextBox.

    thanks

  • #304101
    first set datakeynames="student_id" in the gridview
    this is a property you can set

    in the SelectedIndexChanged event of the gridview write
    int intStudentID = Convert.ToInt16(gridName.SelectedDataKey.Value);

    Thats it

  • #304171
    thanks balaji!.

    your code is working fine,i got soloution.

  • #306201
    To Balaji & Others,]

    hi!,
    first set datakeynames="student_id" in the gridview
    this is a property you can set

    in the SelectedIndexChanged event of the gridview write
    int intStudentID = Convert.ToInt16(gridName.SelectedDataKey.Value);

    ////////////////

    the above code is workng fine,but i want to take the same value on the button click event.,
    thing is i want to delete the row on clicking a button.

    could anyone let me know about this.

    Thanks in Adavnce

  • #338035
    hi for this you do not have to use selected index changed method. do this
    step:1]use button field and and give text and commandName="Select" in gridview.

    step:2]now go on row_command event of grid view and write this code:

    if(e.CommandName=="Select")
    {
    int intStudentId=gridview.datakeys["Student_id"].value.tostring();
    }
    i Hope this will work


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.