Results 1 to 4 of 4

Thread: ASP.NET and GridViews

  1. #1
    Hmmm bed
    Join Date
    Jul 2003
    Posts
    441
    Thanks
    5
    Thanked
    0 times in 0 posts

    ASP.NET and GridViews

    Hi All,

    I've been playing with asp.net and in particular gridviews. I am however wanting to do something which I can not seem to get to work.

    I want to define the datasource of the gridview as an objectdatasource (I'm using a vs.net data set and table adapters), now, I can do this fine through the gridviews little wizzard, however this places all the code in the .aspx file. What I want is for all the declaration of the objectdatasource stuff to be done in the pages .aspx.vb file, or even better in a seperate class.

    Is there anyway to do this?

    Regards,

    James

  2. #2
    Flower Child stytagm's Avatar
    Join Date
    Aug 2004
    Location
    London
    Posts
    754
    Thanks
    47
    Thanked
    23 times in 18 posts
    Not really sure what's up there, possibly it's an option in Visual Studio.

    When you added the gridview to the page in the first place, was there already a code behind file? If not, try creating it (I think just right-click, view-code) and then adding the gridview.

    If that doesn't work I try and find time to have an experiment later to figure it out.

    Which version of visual studio are you using? 2003? 2005? Express?
    They told me I was gullible ... and I believed them.

  3. #3
    Hmmm bed
    Join Date
    Jul 2003
    Posts
    441
    Thanks
    5
    Thanked
    0 times in 0 posts
    Hi, thanks for the response

    Yes, there is already a code-behind file there when i add the gridview onto the page.

    I am using VS2005

  4. #4
    Theoretical Element Spud1's Avatar
    Join Date
    Jul 2003
    Location
    North West
    Posts
    7,494
    Thanks
    335
    Thanked
    313 times in 249 posts
    • Spud1's system
      • Motherboard:
      • Gigabyte Aorus Master
      • CPU:
      • 9900k
      • Memory:
      • 16GB GSkill Trident Z
      • Storage:
      • Lots.
      • Graphics card(s):
      • RTX3090
      • PSU:
      • 750w
      • Case:
      • BeQuiet Dark Base Pro rev.2
      • Operating System:
      • Windows 10
      • Monitor(s):
      • Asus PG35VQ
      • Internet:
      • 910/100mb Fibre
    My main question is why?

    The datasource controls are just that - asp.net controls, and therefore they belong in the .aspx file as it is not your code. It's part of the way it works

    If you want it all in the .aspx.vb file then you should/could do it all with the SQLclient namespace (web.data.sqlclient i think) and connect to your datasource manaually (much more efficient and easier to do once you get the hang of which objects to use)

    Or if you insist on using the datasource control(s) you can simply put the asp declaration in the .aspx file, and configure it all programatically by setting its properties in your .aspx.cs (or vb) file.
    Last edited by Spud1; 05-01-2007 at 02:34 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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