GridView

Last post 05-14-2008 5:57 PM by Andrew_C1. 3 replies.

Sort Posts:

  • GridView

    05-14-2008, 5:24 PM

    Hi ....

    Why I can't  specifies the row in the ( RowEditing ) Event or ( RowDeleting) event ?.. Like in the ( SelectedIndexChanged ) event ?

    In the SelectIndexChanged event I can get the data in the row that I select

    but in the other event like RowEditing or RowDeleting I get the data in the first row only .........Why ?

    I hope that you understand me ......... thanx

  • Re: GridView

    05-14-2008, 5:50 PM
    Answer
    • Loading...
    • johram
    • Joined on 06-13-2006, 6:36 AM
    • Sweden
    • Posts 2,777
    • Moderator

    For RowEditing event, you should look in the GridViewEditEventArgs parameter, it contains a property called NewEditIndex which reflects the row id of the row being edited. You can use the property like this:

    void CustomersGridView_RowEditing(Object sender, GridViewEditEventArgs e)
    {
    String country = CustomersGridView.Rows[e.NewEditIndex].Cells[6].Text;
    if (country == "USA")
    {
    // Cancel the edit operation.
    e.Cancel = true;
    Message.Text = "You cannot edit this record.";
    }
    else
    {
    Message.Text = "";
    }
    }

    [Full code at MSDN: GridView.RowEditing Event]

    Similarly, there's a GridViewDeleteEventArgs available in the RowDeleting event method that contains a RowIndex property.

    If this post was useful to you, please mark it as answer. Thank you!
  • Re: GridView

    05-14-2008, 5:51 PM
    Answer
    • Loading...
    • vinz
    • Joined on 10-05-2007, 11:47 AM
    • Cebu Philippines
    • Posts 6,026

    Have you tried

    string str =  GridView1.SelectedRow.Cells[1].Text;


    Cheers,
    Vincent Maverick Durano


  • Re: GridView

    05-14-2008, 5:57 PM
    Answer
    • Loading...
    • Andrew_C1
    • Joined on 09-18-2007, 3:34 PM
    • Noida
    • Posts 100

    Hello Fawaz,

    In RowEditing event you may use following code to get the cell content:

    this.GridView1.Rows[GridView1.EditIndex].Cells

    Similarly other events can be used

    Regards,

     

    If this post was useful to you, please mark it as answer. Thank you!

    Andrew Miller
    www.ComponentOne.com
Page 1 of 1 (4 items)