G Gr
G Gr

Reputation: 6080

Error NewSelectedIndex

hey getting a error for NewSelectedIndex any one able to help?:

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        string PhotoPath = "";
        GridViewRow row = GridView1.Rows[e.NewSelectedIndex];

        PhotoPath = row.Cells[5].Text;
    }

'System.EventArgs' does not contain a definition for 'NewSelectedIndex' and no extension method 'NewSelectedIndex' accepting a first argument of type 'System.EventArgs' could be found (are you missing a using directive or an assembly reference?)48 NapierLecturer

Upvotes: 1

Views: 2776

Answers (1)

NoAlias
NoAlias

Reputation: 9193

Since the EventArgs (e) does not contain a method by the name of NewSelectedIndex (nor are there any extension methods for EventArgs named NewSelectedIndex) the error was thrown. What I think you want is to get the new selected index of the GridView control, which can be done by the code shown below.

  protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) 
{ 
    string PhotoPath = ""; 
    GridViewRow row = GridView1.Rows[GridView1.SelectedIndex]; 


PhotoPath = row.Cells[5].Text;


} 

Upvotes: 3

Related Questions