This message was discovered on ASPFriends.com 'aspngescalate' list.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
| Dennis Werry |
Hi,
I have posted this (twice) on aspngdatagridrepeaterdatalist and have received no answers.
I'm attempting to bind datalists/datagrids/repeaters to my own classes. I can get this to work fine as long as I specify the fields to which to bind - (e.g. AutoGenerateColumns="false"). I accomplish this by Implementing IEnumerable and creating a Default Property to return the appropriate field values. This all works fine.
Although I'm not sure that I'd really want to do this in a production environment, but to make my classes complete, and to better understand the infrastructure of .NET, I'd like to implement the appropriate interface so that I could do the equivalent of the following:
DataGrid1.AutoGenerateColumns = true;
// Employees ImplementsIEnumerable. DataGrid1.DataSource = new Employees(Employees.NightShift); DataGrid1.DataBind();
// Each Employee object has 17 fields, SSN, Lastname, Firstname, Address, //JobClass, etc.
What do I have to do to my class so that the datagrid can discover the number of "fields" and their "field names" at runtime? I'm sure I'm just over-looking it, but I can't find anything that specifically describes that process.
Said another way, "What interface or attribute does a DataView have that allows a DataGrid to discover the field count, and field names at runtime?"
Like I said, the above works fine, if I AutoGenerateColumns="False" and then specify the fields.
I've created another class that Implements IListSource that can return all the fields in the objects. Additionally, I have its default property, return the appropriate current data field value from the current row in the datasource. I just don't know how to expose that class to the grid from my objects.
Thanks in advance.
Dennis
|
|
| |
| |
| Brian Bilbro (VIP) |
I'm taking a totally wild stab at this, but perhaps implementing IDataReader will solve this. IDataReader defines GetSchemaTable() which the DataBind may use to get the header names. (there may a more appropriate interface to implement, this is just a start) -- Brian
----- Original Message ----- From: "Dennis Werry" <Click here to reveal e-mail address> Sent: 03/19/2002 5:58 AM
[Original message clipped]
|
|
| |
|
| |
| Dennis Werry |
Thanks Brian,
I'm still hoping that somebody from Microsoft will give me a clue as to the "BEST" way to handle this. But if they won't/can't/don't I will sure try out the IDataReader Interface.
I just can't help but think that there is a more pure way to do that ... since I don't think DataView implements the IDataReader Interface.
Thanks again.
Dennis
[Original message clipped]
|
|
| |
|
| | |
| |
| Isaac Hepworth |
[Original message clipped]
ITypedList.
Cheers,
Isaac
[Original message clipped]
|
|
| |
|
| |
| Dennis Werry |
Isaac,
Thanks for the response. When does it get invoked and by what means?
In other words, does my Employees Class have to implement ITypedList? ... or do I return a ITypedList from my default property? ... exactly how does that work?
Thanks again.
Dennis
[Original message clipped]
|
|
| |
|
| |
| Isaac Hepworth |
[Original message clipped]
yes, your datasource has to implement ITypedList. this gets used from the datagrid's private CreateAutoGeneratedColumns method.
the actual workings are that internally, your Employees class gets wrapped in a PagedDataSource object---and it is this that the datagrid interacts with. in DataGrid.CreateAutoGeneratedColumns, the datagrid calls GetItemProperties (from ITypedList) on the PagedDataSource, and the PagedDataSource checks if the datasource it's wrapping (your Employees class) implements ITypedList. if it does, it delegates the call and the columns of the grid get autogenerated from the result.
sorry if this hasn't come across clearly; email me off-list if you need more detail or clarification,
isaac
[Original message clipped]
|
|
| |
|
| |
| Dennis Werry |
Isaac,
I got it to work ... several ways.
I return an object from my Employees.Item that: Implements IEnumerable Implements IBindingList Implements IListSource
The Default Property Item(nIndex) of this returned object does not return field names, but Employee data. (this is what originally confused me)
yea!
But, however, no matter which way I get it to work, the columns come out in seemingly random order ... not in the order of my enumerator. Any ideas what is up with that?
I would assume that they would do something along the lines of: for each o in oColumns.GetEnumerator() AddColumn(o ...) next o
It is in very random order, not sorted, not in my order, I don't know what order.
Thanks for your help.
Dennis
[Original message clipped]
|
|
| |
| |
| shahzad |
hi After a long search i come to found your conversation at this forum I want to implement same thing as you in C# I have classes Depts & Dept
oDepts.GetAll(); foreach(Dept in oDepts) { response.write( Dept.Name); response.write( Dept.Address); response.write( Dept.Owner); } it works crrectly now i want to implement it in such a way that i can assing myDepts object to a data grid like this dataGrid1.datasource = oDepts; so that it automacitaly fill the datagrid to achive this what is need to do i have try to implemts different interface but not success
-------------------------------- From: shahzad arfan Click here to reveal e-mail address
|
|
| |
|
|
|
|
|
|