I have a Grid View control that displays data based on what is returned by the LinqDataSource. The LinqDataSource selects data depending on the date chosen in a date control (used in the where clause), but I a开发者_如何学JAVAlso need the where clause to be based on the current userID which is a GUID.
How can I get the LinqDataSource to obtain the Current User ID and use it in the where clause? My code currently looks like something like this (in the .aspx page)
Where=UserID == GUID?(@UserID)
<asp:Parameter DbType="Guid" Name="UserId" />
I hope that's enough information - please let me know if you need more! :)
Thanks :)
If anyone is interested, I stopped using the smart tag and ended up writing the query in the _Selecting event of the LinqDataSource. That seemed to fix it.
What I did when I had the same problem:
<asp:LinqDataSource ... Where="UserID == Convert.ToInt32(@UserID)">
<WhereParameters>
<asp:ControlParameter Name="UserID" ControlID="hdnUserID"
Type="Int32" PropertyName="Value" />
</WhereParameters>
</asp:LinqDataSource>
<asp:HiddenField runat="server" ID="hdnUserID" Visible="false" />
Then I set the Value
attribute of hdnUserID
from code-behind. It's a hack, but works.
精彩评论