ASP.NET ObjectDataSource SelectParameters CookieParameter question
Question
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>
Solution
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.
OTHER TIPS
You can create custom control to solve this problem. Kevin Isom's blog has a blog entry.
Custom Parameter for a DataSource
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow