Monday, March 26, 2012

passing variable to the Parameter value of ObjectDataSource1?

How do I go about passing the value strUserId to the parameter value of ObjectDataSource1?

// get userid for logged in client
if (User.Identity.IsAuthenticated)
{
strUserId = Membership.GetUser().ProviderUserKey.ToString();
}

In the Configure Data Source wizard it is asking for a Parameter Source in the drop down. And the variable strUserId (in the code-behind for the page) is not an option.

How do I make it one?

hi

you need to set the parameter value in Selecting event of the object datasource :

protected void ObjectDataSource1_Selecting(object sender, ObjectDataSourceSelectingEventArgs e) {this.ObjectDataSource1.SelectParameters[0].DefaultValue = Membership.GetUser().ProviderUserKey(); }


Try setting your Parameter in the ObjectDataSource.Selecting event like so:

protected void ObjectDataSource1_Selecting(object sender, ObjectDataSourceSelectingEventArgs e){e.InputParameters["UserID"] = Membership.GetUser().ProviderUserKey;}

Thank you Anas,

I double clicked the ObjectDataSource1 in design view and was able to get it started.

I will review your code.

Thanks again.

Update: I actually got the 2nd answer in this thread to work.

0 comments:

Post a Comment