ASP.Net 2.0 : how to set the selectedrow

Discussion in 'ASP .Net' started by Steve B., Dec 8, 2006.

  1. Steve B.

    Steve B. Guest

    Hi,

    I'm building an ASP.Net 2.0 web application that uses the gridview control
    (read only).
    This gridview is filled by a DataTable which is the result of the select
    method of an object binding source (which is a WebService but I don't think
    it matters).

    I also have a querystring parameter "id" and I want to "Select" the row of
    the gridview that match one of its column (which is the primary key of my
    table).

    I did not succeed in setting the .SelectedRow since it's a readonly
    property. I also tryed to set the selectedindex of the gridview, but I don't
    know the index of the row before the databind.

    How can I reach my goal ?

    Thanks in advance,
    Steve
     
    Steve B., Dec 8, 2006
    #1
    1. Advertising

  2. Steve B.

    Jester98x Guest

    Steve,

    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.GridViewRowEventArgs) Handles
    GridView1.RowDataBound
    If e.Row.RowType = DataControlRowType.DataRow Then
    If GridView1.Rows(e.Row.RowIndex - 1).Cells(1).Text = "Search Text"
    Then
    e.Row.RowState = DataControlRowState.Selected
    End If
    End If
    End Sub

    The above code in the code behind page should do the job. Change the
    index of the Cells collection and the value you are check for to decide
    if the row is selected or not.

    The GridView must be configured with Enable Selection otherwise you
    will get an error.

    Regards,
    Steve
     
    Jester98x, Dec 8, 2006
    #2
    1. Advertising

  3. Steve B.

    Steve B. Guest

    I was confused because the XML documentation of the property RowState is
    "Get the ...." and not "Gets or sets the..." like the documentation
    convention is supposed to be...

    Thanks for this lighting !


    "Jester98x" <> a écrit dans le message de news:
    ...
    > Steve,
    >
    > Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As
    > System.Web.UI.WebControls.GridViewRowEventArgs) Handles
    > GridView1.RowDataBound
    > If e.Row.RowType = DataControlRowType.DataRow Then
    > If GridView1.Rows(e.Row.RowIndex - 1).Cells(1).Text = "Search Text"
    > Then
    > e.Row.RowState = DataControlRowState.Selected
    > End If
    > End If
    > End Sub
    >
    > The above code in the code behind page should do the job. Change the
    > index of the Cells collection and the value you are check for to decide
    > if the row is selected or not.
    >
    > The GridView must be configured with Enable Selection otherwise you
    > will get an error.
    >
    > Regards,
    > Steve
    >
     
    Steve B., Dec 8, 2006
    #3
    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. mosscliffe

    GridView.SelectedRow - need Help Please

    mosscliffe, May 25, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    5,716
    =?Utf-8?B?RGF2aWQgSmVzc2Vl?=
    May 25, 2006
  2. HaVoK

    GridView selectedrow values

    HaVoK, Oct 17, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    872
    Mark Rae
    Oct 17, 2006
  3. =?Utf-8?B?QmFkaXM=?=

    GridView SelectedRow

    =?Utf-8?B?QmFkaXM=?=, Dec 5, 2006, in forum: ASP .Net
    Replies:
    7
    Views:
    3,936
    Phil H
    Dec 7, 2006
  4. =?Utf-8?B?QmFkaXM=?=

    Get SelectedRow index

    =?Utf-8?B?QmFkaXM=?=, Dec 7, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    393
    =?Utf-8?B?QmFkaXM=?=
    Dec 7, 2006
  5. Keith G

    GridView SelectedRow and Paging

    Keith G, Oct 16, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    217
    Keith G
    Oct 16, 2006
Loading...

Share This Page