1

我需要一个网格,它在最后一列中有一些不同的颜色标签,如下所示。我知道如何处理一个标签,但我需要 4 个并且需要使用网格上的值(değer)使它们可见或不可见。

例如

  if value is below 20 the red label will appear,

  if value is over 40 the yellow and orange will appear same time,

  if value is between 20-40 green label will appear... 

任何帮助将不胜感激。

网格

4

2 回答 2

2

您需要一个如下所示的函数:

void UpdateGridColumnLabels(int index){
    int width = column.Width;
    int height = gridRow.Height;
    Bitmap bmp = new Bitmap(width, height, g);
    Graphics g = Graphics.FromImage(bmp);
    if(value < 20)
        g.FillRect(Brushes.Red, 0, 0, width / 3, height);
    else if(value >= 20 && value < 40)
        g.FillRect(Brushes.Orange, width/3, 0, width / 3, height);
    else
        g.FillRect(Brushes.Yellow, 2 * width/3, 0, width / 3, height);
    gridViewImageColumn[index] = bmp;
}

在这里,您正在创建一个适合您的单元格的位图。然后,您使用 Graphics 类根据您的条件动态添加标签。之后这个带有标签的位图成为单元格的内容。

于 2016-05-31T09:25:03.087 回答
0

你指的是这样吗?

<asp:TemplateField HeaderText="Select" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle">
        <ItemTemplate>
            <asp:Label runat="server" ID="lblId" Text='<%# Bind("Id") %>'
                Visible="false"></asp:Label>
            <asp:Label runat="server" ID="lblId" Text='<%# Bind("Id") %>'
                Visible="false"></asp:Label>
        </ItemTemplate>
    </asp:TemplateField>

代码背后:

protected void GridView1_RowDataBound(object sender,  GridViewRowEventArgs e)
    {
        try
        {

            Label lbl1 = (e.Row.FindControl("lblFirstEntry") as Label);
            //Play with your control

            Label lbl2 = (e.Row.FindControl("lblSecondEntry") as Label);        
            //Play with your control            
        }
    }
于 2016-05-31T09:07:25.740 回答