By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,397 Members | 2,552 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,397 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

class MyBOService
static int _counter = 0;

public MyBOService ()

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


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" >

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


<asp:GridView ID="myBOGridView" Runat="server"
OnSelectedIndexChanging = "GridView2_OnSelectedIndexChanging" >

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


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?

Mar 1 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.