ASP.NET 2.0 and DATAGRIDVIEW with Objects

Core

Member
Joined
Apr 23, 2006
Messages
10
Programming Experience
1-3
In VB you can create a class, create an object datasource for it and drag it right onto your form.

Why can't I do this in ASP? I can create the datasource no problem. But it doesn't even have the little arrow so you can select master/details.

I am assuming I have to bind it progamatically. How do I do that? Can someone point me to an example?

Thanks for any and all help!
 
Current Answer:

Originally I created a class "rank.vb" with properties to set variables and then made an array of them.

Public RankList(200) As Rank

I set a object datasource to rank and pulled a datagridview onto my form. After updating the array I simple bound it.

Me
.RankBindingSource.DataSource = RankList

That didn't work with ASP.NET. As soon as I tried to move it over to ASP it wouldn't bind.

So basically here is what I did. I stripped out all other variables except one.

I added a Sub to Rank.vb (Rank.vb class code not provided)

Public Sub New(ByVal CurrentRank_ As String)
Me.CurrentRank = CurrentRank_
End Sub

Then I created a new class RankList.vb with the following code:

Imports System.Collections.Generic

Public
Class RankList
Public Function GetList() As List(Of Rank)
Dim NewList As New List(Of Rank)
Dim iter As Integer
For iter = 0 To 199
If gCurrentRank(iter) = ""Then Exit For
NewList.Add(New Rank(gCurrentRank(iter)))
Next
Return NewList
End Function
End
Class

Then I added a gridview and from it's smart tag I selected new datasource. I could then select this function to retrieve the data. I had to also go into properties for the gridview and add selected columns.

Now even though this worked it just feels wrong. Am I doing this right?
 
If it works then it seems that you're doing it right. Perhaps your question should be "Am I doing this efficiently?".
But it doesn't even have the little arrow
You can drag the tables listed in the DataBase Explorer to a webForm and the IDE will do the binding (I'm not sure what you mean by little arrow but you don't need one, simply drag the table Icon or tableName to the webform).

Here's a link to some good videos.
In case you're unaware, MSDN.com is a great resource for learning.
 
Paszt,

Thank you for replying. You are the first person to reply to any of my questions in this forum.

I think I steered you wrong with my description. I can't drag my class object datasource onto the webform. I have tried 9 ways from Sunday to do it and it won't drag onto the form. It will pull out over the form but it has a little circle with a line in it. I can't click the datagrid smart tag and set the datasource that way either. It wants a function to retrieve the data. (Which brought me to the above solution)

The way I found to do it is consuming memory by the truck load. My 2003 Server R2 blue screens at the 3rd consecutive request every single time.

I am forced at this point to go with another approach.

BTW: Am I supposed to be able to take out Windows Server 2003 so easily? It says attempt to write to readonly memory... BOOM!
 
Back
Top