c# - Need to Get data value prior to binding to row in listview -
i have listview
object in asp.net (c#) have listview_itemdatabound()
method populated using sqldatasource
.
in cases, able insert row in listview prior current record being bound. i.e., rows being populated, need able read value bound , insert "header" row mid stream before current row of data added listview
.
in case of itemdatabound
event, data seems bound control rows being added 1 listview
row late me anything.
listview_itemdatabound() { system.data.datarowview rowview = e.item.dataitem system.data.datarowview; //pseudo code of i'd //if rowview["some_field"]==123 // insert row prior row being bound }
i'm relatively new asp.net , come classic asp background maybe i'm thinking , going wrong. suggestions appreciated.
instead of doing after you've assigned datasource , called listview.databind()
should in datasource. presuming it's datatable
:
list<int> rowindices = new list<int>(); for(int = 0; < datatable.rows.count - 1; i++) { int some_field = datatable.rows[i].field<int>("some_field"); if (some_field == 123) rowindices.add(i + rowindices.count); // indices increases count } foreach(int index in rowindices) { datarow newrow = .... datatable.rows.insertat(newrow, index); }
now assign modified table datasource , call databind
.
Comments
Post a Comment