开发者

OnItemDataBound to set row values

开发者 https://www.devze.com 2022-12-26 07:25 出处:网络
I need to set a cell value to something dependant on other values which are only available during data binding so I\'m using OnItemDataBound but it says I can\'t set the dataitem value.

I need to set a cell value to something dependant on other values which are only available during data binding so I'm using OnItemDataBound but it says I can't set the dataitem value.

Any ideas how to do this?

protected override void OnItemDataBound(Repea开发者_StackOverflowterItemEventArgs e) {

    base.OnItemDataBound(e);

    DateTime date = (DateTime)DataBinder.Eval(e.Item.DataItem, "date");

    string year = String.Format("{0:yyyy}", date);
    string month = String.Format("{0:MM}", date);

    ((DataRowView)e.Item.DataItem)["url"] = "/" + year + "/" + month;

}

Results in the exception:

System.Data.DataException: Cannot set url.


Well I guess this isn't possible then. I've gotten around the problem by setting the values in the underlying datatable before binding to the repeater.

0

精彩评论

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

关注公众号