Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
服务器端的ASP.Net字符串_Asp.net - Fatal编程技术网

服务器端的ASP.Net字符串

服务器端的ASP.Net字符串,asp.net,Asp.net,我在服务器端有一个字符串。我想将此字符串绑定到textbox的文本属性或图像的imageurl属性 服务器端 public string image_path = "@/tool_images/10000000s0.png"; 我在客户端试过这些 <asp:Image ID="t10000000" runat="server" ImageUrl='<%=image_path %>' /> <asp:TextBox ID="ASPTextBox1" runa

我在服务器端有一个字符串。我想将此字符串绑定到textbox的文本属性或图像的imageurl属性

服务器端

public string image_path = "@/tool_images/10000000s0.png";
我在客户端试过这些

 <asp:Image ID="t10000000" runat="server" ImageUrl='<%=image_path %>' />  
 <asp:TextBox ID="ASPTextBox1" runat="server" Text='<%= image_path %>' />
 <asp:TextBox ID="TextBox1" runat="server" Text="<%# image_path %>" />

它不能工作

“”的输出为
“”的输出为空

如果输出为true,我希望使用三元运算符绑定此ImageURL属性。 让我知道它是否适合你

布尔表达式?trueValue:falseValue用于将数据绑定到控件,因此您需要为每个控件调用数据绑定方法

<asp:Image ID="t10000000" runat="server" ImageUrl='<%# image_path %>' />
<asp:TextBox ID="ASPTextBox1" runat="server" Text='<%# image_path %>' />
<asp:TextBox ID="TextBox1" runat="server" Text="<%# image_path %>" />

// Code Behind
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        t10000000.DataBind();
        ASPTextBox1.DataBind();
        TextBox1.DataBind();
    }
}

//代码隐藏
受保护的无效页面加载(对象发送方、事件参数e)
{
如果(!IsPostBack)
{
t10000000.DataBind();
ASPTextBox1.DataBind();
TextBox1.DataBind();
}
}

仅供参考:在ASP.NETWeb表单中,我们通常不使用这种方法将数据绑定到控件,除非这些控件位于数据控件中,如GridView、ListView或Repeater。换句话说,我们只是在代码后面赋值,比如t10000000.ImageUrl=image\u path

这些图像和文本框是位于GridView还是其他一些数据控件中?@Win No。只是在div中,它可以工作。但我的主要目的是根据id动态更改图像URL。