Reputation: 73918
I have an EntityDataSource and I need set WHERE to a Local Variable Type: GUID.
My problem is I am not able to send my local variable Guid to EntityDataSource for a WHERE OPERATION.
I also tried to to use a ControlParameter<asp:ControlParameter Name="UserId" />
and have a Label with Text property on my Guid converted in String. But does not work.
Any idea how to solve teh matter
<asp:EntityDataSource ID="EntityDataSourceListAuthors" runat="server"
AutoGenerateWhereClause="True"
ConnectionString="name=CmsConnectionStringEntityDataModel"
DefaultContainerName="CmsConnectionStringEntityDataModel"
EnableFlattening="False" EntitySetName="CmsAuthors" Where=""
EntityTypeFilter="" Select="">
<WhereParameters>
<asp:Parameter Name="UserId" />
</WhereParameters>
</asp:EntityDataSource>
Upvotes: 3
Views: 5330
Reputation: 73918
Solution yo my problem:
Useful resources:
http://www.leftslipper.com/ShowFaq.aspx?FaqId=11
http://weblogs.asp.net/scottgu/archive/2006/01/23/436276.aspx
How to programmatically set parameters for EntityDataSource and DetailsView?
http://msdn.microsoft.com/en-us/library/cc294876%28v=Expression.40%29.aspx
http://msdn.microsoft.com/en-us/library/cc295043%28v=Expression.40%29.aspx
My code now
<asp:EntityDataSource ID="EntityDataSourceListAuthors" runat="server"
AutoGenerateWhereClause="True"
ConnectionString="name=CmsConnectionStringEntityDataModel"
DefaultContainerName="CmsConnectionStringEntityDataModel"
EnableFlattening="False" EntitySetName="CmsAuthors" Where=""
EntityTypeFilter="" Select="">
<WhereParameters>
<cmsParameter:CustomParameter Name="UserId" />
</WhereParameters>
</asp:EntityDataSource>
New Class Added:
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
namespace WebProject.Core.Utilities
{
public class CustomParameter : Parameter
{
protected override object Evaluate(HttpContext context, Control control)
{
MembershipUser currentUser = Membership.GetUser();
return currentUser.ProviderUserKey;
}
}
}
Upvotes: 5