473,326 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Determining Object Passed to a Templated Column

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

Nov 18 '05 #1
6 1293
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!
Nov 18 '05 #2
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!

Nov 18 '05 #3
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!

Nov 18 '05 #4
"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
Nov 18 '05 #5
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

Nov 18 '05 #6
"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

Nov 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
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...
16
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...
3
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...
2
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...
0
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...
9
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...
2
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...
6
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....
16
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
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...
0
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...
0
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...
0
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...
1
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)...
0
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
0
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...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.