[英]How to Set a Parameter for WhereParameters in EntityDataSource
I have an EntityDataSource and I need set WHERE to a Local Variable Type: GUID. 我有一个EntityDataSource,我需要将WHERE设置为本地变量类型:GUID。
My problem is I am not able to send my local variable Guid to EntityDataSource for a WHERE OPERATION. 我的问题是我无法将我的本地变量Guid发送到EntityDataSource以进行WHERE操作。
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. 我还尝试使用ControlParameter <asp:ControlParameter Name="UserId" />
并在我的Guid上使用Text属性转换为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>
Solution yo my problem: 解决方案你的问题:
Useful resources: 有用的资源:
http://www.leftslipper.com/ShowFaq.aspx?FaqId=11 http://www.leftslipper.com/ShowFaq.aspx?FaqId=11
http://weblogs.asp.net/scottgu/archive/2006/01/23/436276.aspx http://weblogs.asp.net/scottgu/archive/2006/01/23/436276.aspx
How to programmatically set parameters for EntityDataSource and DetailsView? 如何以编程方式设置EntityDataSource和DetailsView的参数?
http://msdn.microsoft.com/en-us/library/cc294876%28v=Expression.40%29.aspx 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://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 http://weblogs.asp.net/scottgu/archive/2006/11/26/tip-trick-how-to-register-user-controls-and-custom-controls-in-web-config.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;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.