Set the selectedindex of a datagrid

Discussion in 'ASP .Net' started by Fernando Lopes, Apr 12, 2005.

  1. Hi there.
    I have a customer's address grid in my web application.
    After I searched for a customer I showded all his addresses.
    One of these addresses is the ship address.
    In the search, I gotten the addressId of this ship address.
    The datakey of datagrid is the AddressID.
    I want to keep selected the grid row of this address.

    How can I do that?

    tks.

    Fernando
     
    Fernando Lopes, Apr 12, 2005
    #1
    1. Advertising

  2. myDataGrid.SelectedIndex = myIndex;

    Regards,
    Kostadin Kostov

    "Fernando Lopes" wrote:

    > Hi there.
    > I have a customer's address grid in my web application.
    > After I searched for a customer I showded all his addresses.
    > One of these addresses is the ship address.
    > In the search, I gotten the addressId of this ship address.
    > The datakey of datagrid is the AddressID.
    > I want to keep selected the grid row of this address.
    >
    > How can I do that?
    >
    > tks.
    >
    > Fernando
    >
    >
    >
     
    =?Utf-8?B?S29zdGFkaW4gS29zdG92?=, Apr 12, 2005
    #2
    1. Advertising

  3. Ok Kostadin.
    But, I have the AddressID, not the index of the datagrid.

    index addressid street
    1 1001 aaaaaaaaa
    2 736 bbbbbbbbbb

    Understand?

    tks.

    Fernando

    "Kostadin Kostov" <> wrote in
    message news:...
    > myDataGrid.SelectedIndex = myIndex;
    >
    > Regards,
    > Kostadin Kostov
    >
    > "Fernando Lopes" wrote:
    >
    > > Hi there.
    > > I have a customer's address grid in my web application.
    > > After I searched for a customer I showded all his addresses.
    > > One of these addresses is the ship address.
    > > In the search, I gotten the addressId of this ship address.
    > > The datakey of datagrid is the AddressID.
    > > I want to keep selected the grid row of this address.
    > >
    > > How can I do that?
    > >
    > > tks.
    > >
    > > Fernando
    > >
    > >
    > >
     
    Fernando Lopes, Apr 12, 2005
    #3
  4. Have you tried this?

    index = DataGrid1.SelectedIndex
    key = DataGrid1.DataKeys(index)

    Sandy

    "Fernando Lopes" wrote:

    > Ok Kostadin.
    > But, I have the AddressID, not the index of the datagrid.
    >
    > index addressid street
    > 1 1001 aaaaaaaaa
    > 2 736 bbbbbbbbbb
    >
    > Understand?
    >
    > tks.
    >
    > Fernando
    >
    > "Kostadin Kostov" <> wrote in
    > message news:...
    > > myDataGrid.SelectedIndex = myIndex;
    > >
    > > Regards,
    > > Kostadin Kostov
    > >
    > > "Fernando Lopes" wrote:
    > >
    > > > Hi there.
    > > > I have a customer's address grid in my web application.
    > > > After I searched for a customer I showded all his addresses.
    > > > One of these addresses is the ship address.
    > > > In the search, I gotten the addressId of this ship address.
    > > > The datakey of datagrid is the AddressID.
    > > > I want to keep selected the grid row of this address.
    > > >
    > > > How can I do that?
    > > >
    > > > tks.
    > > >
    > > > Fernando
    > > >
    > > >
    > > >

    >
    >
    >
     
    =?Utf-8?B?U2FuZHk=?=, Apr 12, 2005
    #4
  5. Tks Sandy, the proble is
    I don't have de index. I wrote just to watch the differences betweeen the
    index and de addressID.

    So, I just have the addressID (int) and the grid like:
    addressid street
    1001 aaaaaaaaa
    736 bbbbbbbbbb

    Tks again

    Fernando

    "Sandy" <> wrote in message
    news:...
    > Have you tried this?
    >
    > index = DataGrid1.SelectedIndex
    > key = DataGrid1.DataKeys(index)
    >
    > Sandy
    >
    > "Fernando Lopes" wrote:
    >
    > > Ok Kostadin.
    > > But, I have the AddressID, not the index of the datagrid.
    > >
    > > index addressid street
    > > 1 1001 aaaaaaaaa
    > > 2 736 bbbbbbbbbb
    > >
    > > Understand?
    > >
    > > tks.
    > >
    > > Fernando
    > >
    > > "Kostadin Kostov" <> wrote in
    > > message news:...
    > > > myDataGrid.SelectedIndex = myIndex;
    > > >
    > > > Regards,
    > > > Kostadin Kostov
    > > >
    > > > "Fernando Lopes" wrote:
    > > >
    > > > > Hi there.
    > > > > I have a customer's address grid in my web application.
    > > > > After I searched for a customer I showded all his addresses.
    > > > > One of these addresses is the ship address.
    > > > > In the search, I gotten the addressId of this ship address.
    > > > > The datakey of datagrid is the AddressID.
    > > > > I want to keep selected the grid row of this address.
    > > > >
    > > > > How can I do that?
    > > > >
    > > > > tks.
    > > > >
    > > > > Fernando
    > > > >
    > > > >
    > > > >

    > >
    > >
    > >
     
    Fernando Lopes, Apr 12, 2005
    #5
  6. Fernando Lopes

    Brock Allen Guest

    If the AddressID is in the DataGridKeys collection (meaning it was in there
    because you set "AddressID" as the DataKeyField) then you can find it in
    there. So find the index by searching the DataKeys collection.

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen



    > Tks Sandy, the proble is
    > I don't have de index. I wrote just to watch the differences betweeen
    > the
    > index and de addressID.
    > So, I just have the addressID (int) and the grid like:
    > addressid street
    > 1001 aaaaaaaaa
    > 736 bbbbbbbbbb
    > Tks again
    >
    > Fernando
    >
    > "Sandy" <> wrote in message
    > news:...
    >
    >> Have you tried this?
    >>
    >> index = DataGrid1.SelectedIndex
    >> key = DataGrid1.DataKeys(index)
    >> Sandy
    >>
    >> "Fernando Lopes" wrote:
    >>
    >>> Ok Kostadin.
    >>> But, I have the AddressID, not the index of the datagrid.
    >>> index addressid street
    >>> 1 1001 aaaaaaaaa
    >>> 2 736 bbbbbbbbbb
    >>> Understand?
    >>>
    >>> tks.
    >>>
    >>> Fernando
    >>>
    >>> "Kostadin Kostov" <> wrote
    >>> in message
    >>> news:...
    >>>
    >>>> myDataGrid.SelectedIndex = myIndex;
    >>>>
    >>>> Regards,
    >>>> Kostadin Kostov
    >>>> "Fernando Lopes" wrote:
    >>>>
    >>>>> Hi there.
    >>>>> I have a customer's address grid in my web application.
    >>>>> After I searched for a customer I showded all his addresses.
    >>>>> One of these addresses is the ship address.
    >>>>> In the search, I gotten the addressId of this ship address.
    >>>>> The datakey of datagrid is the AddressID.
    >>>>> I want to keep selected the grid row of this address.
    >>>>> How can I do that?
    >>>>>
    >>>>> tks.
    >>>>>
    >>>>> Fernando
    >>>>>
     
    Brock Allen, Apr 12, 2005
    #6
  7. Ok Brock!
    Tks a lot!
    Now works!


    "Brock Allen" <> wrote in message
    news:...
    > If the AddressID is in the DataGridKeys collection (meaning it was in

    there
    > because you set "AddressID" as the DataKeyField) then you can find it in
    > there. So find the index by searching the DataKeys collection.
    >
    > -Brock
    > DevelopMentor
    > http://staff.develop.com/ballen
    >
    >
    >
    > > Tks Sandy, the proble is
    > > I don't have de index. I wrote just to watch the differences betweeen
    > > the
    > > index and de addressID.
    > > So, I just have the addressID (int) and the grid like:
    > > addressid street
    > > 1001 aaaaaaaaa
    > > 736 bbbbbbbbbb
    > > Tks again
    > >
    > > Fernando
    > >
    > > "Sandy" <> wrote in message
    > > news:...
    > >
    > >> Have you tried this?
    > >>
    > >> index = DataGrid1.SelectedIndex
    > >> key = DataGrid1.DataKeys(index)
    > >> Sandy
    > >>
    > >> "Fernando Lopes" wrote:
    > >>
    > >>> Ok Kostadin.
    > >>> But, I have the AddressID, not the index of the datagrid.
    > >>> index addressid street
    > >>> 1 1001 aaaaaaaaa
    > >>> 2 736 bbbbbbbbbb
    > >>> Understand?
    > >>>
    > >>> tks.
    > >>>
    > >>> Fernando
    > >>>
    > >>> "Kostadin Kostov" <> wrote
    > >>> in message
    > >>> news:...
    > >>>
    > >>>> myDataGrid.SelectedIndex = myIndex;
    > >>>>
    > >>>> Regards,
    > >>>> Kostadin Kostov
    > >>>> "Fernando Lopes" wrote:
    > >>>>
    > >>>>> Hi there.
    > >>>>> I have a customer's address grid in my web application.
    > >>>>> After I searched for a customer I showded all his addresses.
    > >>>>> One of these addresses is the ship address.
    > >>>>> In the search, I gotten the addressId of this ship address.
    > >>>>> The datakey of datagrid is the AddressID.
    > >>>>> I want to keep selected the grid row of this address.
    > >>>>> How can I do that?
    > >>>>>
    > >>>>> tks.
    > >>>>>
    > >>>>> Fernando
    > >>>>>

    >
    >
    >
     
    Fernando Lopes, Apr 12, 2005
    #7
  8. Fernando -

    Try this:

    Dim AddressIDIndex as Integer
    Dim AddressIDKey as Integer
    AddressIDIndex = NameOfYourDataGrid.SelectedIndex
    AddressIDKey = NameOfYourDataGrid.DataKeys(AddressIDIndex)

    Sandy

    "Fernando Lopes" wrote:

    > Tks Sandy, the proble is
    > I don't have de index. I wrote just to watch the differences betweeen the
    > index and de addressID.
    >
    > So, I just have the addressID (int) and the grid like:
    > addressid street
    > 1001 aaaaaaaaa
    > 736 bbbbbbbbbb
    >
    > Tks again
    >
    > Fernando
    >
    > "Sandy" <> wrote in message
    > news:...
    > > Have you tried this?
    > >
    > > index = DataGrid1.SelectedIndex
    > > key = DataGrid1.DataKeys(index)
    > >
    > > Sandy
    > >
    > > "Fernando Lopes" wrote:
    > >
    > > > Ok Kostadin.
    > > > But, I have the AddressID, not the index of the datagrid.
    > > >
    > > > index addressid street
    > > > 1 1001 aaaaaaaaa
    > > > 2 736 bbbbbbbbbb
    > > >
    > > > Understand?
    > > >
    > > > tks.
    > > >
    > > > Fernando
    > > >
    > > > "Kostadin Kostov" <> wrote in
    > > > message news:...
    > > > > myDataGrid.SelectedIndex = myIndex;
    > > > >
    > > > > Regards,
    > > > > Kostadin Kostov
    > > > >
    > > > > "Fernando Lopes" wrote:
    > > > >
    > > > > > Hi there.
    > > > > > I have a customer's address grid in my web application.
    > > > > > After I searched for a customer I showded all his addresses.
    > > > > > One of these addresses is the ship address.
    > > > > > In the search, I gotten the addressId of this ship address.
    > > > > > The datakey of datagrid is the AddressID.
    > > > > > I want to keep selected the grid row of this address.
    > > > > >
    > > > > > How can I do that?
    > > > > >
    > > > > > tks.
    > > > > >
    > > > > > Fernando
    > > > > >
    > > > > >
    > > > > >
    > > >
    > > >
    > > >

    >
    >
    >
     
    =?Utf-8?B?U2FuZHk=?=, Apr 12, 2005
    #8
    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. David D. McCrory

    Set DataList SelectedIndex to data record

    David D. McCrory, Jan 17, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    406
    Alvin Bruney
    Jan 24, 2004
  2. David D. McCrory

    Set DataList SelectedIndex - 2nd Post

    David D. McCrory, Jan 20, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    661
    David D. McCrory
    Jan 20, 2004
  3. Replies:
    1
    Views:
    893
  4. set dropdownlist selectedindex in datagrid

    , Feb 25, 2007, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    955
  5. set dropdownlist selectedindex in datagrid

    , Feb 25, 2007, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    166
Loading...

Share This Page