Error when using GridView1_SelectedIndexChanged

Sunkissed

New Member
I have i Gridview with selectedindexchanged event and 3 buttons. when 1 of the buttons is clicked i use theGridView1.SelectedRow.RowIndex to optain the selected row.
v5kEO.jpg
This works fine when the user has clicked on a row. But the problem is when No rows are selected and GridView1.SelectedRow.RowIndex is called in my code.This gives the error: Object reference not set to an instance of an object.Any ideas how i can check whether GridView1.SelectedRow.RowIndex has a value or how i can disable it until a row is selected?Here is the code for add button:\[code\]protected void AddNews_Click(object sender, EventArgs e){ rowIndex = GridView1.SelectedRow.RowIndex; Response.Redirect("~/AddNews.aspx?Parameter=" + rowIndex);}\[/code\]
 
Top