tags:

views:

60

answers:

3

hi, i have an variable declated as an object Object obj =e.Row.DataContext;

when i go to immediate window and check the value i get like this

?Object obj =e.Row.DataContext;

{TempTypeMinus1487405295}
    People: "7,556,930"
    Name: "India"

string strcounty =obj .Tostring();

now in strcounty i should get as India

but i am getting the value as TempTypeMinus1487405295

how can i get the value india in string variable

thanks in advance

+1  A: 

I think you should cast incoming data type to your object

TypeOfObject obj = (TypeOfObject) e.Row.DataContext; 
or
TypeOfObject obj = e.Row.DataContext as TypeOfObject;

then your object has two properties as given info,if you wish to get Name property,you can access it within

obj.Name

If you dont cast it like this,you will receive name of type by default.

Hope this helps
Myra

Myra
what is the namespace used for to get TypeOfObject
prince23
!No,TypeOfObject refers to which type is bound to DataContext.It's just an example
Myra
hi myra, i am able to get the value e.Row.DataContext; what does bound here means ? would you expalin me
prince23
Indeed,e.Row.DataContext returns you "object" type.I think you misunderstood me with type of object.Immediate window exactly shows you what name of object in curly brackets { ... }.You can also try obj.ToString() which will give you the exact same.I presume that,if your information is correct for name for object's type is 'TempTypeMinus1487405295'.Just replace that with TypeOfObject in my answer to see that it's working
Myra
i am able to get the value e.Row.DataContext. how can i assign it to any variable is my Question if u can help me that would be great thanks
prince23
I don't know with the information you've given in the question.Explain more.
Myra
A: 

If you know the object type that you have in the row, you can use:

TempTypeMinus1487405295 obj = (TempTypeMinus1487405295)e.Row.DataContext

Or you can use the new Dynamic Objects that Net 4.0 have.

Jedi Master Spooky
A: 

finally i solved the issue

in the datagrid event in RowDetailsVisibilityChanged
wrote this code and finally for the value which i clciked.

var element = (TextBlock)dgCounty.Columns[0].GetCellContent(e.Row .DataContext );
string strcounty = element.Text.ToString(); 
prince23