Setting SelectParameter value for ObjectDataSource

  • Thread starter Thread starter MAQ
  • Start date Start date
M

MAQ

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
 
MAQ said:
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

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"
// ...
}
// ...
}
 
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

Duy Lam said:
MAQ said:
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

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"
// ...
}
// ...
}
 
MAQ said:
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

Duy Lam said:
MAQ said:
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
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"
// ...
}
// ...
}


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 :-)
 
Back
Top