开发者

How To Get A Value Out Of A DetailsView DataItem Property

I am accessing a DetailsView from the following event

 public void dvDetails_Da开发者_运维知识库taBound(Object sender, EventArgs e)

I am casting the sender to my detailsview like so

DetailsView dv = (DetailsView)sender;

Now when I look in "dv" I can see the DataItem property has the data I want in it under a field name, but I dont know how to write the code access the value??

The field name is shown in the dataitem property as "_DTMON_F", I tried to say

Datetime myDate=dv.DataItem["_DTMON_F"]

BUT C# doesnt like the syntax, can someone help me with this?


That depends on the Datasource of your DetailsView. In case of a SqlDataSource DataItem would be a DataRowView. You have to cast it, then you can access it's column. For example:

Datetime myDate=(DateTime)((DataRowView)dv.DataItem)["_DTMON_F"];


Casting problem perhaps?

DateTime myDate=(DateTime)dv.DataItem["_DTMON_F"];

If the data source is a database, you may need to use Convert.


DataRowView drv = dv.DataItem as DataRowView;
DateTime myDate = (DateTime)drv["_DTMON_F"];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜