Question how to bind the dataset

yudun1989

New member
Joined
Dec 10, 2010
Messages
2
Programming Experience
Beginner
I've created a web form by vb.net 2005 and added a gridView called gridView1,now I want to use a web method on web service to bind the gridview,and each time the form was loaded bind a table to the GridView1.how to bind it?

my class name is CCustomerRel and the sub is a construction method
Sub CCustomerRel()
Dim aa As OrderInformation = newAutoService.GetCustomerRepairs()
'GetCustomerRepairs is a web method that returns a table
GridView1.DataSource = aa.OrderStatus
'orderInformation is a class that inherts class 'dataset' and OrderStatus is a table
GridView1.DataBind()
End Sub
 
If the GetCustomerRepairs is a Funtion of DataTable datatype then you can just assign it as DataSource e.g.

Dim table As DataTable = AutoService.GetCustomerRepairs()
GridView1.DataSource = table
GridView1.DataBind()


Or if it requires to be instantiated e.g.

Dim orderifno As New AutoService
Dim table As DataTable = orderifno.GetCustomerRepairs()
GridView1.DataSource = table
GridView1.DataBind()


Hmm it is little confusing what is what here. OrderInformation is What and AutoService is what? Please clarify. Thx
 
thx for attention!
okay I've understood what you said ,but i just want to add an event-driven subroutine to my web form class that is called when my web form is loaded.Each time the web form is loaded ,i want to bind my table to my datagrid . how to add the subroutine?
 
Well, The Page_Load event is triggered when a page loads, and ASP.NET automatically calls the subroutine Page_Load, and execute the code inside it.

If you want to execute the code in the Page_Load subroutine only the FIRST time the page is loaded (which is not what you want), you can use the Page.IsPostBack Property (System.Web.UI)

VB.NET:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not IsPostBack Then
         ' some code to be executed only the FIRST time the page is loaded (not necessary in this situation)         
    End If

         ' your code from the above that will be executed EVERY time the page is loaded
End Sub
 
Back
Top