c# - Setting an ItemTemplate property in RunTime -
i trying display small progress bar in gridview within asp.net application. trying itemtemplate.
<itemtemplate> <table width="100%"> <tr> <td style="width: 75%; background-color: red"></td> <td style="width: 25%; background-color: green" ></td> </tr> </table> </itemtemplate>
i want set width percentage based on calculation of values within row.
can done somehow eval? or need code behind?
you can try following approach (sample calculation below):
<td style='<%# string.format("width: {0}%; background-color: red", (int)eval("width") / 100) %>'></td>
but readability sake should better move whole string construction code behind , call corresponding method on page.
update. code behind approach, here how can done. define method appropriate calculations , return string:
protected string getcellstyle(int width) { return string.format("width: {0}%; background-color: red", width / 100); }
and call same data binding syntax:
<td style='<%# getcellstyle((int)eval("width")) %>'></td>
Comments
Post a Comment