开发者

Assign database value to hyperlink but not a runat=server

开发者 https://www.devze.com 2023-02-03 03:23 出处:网络
Its simple if I have an ASP.net page with an ASP.net linkbutton / hyperlink and I obtain a value from say a SQL Database and I store it in the label...

Its simple if I have an ASP.net page with an ASP.net linkbutton / hyperlink and I obtain a value from say a SQL Database and I store it in the label...

For example:

this.myLabel.Text = someValueReturnedFromADatabase

This is simple because it goes right to the code behind page and set the text value to the value returned from my database (aside from going into more details with data access layer, etc).

What I was wondering is what if I dont want to use an ASP.net linkbutton and I simply want to use an HTML link button (as I need to call the jquery fade function). How would I set the value开发者_如何学JAVA someValueReturnedFromADatabase to a control that is not runat=server?


Have a variable in your codebehind:

protected string TextForLabel

Set it in Page_Load, or wherever:

TextForLabel = someValueReturnedFromADatabase;

Reference it with pointy-bracket percent notation:

<a href="http://www.stackoverflow.com/"><% =TextForLabel %></a>


You can set runat="server" on standard html controls. I do it all the time. Then you will be able to access their properties in your code behind just like you do for asp controls.

If I am not mistaken, for labels you can use .InnerText or .InnerHTML to change the text.


From what I know of, you need to make some sort of relation between your HTML document and the code behind to interact with data from a SQL database. Either that or you'll have to make the entire database connection etc. in the HTML header using script type="text/javascript" and script type="text/C#" or whatever language you use to develop.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号