views:

10

answers:

3

I am trying to get an asp:SessionParameter of a SelectParameters, to use a property of an object in session instead of having a string in the session like Session["CustomerID"]

Something like Session["Customer"] where the property is ((Customer) Session["Customer"]).CustomerID)

I don’t know the syntax to do that, if you can help, I’d really appreciate it

Thank you

My code:

<asp:sqldatasource id="SqlDataSource1" runat="server" connectionstring="<%$ ConnectionStrings:DBConnectionString %>" xmlns:asp="#unknown"> SelectCommand="SELECT * FROM getStoreCustomers (@customerID,@week,@day)"
ProviderName="System.Data.SqlClient">
<selectparameters>
<asp:sessionparameter name="customerID" sessionfield="Customer" /> ?????? (what is the syntax to pass the property here?)
<asp:controlparameter controlid="ddWeek" defaultvalue="-1" name="week" propertyname="SelectedValue" /> <asp:controlparameter controlid="ddDay" defaultvalue="-1" name="day" propertyname="SelectedValue" /> </selectparameters>

The class I use is like any other class (but serializable)

[Serializable]
public class Customer
{
public int CustomerID
{
get;
set;
}
} 
A: 

Hey,

I understand what you are saying, but I don't think the parameter is intelligent enough to get a property of the object stored in session. I think it has to be a primitive type, or else use an and explicitly set the DefaultValue property via code:

ds.SelectParameters["ParamName"].DefaultValue = ((Customer)Session["Customer"]).CustomerID;
Brian
A: 

You'll need to handle the OnSelecting event of your sqldatasource and add the parameter there.

matt-dot-net
A: 

Found how to, from peter.

"Use a regular parameter instead, and set the value in the Selectingevent of the SqlDataSource

in the event handler: protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e) { if (Session["Customer"] != null) { Customer c = (Customer)Session["Customer"]; e.Command.Parameters[0].Value = c.CustomerID.ToString();
} }"

Tucho