[2005] Asp.net 2.0 Classes...Please help
Hello all
I have 3 pages in my application
all 3 pages have gridview with same id, i want to bind data from 3 different tables to each 3 gridviews.
i want to create universal databind procedure to bind data to gridview in a class
i am using this line of code in my class
VB Code:
Public sub bind(byval sql as string)
sda = New SqlDataAdapter(sql, strConn)
sda.Fill(ds, "mytable")
GridView1.DataSource = ds.Tables("mytable").DefaultView
GridView1.DataBind()
end sub
i am passing sql string in page1 pageload
i am calling this class procedure in page load of page1 by creating object instance of the class
VB Code:
obj.bind(Select * from CustomerDetails)
But it is giving an error
object reference not set to an instance of object
how can i take referene of the gridview control present in page1 to the class
Kindly help me to solve this
Thanks in advance
Re: [2005] Asp.net 2.0 Classes...Please help
The class has no idea what GridView1 is. You should place the binding code on the page itself. Data retrieval should occur in the function itself, which can return a dataset to the page, but the binding should occur on the page. Keep the UI and logic separate.