我有一个数据网格,其中包含带有标签的项目模板:
<asp:datagrid id="ID" runat="server" Width="641px" CellPadding="2" PageSize="2" DataKeyField="IDs"
AutoGenerateColumns="False" ShowFooter="True" BorderColor="AliceBlue" OnItemDataBound="ID_ItemDataBound" >
<SelectedItemStyle ForeColor="HighlightText" BackColor="Highlight"> </SelectedItemStyle>
<AlternatingItemStyle BackColor="WhiteSmoke">
</AlternatingItemStyle>
<HeaderStyle Font-Bold="True" BackColor="AliceBlue">
</HeaderStyle>
<FooterStyle Font-Bold="True" BackColor="AliceBlue">
</FooterStyle>
<Columns>
<ItemTemplate>
<asp:label BorderStyle=None Visible='<%# ReverseBool(Convert.ToBoolean(DataBinder.Eval(Container, "DataItem.IsCompleteOrNot"))) %>' runat="server" ID="dataScore" Text='<%# DataBinder.Eval(Container, "DataItem.dataScore" ) %>'>
</asp:label>
<asp:label BorderStyle=None Text='<%# GetCompleteIncomplete(Convert.ToInt32(DataBinder.Eval(Container, "DataItem.dataScore")!=null)) %>' Visible='<%# DataBinder.Eval(Container, "DataItem.IsCompleteOrNot") %>' id="txtIsComplete" runat="server">
</asp:label>
</ItemTemplate>
</columns>
我正在尝试将 0 设置为空白,而不是在 DataGrid 中显示 0,因此在 ItemData 绑定时,我得到这样的标签并尝试将值设置为 null:
if ((e.Item.ItemType == ListItemType.Item) ||
(e.Item.ItemType == ListItemType.AlternatingItem))
{
Label dataScore = (Label)e.Item.FindControl("dataScore"); // Gets that Label
Label txtIsComplete = (Label)e.Item.FindControl("txtIsComplete");
if(dataScore .Text == "0")
{
dataScore.Text = string.Empty; // Tried
}