The GridView OnRowDataBound
event is your friend:
<asp:gridview
id="myGrid"
onrowdatabound="MyGrid_RowDataBound"
runat="server">
<columns>
<asp:boundfield headertext="ACount" datafield="ACount" />
<asp:boundfield headertext="BCount" datafield="BCount" />
<asp:boundfield headertext="DCount" datafield="DCount" />
<asp:templatefield headertext="Status">
<itemtemplate>
<asp:label id="aCount" runat="server" />
<asp:label id="bCount" runat="server" />
<asp:label id="dCount" runat="server" />
</itemtemplate>
</asp:templatefield>
</columns>
</asp:gridview>
// Put this in your code behind or <script runat="server"> block
protected void MyGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType != DataControlRowType.DataRow)
{
return;
}
Label a = (Label)e.Row.FindControl("aCount");
Label b = (Label)e.Row.FindControl("bCount");
Label d = (Label)e.Row.FindControl("dCount");
int ac = (int) ((DataRowView) e.Row.DataItem)["ACount"];
int bc = (int) ((DataRowView) e.Row.DataItem)["BCount"];
int dc = (int) ((DataRowView) e.Row.DataItem)["DCount"];
a.Text = ac < 0 ? "S" : "D";
b.Text = bc < 0 ? "S" : "D";
d.Text = dc < 0 ? "S" : "D";
}
I'm not sure where you want the 'S' and 'D characters rendered, but you should be able to rejig to meet your needs.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…