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
/MAQMAQ wrote:
> Hi,
> I have 2 ObjectDataSource on my page "OderDetailDataSource" and
> "CustomerDataSource".
> The first datasource returns only one record, out of which there one colum
n
> 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"
// ...
}
// ...
}
Duy Lam Phuong
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" <duylamphuong@.gmail.com> wrote in message
news:Oe7AjPDNIHA.4948@.TK2MSFTNGP02.phx.gbl...
> MAQ wrote:
> 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"
> // ...
> }
> // ...
> }
> --
> Duy Lam Phuong
MAQ wrote:
> 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" <duylamphuong@.gmail.com> wrote in message
> news:Oe7AjPDNIHA.4948@.TK2MSFTNGP02.phx.gbl...
>
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 :-)
Duy Lam Phuong
Monday, March 26, 2012
Setting SelectParameter value for ObjectDataSource
Labels:
asp,
customerdatasource,
datasource,
net,
objectdatasource,
oderdetaildatasource,
page,
record,
returns,
selectparameter,
setting,
value
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment