[ACCEPTED]-How to check if any row is selected from GridView?-rowdatabound

Accepted answer
Score: 12

You can check like...

if (GridView1.SelectedValue != null)
{
     //Row is Selected
}

0

Score: 2

You can try something like this:

If GridView1.SelectedRows.Count > 0 Then
' yourcode here - a row is selected 
Else
' yourcode here - NO row is selected 
End If

0

Score: 1

Better this:

if(GridView1.SelectedIndex < 0)
    { its -1 and no row is selected.}
else
    {its >= 0 and a row is selected}

testing for != null will throw an exception 1 if the selected value is null.

Score: 0

you can also check like this

if(GridView.SelectedIndex >= 0)
   {
      string result = "Selected";
   }
    else
   {
     string result = "Not Selected";
   }

0

More Related questions