Click here to Skip to main content
15,901,283 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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:----
VB
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.....
Posted
Updated 27-May-13 1:28am
v3
Comments
[no name] 27-May-13 7:27am    
You would create an interface, pass the form instance to your other class or pass the controls to your other class.
Aman.Jen 27-May-13 7:33am    
Thnx for replying ....Its a single form application

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.
 
Share this answer
 
Comments
Aman.Jen 27-May-13 8:03am    
Thanx for replying ...but how wud i write like show next record on button click event..how will call that fuction and wat argument shud be passed then to that function..same for showing previous record
SQL
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.
 
Share this answer
 
Comments
Aman.Jen 27-May-13 8:32am    
I am stuck here ....:( this woking fine i define funtion in same form class but not working with class
i = 0
nv.Nav()
MessageBox.Show("First Record")


-------------------------------------
If i = len - 1 Then
MessageBox.Show("This ia a Last Record")

Else
i = i + 1
nv.Nav()
End If
Mahesh Bailwal 27-May-13 8:44am    
Is it web application or windows application as your using MessageBox.Show, which only works for windows application
Aman.Jen 27-May-13 9:04am    
Windows......
Mahesh Bailwal 27-May-13 9:46am    
are you getting some error? what exactly happening?
Aman.Jen 28-May-13 1:22am    
I have written on Btn click event as below...
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If i = 0 Then
nv.Nav(t1.Text, t2.Text, t3.Text, t4.Text, t5.Text, t6.Text, t7.Text, t8.Text, t9.Text, t10.Text, ds)
End If
End Sub

-------its shwoing error:--value type cannot be converted to string
update your function test it.

VB
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
 
Share this answer
 
Comments
Aman.Jen 28-May-13 2:09am    
yups..its working for first record....but for next record showing same record

here's the code..
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If i = len - 1 Then
MessageBox.Show("This ia a Last Record")
Else
i = i + 1
nv.Nav(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, ds)
End If
End Sub
Mahesh Bailwal 28-May-13 2:15am    
You need pass index which is i as parameter to the function. Then use it inside function to fetch vaues like below

ds.Tables("Customer").Rows(i).ItemArray(0)

Please also mark this question resolved if it works for you.
Aman.Jen 28-May-13 2:24am    
Still showing just one record......
Public Sub Nav(ByVal t1 As TextBox, ByVal t2 As TextBox, ByVal t3 As TextBox, ByVal t4 As TextBox, ByVal t5 As TextBox, ByVal t6 As TextBox, ByVal t7 As TextBox, ByVal t8 As TextBox, ByVal t9 As TextBox, ByVal t10 As TextBox, ByVal ds As DataSet) Implements MyInterface.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)
t4.Text = ds.Tables("Customer").Rows(i).Item(3)
t5.Text = ds.Tables("Customer").Rows(i).Item(4)
t6.Text = ds.Tables("Customer").Rows(i).Item(5)
t7.Text = ds.Tables("Customer").Rows(i).Item(6)
t8.Text = ds.Tables("Customer").Rows(i).Item(7)
t9.Text = ds.Tables("Customer").Rows(i).Item(8)
t10.Text = ds.Tables("Customer").Rows(i).Item(9)

End Sub
Mahesh Bailwal 28-May-13 2:28am    
You need pass i as parameter like below

nv.Nav(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, ds,i)
Aman.Jen 28-May-13 2:39am    
Thank you SOOOOOOOOOOOOOOOOOOOOOOO much Bro....:)............Done!!!!!!!!!!!!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900