string variable not able to get thevalue
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
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
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.
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();
精彩评论