views:

658

answers:

2

If my cookie is set like this: Response.Cookies("Employees")("UserID") = 43

How do I get this value from within an ObjectDataSource SelectParameters CookieParameter?

<asp:ObjectDataSource ID="odsProducts" runat="server" TypeName="MyCompany.Products" SelectMethod="GetAll">
     <SelectParameters>
         <asp:CookieParameter CookieName="????" Name="UserID" Type="Int32" />
     </SelectParameters>        
</asp:ObjectDataSource>

I'm assuming that I would need to do something like this?

<asp:ObjectDataSource ID="odsProducts" runat="server" TypeName="MyCompany.Products" SelectMethod="GetAll">
     <SelectParameters>
         <asp:CookieParameter CookieName="Employees.UserID" Name="UserID" Type="Int32" />
     </SelectParameters>        
</asp:ObjectDataSource>
+1  A: 

You can create custom control to solve this problem. Kevin Isom's blog has a blog entry.
Custom Parameter for a DataSource

Ender Özcan
Good suggestion but just too much work that I need
EdenMachine
A: 

Not ideal, but you could set the ObjectDatasource's Parameter DefaultValue in the code-behind odsProducts.SelectParameters["UserId"].DefaultValue = Response.Cookies["Employees"]["UserID"]

there may be an syntax error in there.

JNappi
Yeah, I do this all the time, just though there might be a better way that I didn't know about that used the design-time controls.
EdenMachine