How to set parameter for WhereParameters in EntityDataSource

I have an EntityDataSource and I need to set WHERE for the local variable type: GUID.

My problem is that I cannot send my local Guid variable to EntityDataSource for WHERE OPERATION.

I also tried using ControlParameter <asp:ControlParameter Name="UserId" />and have the Label with Text property in my Guid converted to String. But does not work.

Any idea how to resolve the issue

   <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>
+3
source share
1 answer

The solution to my problem:

  • Adding a CUSTOM PARAMETER of type Object

Useful resources:

http://www.leftslipper.com/ShowFaq.aspx?FaqId=11

http://weblogs.asp.net/scottgu/archive/2006/01/23/436276.aspx

EntityDataSource 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

http://weblogs.asp.net/scottgu/archive/2006/11/26/tip-trick-how-to-register-user-controls-and-custom-controls-in-web-config.aspx

<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>

:

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;
        }
    }
}
+5

Source: https://habr.com/ru/post/1782558/


All Articles