Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / December 2007

Tip: Looking for answers? Try searching our database.

Setting SelectParameter value for ObjectDataSource

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
MAQ - 01 Dec 2007 15:36 GMT
Hi,

I have 2 ObjectDataSource on my page "OderDetailDataSource" and
"CustomerDataSource".

The first datasource returns only one record, out of which there one column
called "CustomerID". The value on this column should be passed as
SelectParamter "CustomerID" for CustomerDataSource.

Could anybody help me figuring out how to do this? It might be something
very simple, but i'm still quite new to .NET.

Thanks in advance

/MAQ
Duy Lam - 01 Dec 2007 16:05 GMT
> Hi,
>
[quoted text clipped - 11 lines]
>
> /MAQ

I don't know where could you need get value of "customerId" ? So i
assume that you store customerId in a HiddenField, so here your code :

[Code design]
<asp:ObjectDataSource ID="CustomerDataSource" TypeName="CustomerSource"
SelectMethod="GetCustomer" runat="server">
       <SelectParameters>
        <asp:ControlParameter ControlID="hiddenFieldCustomerId"
Name="customerId" PropertyName="Value" Type="int32" />
       </SelectParameters></asp:ObjectDataSource>

[App_Code]
public class CustomerDataSource {
    // ...
    public IList<Customer> GetCustomer(int customerId) {
        // your code in here to get one customer with id is "customerId"
        // ...
    }
    // ...
}

Signature

Duy Lam Phuong

MAQ - 01 Dec 2007 16:37 GMT
Hi Duy,

Thanks for your answer. But, how do i store the CustomerID value in the
hidden field at first place? This value is part of the DataTable that is
being returned by "OrderDetailDataSource"

Thanks

MAQ

>> Hi,
>>
[quoted text clipped - 32 lines]
> // ...
> }
Duy Lam - 11 Dec 2007 16:43 GMT
> Hi Duy,
>
[quoted text clipped - 41 lines]
>> // ...
>> }

It's OK. When you use ObjectDataSource, it's certainly you use Repeater,
DataList or GridView, isn't it ?
And if I'm right, you just capture event DataItemBound and assign value
to your hidden field.
For example:

protected void DataList1_ItemDataBound(object sender,
DataListItemEventArgs e)
{
    if( e.Item.ItemType = ListItemType.Item || e.Item.ItemType =
ListItemType.AlternativeItem )
    {
        Customer c = e.Item.DataItem as Customer;
        HiddenField1.Value= c.CustomerId; // Assign ID to hidden field
    }
}

Sorry if I reply to you late :-)

Signature

Duy Lam Phuong


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.