在类中创建函数 [英] Creating Function in classes

查看:116
本文介绍了在类中创建函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我在表单上创建了一个导航方法。它只是从SqlDb中获取数据并在表单上的文本框中显示。它对于表单后面的代码工作正常..



我想为此创建一个不同的类函数,并希望从类中调用该函数。

我的问题是...如何在类中编写一个可以在我的表单中使用的函数,如何在我的表单上为文本框工作相同..



功能如下:----

 私有  Sub  Nav()
t1.Text = ds.Tables( 客户)。行(i).Item( 0
t2.Text = ds.Tables( Customer)。行(i).Item( 1
t3.Text = ds.Tables( 客户)。行(ⅰ).Item(<跨度class =code-digit> 2
结束 Sub



这是我为我的表单类编写的....如何在课堂上编写它。如何为表单上的texbox定义... ????



Plz help .....

解决方案

下面是供您参考的示例代码。您需要将文本框控件作为参数传递。





Imports System.Data

Imports System.Configuration

Imports System.Linq

Imports System.Web

Imports System.Web.Security

Imports System.Web。 UI

Imports System.Web.UI.HtmlControls

Imports System.Web.UI.WebControls

Imports System.Web.UI.WebControls。 WebParts

Imports System.Xml.Linq



命名空间WebApplication3

公共类Class1

Public Sub Nav(t1 As TextBox,t2 As TextBox,t3 As TextBox,ds As DataSet)

t1.Text = ds.Tables(Customer)。Rows(0).ItemArray( 0)

t2.Text = ds.Tables(Customer)。行(0).ItemArray(1)

t3.Text = ds.Tables(Customer ).Rows(0).ItemArray(2)

End Sub

End Class

结束命名空间



如果您需要任何进一步的帮助,请告诉我。


您需要  keep  index   of  当前记录  ViewState。 
显示下一个记录增量此索引 一个 私有减少 one。
无论何时在文件中调用 function 沿传递 index 其他参数。





如果您遇到任何语法问题,请告诉我。


更新你的功能测试它。



 私人  Sub  Button1_Click( ByVal  sender  As  System。 Object  ByVal  e  As  System.EventArgs)< span class =code-keyword>句柄 Button1.Click 
如果 i = 0 然后
nv.Nav(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,ds)
结束 如果
结束 Sub


Hi I have created a navigation method on form. It is simply fetch the data from SqlDb and shows in textboxes on form.It is working fine for code behind form..

I want to create a different class for this function and want to call that function from class.
My issues is ...How write a Function in class which can be used in my form , how it is goin to work for textboxes on my form for the same..

Function is as below:----

Private Sub Nav()
        t1.Text = ds.Tables("Customer").Rows(i).Item(0)
        t2.Text = ds.Tables("Customer").Rows(i).Item(1)
        t3.Text = ds.Tables("Customer").Rows(i).Item(2)
End Sub


This is when I write it for my form class....how to write it in class. how to define it for texboxes on form...????

Plz help.....

解决方案

Below is the sample code for your reference. You need to pass textbox control as parameter.


Imports System.Data
Imports System.Configuration
Imports System.Linq
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Xml.Linq

Namespace WebApplication3
Public Class Class1
Public Sub Nav(t1 As TextBox, t2 As TextBox, t3 As TextBox, ds As DataSet)
t1.Text = ds.Tables("Customer").Rows(0).ItemArray(0)
t2.Text = ds.Tables("Customer").Rows(0).ItemArray(1)
t3.Text = ds.Tables("Customer").Rows(0).ItemArray(2)
End Sub
End Class
End Namespace

Let me know if you need any further assistance.


You need to keep index of current record in ViewState.
To show next record increment this index by one and for privious decrease by one.
Whenever you call function  defined in class file you need to pass index along with other parameters.



If you are facing any problem with syntax then let me know.


update your function test it.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If i = 0 Then
            nv.Nav(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, ds)
        End If
    End Sub


这篇关于在类中创建函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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