我有以下LinqDataSource:
<asp:LinqDataSource ID = "agreementDs"
ContextTypeName = "AdministrationDataContext"
TableName = "Agreements"
runat = "server"
EnableUpdate = "true"
Where = "AgreementId=@AgreementId">
<WhereParameters>
<asp:QueryStringParameter QueryStringField = "AgreementId"
Name = "AgreementId"
Type = "Int32"
DefaultValue = "-1" />
</WhereParameters>
</asp:LinqDataSource> 它应该从协议数据库表中提取一行。如何检测参数AgreementId是否为-1 ?如果是,可以显示一个404页面或将用户重定向到我的站点的首页?我不知道在代码隐藏中插入这个逻辑的正确位置是什么。
更新:不仅仅是当AgreementId参数为-1时,用户才应该被重定向。当数据源不包含任何行时,应该始终发生这种情况。
发布于 2011-11-18 23:20:59
将"OnSelecting“方法名添加到您的LINQ数据源,然后从该方法中检查您需要的任何内容:
<asp:LinqDataSource runat="server" OnSelecting="ldsSelecting" .... />
protected void ldsSelecting(object o, LinqDataSourceSelectEventArgs e)
{
// check for query string or other stuff here, redirect if needed
}https://stackoverflow.com/questions/6408503
复制相似问题