从后面的代码访问ASP.Net变量时,“

时间:2021-12-30 00:41:35

This fix possibly pretty easy. When I copy and paste it works, but my SelectCommand is too long and I need to get it from the code behind.

这个修复可能很容易。当我复制并粘贴它有效时,但我的SelectCommand太长了,我需要从后面的代码中获取它。

Aspx file:

Aspx文件:

<asp:SqlDataSource ID="sds_Dashboard" runat="server" ConnectionString="<%$
                   ConnectionStrings:MyDbConn %>"
                   SelectCommand="<%= SelectCommand.ToString() %>">

Cs file:

Cs文件:

public partial class Dashboard : System.Web.UI.Page
{
    public string SelectCommand = "Select * from .....";
}

Error:

错误:

Incorrect syntax near '<'.

'<'附近的语法不正确。

3 个解决方案

#1


1  

You can set SelectCommand of SqlDataSource in code-behind's Page_Load instead of aspx file:

您可以在代码隐藏的Page_Load而不是aspx文件中设置SqlDataSource的SelectCommand:

sds_Dashboard.SelectCommand = "Select * from .....";

#2


0  

There maybe a constant newline in your code here:

您的代码中可能有一个不变的换行符:

ConnectionString="<%$ //HERE
                   ConnectionStrings:MyDbConn %>"

. But my concern is a little different, why can't you custom define your select statement in the window that looks like this:

。但我的担心有点不同,为什么你不能在窗口中自定义你的select语句,如下所示:

从后面的代码访问ASP.Net变量时,“

Instead of in the code-behind?

而不是在代码隐藏?

#3


0  

Try to change your ASP.NET code into something like this:

尝试将ASP.NET代码更改为以下内容:

<asp:SqlDataSource ID="sds_Dashboard" runat="server" ConnectionString="<% ConnectionStrings:MyDbConn %>" />

Then from Code Behind, After some If/Else blocks, try this:

然后从Code Behind,在一些If / Else块之后,试试这个:

sds_Dashboard.SelectCommand = "Select * FROM ...";

It should work fine now.

它现在应该工作正常。

Thanks.

谢谢。

#1


1  

You can set SelectCommand of SqlDataSource in code-behind's Page_Load instead of aspx file:

您可以在代码隐藏的Page_Load而不是aspx文件中设置SqlDataSource的SelectCommand:

sds_Dashboard.SelectCommand = "Select * from .....";

#2


0  

There maybe a constant newline in your code here:

您的代码中可能有一个不变的换行符:

ConnectionString="<%$ //HERE
                   ConnectionStrings:MyDbConn %>"

. But my concern is a little different, why can't you custom define your select statement in the window that looks like this:

。但我的担心有点不同,为什么你不能在窗口中自定义你的select语句,如下所示:

从后面的代码访问ASP.Net变量时,“

Instead of in the code-behind?

而不是在代码隐藏?

#3


0  

Try to change your ASP.NET code into something like this:

尝试将ASP.NET代码更改为以下内容:

<asp:SqlDataSource ID="sds_Dashboard" runat="server" ConnectionString="<% ConnectionStrings:MyDbConn %>" />

Then from Code Behind, After some If/Else blocks, try this:

然后从Code Behind,在一些If / Else块之后,试试这个:

sds_Dashboard.SelectCommand = "Select * FROM ...";

It should work fine now.

它现在应该工作正常。

Thanks.

谢谢。