页面加载增量 [英] Increment on page load

查看:87
本文介绍了页面加载增量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在每次加载页面时实现该值增加并显示在标签中

例如

页面加载标签-1显示1

如果再次加载页面,则label-1应显示2,依此类推,每次页面加载时,label-1的值应增加1.

how to implement that on each time page is load the value is increased and displayed in label
e.g
on page load label-1 is displaying 1
and if page is loaded again then label-1 should display 2 and so on on ,each time the page load the value of label-1 should increase by 1 .

推荐答案

在数据库中创建了一个名为hit的表格

然后

页面加载代码

created a table in database named " hit "
then
code on Page Load
<pre lang="vb">If Not IsPostBack Then
Dim co, jo As Integer
                cn.ConnectionString = &quot;server=localhost; user id=root; password=; database=**&quot;
                cn.Open()
                co = 1
                s = &quot;select * from hit where id=&#39;&quot; &amp; co &amp; &quot;&#39; &quot;
                cd = New MySqlCommand(s, cn)
                r = cd.ExecuteReader()
                r.Read()
                jo = CInt(r(&quot;count&quot;).ToString())
                Label5.Text = r(&quot;count&quot;).ToString()
                r.Close()
                cn.Close()

                Dim c As Integer
                Dim s1 As String
                cn.ConnectionString = &quot;server=localhost; user id=root; password=; database=**&quot;
                cn.Open()
                co = 1
                c = jo + 1
                s1 = &quot;update  hit set count=&#39;&quot; &amp; c &amp; &quot;&#39; where id=&#39;&quot; &amp; co &amp; &quot;&#39;&quot;
                cd = New MySqlCommand(s1, cn)
                cd.ExecuteNonQuery()
                cn.Close()
 End If
</pre>


你可以在Application对象或数据存储(数据库,XML文件,文本文件等)中存储值以使其保持不变。
You can store a value in the Application object, or in a data store ( database, XML file, text file, etc ) to make it persist.


这篇关于页面加载增量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆