Hi Naomi
I' not sure what you are trying to do there.
if SelectedIndex is -1 then nothing is selected in the grid.
You need to select something or set SelectedIndex to something.
Nick
>>Hi everybody,
>>
>>I have a GridView with a LinkButton. I had a code in RowCommand when the LinkButton was a button field. This code no longer works.
>>
>>I added the following code into the LinkButton_Click event:
>>
>>protected void lnkbtnRemoveRole_Click(object sender, EventArgs e)
>> {
>> int index = this.grdvwUsers.SelectedIndex;
>>
>> string username = ((Label)grdvwUsers.Rows[index].Cells[1].Controls[1]).Text;
>> this.drpSelRole.Visible = false;
>> try
>> {
>> Roles.RemoveUserFromRole(username, drpSelRole.SelectedItem.Value);
>> }
>> catch (Exception ex)
>> {
>> lblMsg.Text = "An exception of type " + ex.GetType().ToString() +
>> " was encountered removing the user from the role.";
>> }
>>
>>
>> // Re-bind users in role to GridView.
>>
>> PopGrid();
>> }
>> }
>>
>>However, it doesn't work either, because my SelectedIndex is -1. I need to be able to find the information from the current row different field in the button's click.
>>
>>Would you please help me to figure this out?
>>
>>Thanks a lot in advance.
>
>The only way I found so far was to save grid's field information in the hidden field on Client click. Is there a better or simpler way to achieve the desired functionality?