c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -


i have detailsview control on page used edit various fields of record, works in respect.

i looking way add 1 column (and if works, why not more) right, absolutely read-only, show same fields of record comparison purposes.

i aware there no obvious way such thing out of box detailsview. have looked other controls (transposed gridview, recommended formview, listview), nothing satisfies. have special data binding setup using detailsview , can't out of without losing features.

anyone on how "hack in" additional columns (for display only) on detailsview ?

the solution have now, use second detailsview, visible set false in aspx. in code, make sure databind hidden detailsview hosts data third column first, initial detailsview named itemdetails.

and in item created event, pass third column html rendering of hidden controls (in last code block) :

protected void itemdetails_itemcreated(object sender, eventargs e)         {             if (dataitem2 != null) //compare enabled             {                 var headerrow = ((detailsview)sender).headerrow;                 var headerl = new label();                 headerl.text = header2;                 headerl.style.add("font-weight", "bold");                 var headercell = new tablecell();                 headercell.controls.add(headerl);                 headercell.style.add("text-align", "right");                 headerrow.cells.add(headercell);                 if (string.isnullorempty(header1) && string.isnullorempty(header2)) ((detailsview)sender).headerrow.visible = false;             }             else             {                 ((detailsview)sender).headerrow.visible = false;             }             foreach (detailsviewrow r in itemdetails.rows)             {                 if (r.rowtype == datacontrolrowtype.datarow)                 {                     // assume first cell header cell                             var datacell = (datacontrolfieldcell)r.cells[0];                     string datafieldname = null;                     if (datacell.containingfield customboundfield) datafieldname = ((customboundfield)datacell.containingfield).getdatafieldname();                     else if (datacell.containingfield boundfield) datafieldname = ((boundfield)datacell.containingfield).datafield;                     if (dataitem2 != null) //compare enabled                     {                         if (!string.isnullorempty(datafieldname)) //it's field, copy boundfield hidden detailsview                         {                             var ct = new tablecell();                             var text = new stringwriter();                             var html = new htmltextwriter(text);                             dict[datafieldname].rendercontrol(html);                             ct.text = text.tostring().replace("<td>", string.empty).replace("</td>", string.empty);                             r.cells.add(ct);                         }                     }                 }             }          } 

Comments

Popular posts from this blog

php - cannot display multiple markers in google maps v3 from traceroute result -

javascript - firefox memory leak -