Results 1 to 2 of 2

Thread: [2005] Asp.net 2.0 Classes...Please help

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Posts
    244

    [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:
    1. Public sub bind(byval sql as string)
    2.   sda = New SqlDataAdapter(sql, strConn)
    3.    sda.Fill(ds, "mytable")
    4.   GridView1.DataSource = ds.Tables("mytable").DefaultView
    5.   GridView1.DataBind()
    6. 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:
    1. 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

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width