i trying dynamically create gridview. 1 of columns user created row.
jobdebrief jd = new jobdebrief(jobid); job jb = new job(jobid); datagrid db = jobclass.job_piece.buildgrid(); db.columns.add(createboundcolumn(jd.dbriefedbyuser, "user")); placeholder.controls.add(db); db.datasource = jb.pieces; db.databind(); i created gridview in buildgrid function in job_piece class.
public static datagrid buildgrid() { datagrid newdg = new datagrid(); newdg.datakeyfield = "id"; newdg.autogeneratecolumns = false; newdg.cssclass = "tblresults"; newdg.headerstyle.cssclass = "tblresultsheader"; newdg.alternatingitemstyle.cssclass = "resultsstylealt"; newdg.itemstyle.cssclass = "resultsstyle"; newdg.columns.add(load.createboundcolumn("advisedqty", "qty advised")); newdg.columns.add(load.createboundcolumn("piecetypestring", "piece type")); newdg.columns.add(load.createboundcolumn("receivedqty", "rcvd qty")); newdg.width = unit.percentage(100.00); return newdg; } public static boundcolumn createboundcolumn(string datafield, string header,string cssclass ="",bool highlight = false) { boundcolumn column = new boundcolumn(); column.datafield = datafield; column.headertext = header; column.sortexpression = datafield; if (highlight) { column.itemstyle.cssclass = "columnhighlight"; } if (!string.isnullorempty(cssclass)) { column.itemstyle.cssclass = cssclass; } return column; } the 3 columns displaying come job_piece. since user doesn't belong class tried create column outside of function.
the column displays header rows blank. username comes jobdebrief class. since binding gridview pieces, db.datasource = jb.pieces; not finding information. possible set user column different datasource?
the simplest answar create new datatable , assign values in it
datatable dt= jb.pieces.copytodatatable(); dt.columns.add("userid") for(int i=0;i<dt.rows.count;i++) { dt.rows[i]=//your info } db.datasource = dt; db.databind();
Comments
Post a Comment