How do I pass GridView select properties to ObjectDataSource without using get params

Discussion in 'ASP .Net' started by David Hubbard, Mar 1, 2006.

  1. I am using a GridView to display a set of objects that have a parent-child
    relationship. Each object, MyBO, has
    an ID property that is used to get the children of that object.

    class MyBO
    {

    int _id;
    String _name;


    public int ID
    {
    get { return _id; }
    set { _id = value; }
    }

    public String Name
    {
    get { return _name; }
    set { _name = value; }
    }

    public MyBO ()
    {
    _id = -1;
    _name = "";
    }
    }


    A service is attached to an ObjectDataSource to get the children of the
    object:

    class MyBOService
    {
    static int _counter = 0;

    public MyBOService ()
    {
    }

    public MyBO [] getMyBOs ( int id )
    {
    MyBO [] children = new MyBO[5];

    _counter++;

    for ( int i=0; i<5; i++ )
    {
    MyBO myBO = children[ i ] = new MyBO();
    myBO.ID = (_counter * 10 ) + i;
    myBO.Name = "MyBO_" + _counter.ToString() + "_" + id.ToString()
    ;
    }

    return children;
    }
    }

    For testing their is a static counter to make the names unique. I have tried
    two methods of calling the service. The
    first uses a get parameter.

    <asp:ObjectDataSource ID="myBODataSource"
    Runat="server" TypeName="MyBOService"
    SelectMethod="getMyBOs" >

    <SelectParameters>
    <asp:QueryStringParameter QueryStringField="ID"
    DefaultValue="1" Name="ID" Direction="Input" Type="Int32" />
    </SelectParameters>

    </asp:ObjectDataSource>

    <asp:GridView ID="myBOGridView" Runat="server"
    DataSourceID="myBODataSource"
    AutoGenerateColumns="False"
    OnSelectedIndexChanging = "GridView2_OnSelectedIndexChanging" >

    <Columns>
    <asp:TemplateField HeaderText="ID">
    <ItemTemplate>
    <asp:HyperLink NavigateUrl='<%# Eval( "ID",
    "~/Default.aspx?ID={0}" ) %>' runat="server" Text='<%# Eval( "ID" ) %>' />
    </ItemTemplate>
    </asp:TemplateField>


    <asp:BoundField HeaderText="Name" DataField="Name" />

    </Columns>
    </asp:GridView>

    And this works fine. However I would like to use a post parameter by
    changing the ObjectDataSource select parameters:


    <asp:parameter DefaultValue="1" Name="ID" Direction="Input" Type="Int32" />

    I am not using AutoGenerateSelect, for a cleaner UI, so I cannot hook into
    the OnSelectedIndexChanged of the GridView to change the default value.
    I can use the selecting event of the ObjectDataSource but how can I get the
    ID selected in the GridView?

    Thanks
    David Hubbard, Mar 1, 2006
    #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. =?Utf-8?B?RGFiYmxlcg==?=

    select gridview row without using select button?

    =?Utf-8?B?RGFiYmxlcg==?=, Mar 3, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    101,518
    dch31969
    Feb 27, 2009
  2. Ian
    Replies:
    3
    Views:
    16,464
    zpradipta
    Jul 23, 2007
  3. =?Utf-8?B?SmF5IFBvbmR5?=
    Replies:
    2
    Views:
    783
    Steven Cheng[MSFT]
    Nov 14, 2007
  4. RenatoGuarilha
    Replies:
    0
    Views:
    240
    RenatoGuarilha
    Dec 21, 2005
  5. Barry
    Replies:
    9
    Views:
    443
    Ara.T.Howard
    Sep 15, 2005
Loading...

Share This Page