OnItemDataBound to set row values
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.
精彩评论