Problem with setting a gridview's SelectedIndex property in code

Discussion in 'ASP .Net' started by Froefel, Jul 25, 2007.

  1. Froefel

    Froefel Guest

    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
     
    Froefel, Jul 25, 2007
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jay Pondy
    Replies:
    1
    Views:
    6,903
    Christopher Reed
    Mar 3, 2006
  2. RSH
    Replies:
    3
    Views:
    430
  3. Froefel
    Replies:
    0
    Views:
    418
    Froefel
    Jul 24, 2007
  4. Froefel
    Replies:
    0
    Views:
    517
    Froefel
    Jul 25, 2007
  5. =?Utf-8?B?RnJvZWZlbA==?=
    Replies:
    0
    Views:
    441
    =?Utf-8?B?RnJvZWZlbA==?=
    Jul 25, 2007
Loading...

Share This Page