Problem with setting a gridview's SelectedIndex property in code

F

Froefel

Hi group,

I have a gridview "gdCustomers" with several columns. Column[0] is a
LinkButton with CommandName="Select" and column[1] is a ButtonField
with ButtonType="Image" and CommandName="EditNotes".

When I click a link in column[0], the corresponding gridrow is
selected, as it should.
When I click the image in column[1], I intercept the
gdCustomers_RowCommand() event and execute the following logic:
protected void gdCustomers_RowCommand(object sender,
GridViewCommandEventArgs e)
{
if (e.CommandName == "EditNotes")
{
int index = Convert.ToInt32(e.CommandArgument);
gdCustomers.SelectedIndex = index;

//execute some more stuff here;
}
}

However, even though I explicitly set the row whose image was clicked
to be selected, when the page gets returned to the browser, the row is
not visible selected (it doesn't have the SelectedRow style). Now,
when I click the image a second time, the row gets visibly selected.

Could anyone tell me what I'm doing wrong and why I need to click the
image twice to get the selection to display. Note that the code itself
does get executes the first time I click the image.

Any help would be greatly appreciated.

-- Hans
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,522
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top