I have been loving the templated datacolumns of the datagrid. I have stumbled onto a problem though that is beyond by knowledge and I was hoping someone here could jumpstart me. My templated columns work find as long as I pass in a dataset but if I pass in a collection of objects then they won't work unless I can cast the correct object and then fill in the column with the object. My current code looks like this:
public void BindData(object sender, EventArgs e) {
Literal l = (Literal) sender;
DataGridItem container = (DataGridItem) l.NamingContainer;
Folder folder = (Folder) (((DictionaryEntry) container.DataItem).Value);
l.Text = folder[_column];
}
and it works fine as long as I know the object. But I can't figure out how to get it to work in a more generic manner - IE: I want to be able to determine the object on the fly, cast it and then have the BindData method populate the column from the _column in the object without knowing what the object is in advance.
Anyone have any pointers they'd like to share to get me in the right direction?
Thanks,
Alex 6 1293
Actually, I was being pretty dense, just adding the following solved it
object item = (object)(((DictionaryEntry) container.DataItem).Value);
DataBinder.Eval(item, this._idfield)
As long as I pass in an object then its no problem - I think I need to test to see whether its an object or a datarow so that I could handle both but this works.
Alex
"Alex" wrote: That's actually the approach I started to take but I wind up with a lot of if then constructs trying to determine what the appropriate object is. I'd like this to be more generic so I can decouple the object type that is passed in from retrieving the result. So I came up with the following which just casts a generic object:
object item = (object) (((DictionaryEntry) container.DataItem).Value); l.Text = item[_columnname];
The only problem with this is that the compiler won't compile it because I get an error that states I can't apply indexing to a type Object.
Alex "Natty Gur" wrote:
Hi,
I think you arn't in the right direction. check out : 1) http://www.dotnetjunkies.com/Tutoria...863-F85EE1AA76 2C.dcik
Natty Gur[MVP]
blog : http://weblogs.asp.net/ngur Mobile: +972-(0)52-8888377
*** Sent via Devdex http://www.devdex.com *** Don't just participate in USENET...get rewarded for it!
Actually, I was being pretty dense, just adding the following solved it
object item = (object)(((DictionaryEntry) container.DataItem).Value);
DataBinder.Eval(item, this._idfield)
As long as I pass in an object then its no problem - I think I need to test to see whether its an object or a datarow so that I could handle both but this works.
Alex
"Alex" wrote: That's actually the approach I started to take but I wind up with a lot of if then constructs trying to determine what the appropriate object is. I'd like this to be more generic so I can decouple the object type that is passed in from retrieving the result. So I came up with the following which just casts a generic object:
object item = (object) (((DictionaryEntry) container.DataItem).Value); l.Text = item[_columnname];
The only problem with this is that the compiler won't compile it because I get an error that states I can't apply indexing to a type Object.
Alex "Natty Gur" wrote:
Hi,
I think you arn't in the right direction. check out : 1) http://www.dotnetjunkies.com/Tutoria...863-F85EE1AA76 2C.dcik
Natty Gur[MVP]
blog : http://weblogs.asp.net/ngur Mobile: +972-(0)52-8888377
*** Sent via Devdex http://www.devdex.com *** Don't just participate in USENET...get rewarded for it!
"Alex" <Al**@discussions.microsoft.com> wrote in message
news:B2**********************************@microsof t.com... I have been loving the templated datacolumns of the datagrid. I have
stumbled onto a problem though that is beyond by knowledge and I was hoping
someone here could jumpstart me. My templated columns work find as long as
I pass in a dataset but if I pass in a collection of objects then they won't
work unless I can cast the correct object and then fill in the column with
the object. My current code looks like this: public void BindData(object sender, EventArgs e) { Literal l = (Literal) sender; DataGridItem container = (DataGridItem) l.NamingContainer; Folder folder = (Folder) (((DictionaryEntry)
container.DataItem).Value); l.Text = folder[_column]; }
and it works fine as long as I know the object. But I can't figure out
how to get it to work in a more generic manner - IE: I want to be able to
determine the object on the fly, cast it and then have the BindData method
populate the column from the _column in the object without knowing what the
object is in advance. Anyone have any pointers they'd like to share to get me in the right
direction?
If you don't know what the object is, how would you know what the "value"
is? The object could have two "values".
--
John Saunders
johnwsaundersiii at hotmail
When I initialize the templated control, I pass in the name of the value I want to render. In this way I can pass in a collection of objects. The collection will always contain the same type object but different collections may have different objects. I am trying to get my templated control to handle an object in the same way it would handle a dataset.
Alex
"John Saunders" wrote: "Alex" <Al**@discussions.microsoft.com> wrote in message news:B2**********************************@microsof t.com... I have been loving the templated datacolumns of the datagrid. I have stumbled onto a problem though that is beyond by knowledge and I was hoping someone here could jumpstart me. My templated columns work find as long as I pass in a dataset but if I pass in a collection of objects then they won't work unless I can cast the correct object and then fill in the column with the object. My current code looks like this: public void BindData(object sender, EventArgs e) { Literal l = (Literal) sender; DataGridItem container = (DataGridItem) l.NamingContainer; Folder folder = (Folder) (((DictionaryEntry)
container.DataItem).Value); l.Text = folder[_column]; }
and it works fine as long as I know the object. But I can't figure out how to get it to work in a more generic manner - IE: I want to be able to determine the object on the fly, cast it and then have the BindData method populate the column from the _column in the object without knowing what the object is in advance. Anyone have any pointers they'd like to share to get me in the right
direction?
If you don't know what the object is, how would you know what the "value" is? The object could have two "values". -- John Saunders johnwsaundersiii at hotmail
"Alex" <Al**@discussions.microsoft.com> wrote in message
news:FE**********************************@microsof t.com... When I initialize the templated control, I pass in the name of the value I
want to render. In this way I can pass in a collection of objects. The
collection will always contain the same type object but different
collections may have different objects. I am trying to get my templated
control to handle an object in the same way it would handle a dataset.
Well, you can look into using Reflection. Read up on the PropertyDescriptor
class, TypeDescriptor class and Type class.
--
John Saunders
johnwsaundersiii at hotmail "Alex" <Al**@discussions.microsoft.com> wrote in message news:B2**********************************@microsof t.com... I have been loving the templated datacolumns of the datagrid. I have stumbled onto a problem though that is beyond by knowledge and I was
hoping someone here could jumpstart me. My templated columns work find as long
as I pass in a dataset but if I pass in a collection of objects then they
won't work unless I can cast the correct object and then fill in the column
with the object. My current code looks like this: public void BindData(object sender, EventArgs e) { Literal l = (Literal) sender; DataGridItem container = (DataGridItem) l.NamingContainer; Folder folder = (Folder) (((DictionaryEntry)
container.DataItem).Value); l.Text = folder[_column]; }
and it works fine as long as I know the object. But I can't figure
out how to get it to work in a more generic manner - IE: I want to be able
to determine the object on the fly, cast it and then have the BindData
method populate the column from the _column in the object without knowing what
the object is in advance. Anyone have any pointers they'd like to share to get me in the right
direction?
If you don't know what the object is, how would you know what the
"value" is? The object could have two "values". -- John Saunders johnwsaundersiii at hotmail This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Kristofer Pettijohn |
last post by:
Greetings,
I'm trying to figure out if there is a way to determine whether a class
has the traits of another class...
For example...
I have a class called Square, which inherits Cube, which...
|
by: D Witherspoon |
last post by:
I am developing a Windows Forms application in VB.NET that will use .NET
remoting to access the data tier classes.
A very simple way I have come up with is by creating typed (.xsd) datasets.
For...
|
by: Trevor M. Lango |
last post by:
The number of arguments passed to the following functions can be
determined - but how is this coded?
main (int argc, char *argv)
printf ( string format )
I would like to be able to write...
|
by: Clinton Pierce |
last post by:
I've filled a DataTable with columns that have custom type (a class that I'm
using to keep track of other things, not just a value). When the .Select
method goes to sort this column, how do I let...
|
by: AW |
last post by:
Hello guys, it's my turn to ask for help,
I'm fighting with Visual Studio.net 2003. I made a templated control and it
displays alright when I ask the page through my browser, but Visual Studio...
|
by: lou zion |
last post by:
hey all,
i've got a class that A that has a static class member
static int MajorMode;
it's important that if one instance of the class changes this variable, all
instances react...
|
by: Anonieko |
last post by:
Hello ASPNET guru's,
What is a clean way to go around the problem of displaying a GridView
templated column where data can contain Single Quote ( ' )?
I maybe too naive, but this is of course...
|
by: Murray Hopkins |
last post by:
Hi.
THE QUESTION: How do I get a reference to my Object when processing an
event handler bound to an html element ?
CONTEXT:
Sorry if it is a bit long.
I am developing a JS calendar tool....
|
by: s16kumar |
last post by:
Hi,,
I am new to programming languages..
I want this problem to be resolved.
Consider a situation of three class.. C1, C2 & C3.
Class C3 has a method that receives the object as the...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |