简体   繁体   English

ASP.NET web 形式:显示值来自 c# 代码隐藏

[英]ASP.NET web form: display value coming from c# code-behind

I am working with Visual Studio 2019, where I am creating a web form.我正在使用 Visual Studio 2019,我正在创建一个 web 表单。 My code-behind pulls data from a database using a sql script.我的代码隐藏使用 sql 脚本从数据库中提取数据。 I have to display some of these fields in the web form.我必须在 web 表单中显示其中一些字段。

For instance, project_description is one of the fields, which is stored as ProjDesc in my.cs file.例如, project_description是字段之一,它作为ProjDesc存储在 my.cs 文件中。

In the web form, I have a text box intended to display this field:在 web 表单中,我有一个用于显示此字段的文本框:

<td class="auto-style29"><b>Project description</b></td>
<td class="auto-style5"><asp:TextBox Text="<insert variable>" ID="txtProjTitle" runat="server" Width="768px" Height="26px" ReadOnly ="true" Enabled="false" CssClass="auto-style16"></asp:TextBox></td>

Where it says <insert variable> , I tried to use the variable name ProjDesc , but this was highlighted because "it does not exist in the current context".在它说<insert variable>的地方,我尝试使用变量名称ProjDesc ,但由于“它在当前上下文中不存在”而突出显示。

What's the correct way of recalling ProjDesc from my.aspx file?从 my.aspx 文件中调用ProjDesc的正确方法是什么? Does it have to go under the Text properties?是否必须在Text属性下为 go ?

If you are using web forms then one way to set the text of your textbox from the aspx is in an event of the web page, probably the same event that is firing the SQL script. If you are using web forms then one way to set the text of your textbox from the aspx is in an event of the web page, probably the same event that is firing the SQL script.

txtProjTitle.Text = ProjDesc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM