本文介绍了如何将backcolor设置为gridview的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hiii,



在我的数据库中,我的颜色代码表都是十六进制值..

现在在gridview专栏中想要显示我有标签的一列。我想将标签文本设置为颜色名称,将背景颜色设置为该颜色。想要根据每行的颜色显示显示...





Hiii,

In my database i have table of color codes that is all hexadecimal values ..
now in gridview column i want to show one column in which i have labels . i want to set labels text as a color name and back color as that color.want to display display according colors in each row ..


protected void gvAbsenceTypes_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if (DataBinder.Eval(e.Row.DataItem, "TotalLeave") != null)
                {
                    if (DataBinder.Eval(e.Row.DataItem, "TotalLeave").ToString() != "0")
                    {
                        Label lblTotalLeave = (Label)e.Row.FindControl("lblTotalLeave");
                        lblTotalLeave.Text = DataBinder.Eval(e.Row.DataItem, "TotalLeave").ToString();
                    }
                }

                if (DataBinder.Eval(e.Row.DataItem, "colorcode").ToString() != "0")
                {
                    Label lblTotalLeave = (Label)e.Row.FindControl("lblColour");
                    lblTotalLeave.Text = System.Drawing.Color.FromName(DataBinder.Eval(e.Row.DataItem, "colorcode").ToString());
                }
            }
        }

推荐答案

lblTotalLeave.BackColor = System.Drawing.Color.FromName( DataBinder.Eval( e.Row.DataItem, "colorcode" ).ToString() );

lblTotalLeave.Text = System.Drawing.Color.FromName( DataBinder.Eval( e.Row.DataItem, "colorcode" )).Name.ToString();





我相信这会解决你的问题问题。



I am sure this will solve your problem.



<asp:label id="lblColour" backcolor="<%#Eval("colorcode") %>" runat="server" xmlns:asp="#unknown"></asp:label>


这篇关于如何将backcolor设置为gridview的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-18 04:53
查看更多