473,414 Members | 1,911 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

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

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
Mar 1 '06 #1
0 1798

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Eiriken | last post by:
Hello everyone, I am using ASP.NET 2 and trying to bind a objectdatasource to a gridview. By doing this the most common way by adding an objectdatasource to the page and by using the wizard to...
1
by: A_StClaire_ | last post by:
hi all, I am using a GridView bound to an ObjectDataSource. edit and delete functionality has been enabled. my ObjectDataSource is tied to a TableAdapter that accesses three stored procedures...
6
by: Dabbler | last post by:
I have a dropdownlist in a GridView ItemTemplate. I need to bind the ddl to an SqlDataSource, then have a value from a boundfield in the row be passed as the keyfield for select where clause. Im...
1
by: syl | last post by:
Hello I am trying to create a "easy to use" gridview with filters (dropdownlist in headers), sorting...and much more.... In order to do that, i prefer to use a objectdatasource (ODS) beacause...
2
by: Olivier Matrot | last post by:
Hello, I'm using a gridview with objectdatasource and custom objects collections SELECT/INSERT/UPDATE/DELETE methods are using custom objects as parameters. This is working fine. But I have a...
2
by: Greg | last post by:
Hello, I am trying to bind a GridView to a custom object I have created. First, here is what I'm trying to do: I have a wizard for adding/editing Users. When the wizard begins, a User...
5
by: Randy Smith | last post by:
Hi ALL, I wonder if anyone has been using n-tier to bind to a GridView control by using the ObjectDataSource. This is our first OOP web application, and we have no tables. Right now we are...
2
by: =?Utf-8?B?SmF5IFBvbmR5?= | last post by:
Based on wether a row is selected in a GridView I need to HIDE the last two columns of a gridview. I do NOT need to make the cells invisible I want to hide the entire column. When I set the...
3
by: Peter | last post by:
I have a GridView which is populated by List<ofObjects> Does anyone have example of how to sort the columns of this GridView? I have found examples without DataSourceControl but these use...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.