asp.net - gridview row eval: column as name parameter instead of index -
i have gridview , onrowdatabound event linked function:
if (e.row.rowtype == datacontrolrowtype.datarow) { thisrow = e.row.dataitem myobjectmodel; if (thisrow.property1 == null) { e.row.cells[5].text = "-"; }
this code looks @ value of property of object in data source , if it's null, converts null display "-" in column 5. problem i'm having if change order of columns of gridview, need change index of every other modification. i'd change statement "e.row.cells[5].text" says "the cell column header xyz".
any suggestions?
thanks.
i think might better off handling in gridview code rather code behind, if shuffling columns around.
here's example ponies. feel free edit needed.
<asp:templatefield headertext="likes ponies?"> <itemtemplate> <asp:label id="uxlikesponieslabel" runat="server" text=’<%# databinder.eval(container.dataitem, "favoriteponies").tostring() == "" ? "i " + databinder.eval(container.dataitem, "favoriteponies") + " ponies!" : "-" %>’ /> </itemtemplate> </asp:templatefield>
i'm using c# (boolean condition) ? "value if true" : "value if false"
here.
so, code check see if favoriteponies
column in particular row ""
(because null values displayed empty string) , if so, displays "-" instead. if it's not null, displays in database databinder.eval(container.dataitem, "favoriteponies")
"i ponies!".
Comments
Post a Comment