简体   繁体   English

如何像我们在aspx:DropDown中那样用SqlDataSource填充aspx:TextBox?

[英]How to populate aspx:TextBox with SqlDataSource as we can in aspx:DropDown?

I need to populate a text box using some queries. 我需要使用一些查询来填充文本框。 I an newbie in asp.net, whereas i was able to do that with asp:DropDown . 我是asp.net的新手,而我却可以使用asp:DropDown做到这一点。 How should i do that? 我该怎么办?

You need to use the Page.DataBind() to bind public properties with your page. 您需要使用Page.DataBind()将公共属性与页面绑定。

<asp:textbox id=txt text="<%# custID %>" runat=server />

Refer the databinding overview 请参阅数据绑定概述

ASP.NET introduces a new declarative syntax, <%# %>. ASP.NET引入了新的声明性语法<%#%>。 This syntax is the basis for using data binding in an .aspx page. 此语法是在.aspx页中使用数据绑定的基础。 All data binding expressions must be contained within these characters. 所有数据绑定表达式必须包含在这些字符中。

No data is rendered to the control until you explicitly call either the DataBind method of the Web server control or until you invoke the page-level Page.DataBind method. 没有数据呈现到控制,直到显式调用Web服务器控件的DataBind方法或在调用页面级的Page.DataBind方法。 Typically, Page.DataBind (or DataBind) is called from the Page_Load event. 通常,从Page_Load事件中调用Page.DataBind(或DataBind)。

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

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