New Posts  All Forums:Forum Nav:

C# GridView

post #1 of 4
Thread Starter 
I'm trying to use a custom object in a GridView for an ASP.NET project.

With normal string objects I can get the GridView to work, but for displaying custom objects I seem to be stuck.

In the Object class I have your usual accessors and mutators along with ToString(). All private variables are strings.


When I try to bind the object to a GridView it does not work.

Here's an example:

Code:
public class Bike
{
    private string name;
    private string color;
    private string owner;

    public Bike( String n, String c, String o)
    {
        name = n;
        color = c;
        owner = o; 
   }

    public void setColor(String s){ color = s; }
    public string getColor(){ return color;}
    .
    .
    .
    .
    // You get the idea
}

But when I try to bind an ArrayList of these Bike objects to a GridView it fails.

Code:
  ArrayList al = new ArrayList();
  Bike b = new Bike("huffy","green","bozo");
  al.add(b);
  GridView.DataSource = al;
  GridView.DataBind();
I get nothing...

Keep in mind if I bind the GridView to a simple ArrayList of things like String objects it works. Thanks in advance.
GAMR
(15 items)
 
  
CPUMotherboardGraphicsGraphics
6600K ASUS Z170-A ASUS 970 Strix ASUS 970 Strix 
RAMHard DriveHard DriveHard Drive
Crucial Ballistix Elite Samsung 850 EVO Intel 320 6400AAKS 
Hard DriveCoolingMonitorPower
6400AAKS Cooler Master Hyper 212 EVO ASUS VG24QE EVGA SuperNova 650 G2 
CaseMouseMouse Pad
Antec 1200 Razer Abyssus 3.5G QCK+ 
  hide details  
Reply
GAMR
(15 items)
 
  
CPUMotherboardGraphicsGraphics
6600K ASUS Z170-A ASUS 970 Strix ASUS 970 Strix 
RAMHard DriveHard DriveHard Drive
Crucial Ballistix Elite Samsung 850 EVO Intel 320 6400AAKS 
Hard DriveCoolingMonitorPower
6400AAKS Cooler Master Hyper 212 EVO ASUS VG24QE EVGA SuperNova 650 G2 
CaseMouseMouse Pad
Antec 1200 Razer Abyssus 3.5G QCK+ 
  hide details  
Reply
post #2 of 4
First ASP.NET controls can bind to object properties but not fields. Secondly, you're using java convention in defining properties. Should be done thusly in C#:

public string Name
{
get { ... }
}
Black Box 3
(13 items)
 
  
CPUMotherboardGraphicsHard Drive
i7 920 4GHz 1.248 VCore Gig EX58-UD3R 5870 2x160GB Hitachi RAID 0, 500GB WD 
Optical DriveOSPowerCase
ASUS DRW-2014L1T Windows 7 Ultimate 64bit SilverStone Zeus 850w Antec 902 
  hide details  
Reply
Black Box 3
(13 items)
 
  
CPUMotherboardGraphicsHard Drive
i7 920 4GHz 1.248 VCore Gig EX58-UD3R 5870 2x160GB Hitachi RAID 0, 500GB WD 
Optical DriveOSPowerCase
ASUS DRW-2014L1T Windows 7 Ultimate 64bit SilverStone Zeus 850w Antec 902 
  hide details  
Reply
post #3 of 4
Thread Starter 
I learned something new today

C# Properties. Although you can still used the traditional methods it does seem a little cleaner.

I'm still not too sure about how one would go about displaying the Object fields in .NET provided DataGrid/GridView/Table/etc...
GAMR
(15 items)
 
  
CPUMotherboardGraphicsGraphics
6600K ASUS Z170-A ASUS 970 Strix ASUS 970 Strix 
RAMHard DriveHard DriveHard Drive
Crucial Ballistix Elite Samsung 850 EVO Intel 320 6400AAKS 
Hard DriveCoolingMonitorPower
6400AAKS Cooler Master Hyper 212 EVO ASUS VG24QE EVGA SuperNova 650 G2 
CaseMouseMouse Pad
Antec 1200 Razer Abyssus 3.5G QCK+ 
  hide details  
Reply
GAMR
(15 items)
 
  
CPUMotherboardGraphicsGraphics
6600K ASUS Z170-A ASUS 970 Strix ASUS 970 Strix 
RAMHard DriveHard DriveHard Drive
Crucial Ballistix Elite Samsung 850 EVO Intel 320 6400AAKS 
Hard DriveCoolingMonitorPower
6400AAKS Cooler Master Hyper 212 EVO ASUS VG24QE EVGA SuperNova 650 G2 
CaseMouseMouse Pad
Antec 1200 Razer Abyssus 3.5G QCK+ 
  hide details  
Reply
post #4 of 4
Thread Starter 
Quote:
Originally Posted by decompiled View Post
I learned something new today

C# Properties. Although you can still used the traditional methods it does seem a little cleaner.

I'm still not too sure about how one would go about displaying the Object fields in .NET provided DataGrid/GridView/Table/etc...
Firstly this is cool because I get to quote myself.

Secondly I figured it out
GAMR
(15 items)
 
  
CPUMotherboardGraphicsGraphics
6600K ASUS Z170-A ASUS 970 Strix ASUS 970 Strix 
RAMHard DriveHard DriveHard Drive
Crucial Ballistix Elite Samsung 850 EVO Intel 320 6400AAKS 
Hard DriveCoolingMonitorPower
6400AAKS Cooler Master Hyper 212 EVO ASUS VG24QE EVGA SuperNova 650 G2 
CaseMouseMouse Pad
Antec 1200 Razer Abyssus 3.5G QCK+ 
  hide details  
Reply
GAMR
(15 items)
 
  
CPUMotherboardGraphicsGraphics
6600K ASUS Z170-A ASUS 970 Strix ASUS 970 Strix 
RAMHard DriveHard DriveHard Drive
Crucial Ballistix Elite Samsung 850 EVO Intel 320 6400AAKS 
Hard DriveCoolingMonitorPower
6400AAKS Cooler Master Hyper 212 EVO ASUS VG24QE EVGA SuperNova 650 G2 
CaseMouseMouse Pad
Antec 1200 Razer Abyssus 3.5G QCK+ 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming