简体   繁体   English

在HTML上使用vb.net变量

[英]Using vb.net variables on html

I am trying to use VB variable names to insert a name into an SQL Server Database from a grid view. 我正在尝试使用VB变量名从网格视图中将名称插入SQL Server数据库。 It is inserting a row, but the value in the database is the variable name not the value held by the variable. 它正在插入一行,但是数据库中的值是变量名,而不是变量保存的值。

I have defined names as 我将名称定义为

dim names as string="Mike"

and this is how am calling it on the gridview 这就是在gridview上如何调用它

<asp:Parameter Name="name" Type="String" Defaultvalue = ' <%=names %> ' />

and the SQL query is as follows 和SQL查询如下

UPDATE [Loans] SET [admin]=@name WHERE [Loanid] = @Loanid">

The problem is with inserting the data in the db here ' /> It is inserting 问题是在这里在数据库中插入数据'/>

Make your string public : Public Names As String = "Mike" 公开您的字符串: Public Names As String = "Mike"

Call Page.DataBind() in your Page_Load . Page_Load调用Page.DataBind()

Then access the variable by using <%# Names %> 然后使用<%# Names %>访问变量

Edit 编辑

Try setting your string to private : private _names as String 尝试将您的字符串设置为private: private _names as String

Then creating a public property. 然后创建一个公共财产。

    Public Property Names As String
            Get
                Return _names 
            End Get
            Set(value As String)
                _names = value
            End Set
   End Property

Then set the public proprty to the value you want (Names = "Mike") then you should be able to access the property it from your .aspx page using <%=Names%> 然后将公共属性设置为所需的值(名称=“ Mike”),那么您应该可以使用<%=Names%>从.aspx页访问该属性。

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

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