Problem with setting a gridview's SelectedIndex property in code

Discussion in 'ASP .Net' started by =?Utf-8?B?RnJvZWZlbA==?=, Jul 25, 2007.

  1. 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
     
    =?Utf-8?B?RnJvZWZlbA==?=, Jul 25, 2007
    #1
    1. Advertisements

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. David Austin via .NET 247
    Replies:
    2
    Views:
    692
    =?Utf-8?B?VHJldm9yIEJlbmVkaWN0IFI=?=
    Jun 7, 2004
  2. Jay Pondy
    Replies:
    1
    Views:
    7,072
    Christopher Reed
    Mar 3, 2006
  3. RSH
    Replies:
    3
    Views:
    539
  4. Froefel
    Replies:
    0
    Views:
    503
    Froefel
    Jul 24, 2007
  5. Froefel
    Replies:
    0
    Views:
    592
    Froefel
    Jul 25, 2007
  6. Froefel
    Replies:
    0
    Views:
    454
    Froefel
    Jul 25, 2007
  7. kevin  cline
    Replies:
    2
    Views:
    2,603
    Gilbert Rebhan
    Jul 26, 2008
  8. Harry Keck
    Replies:
    0
    Views:
    338
    Harry Keck
    Jan 27, 2005
Loading...