如何在Gridview中为控件添加颜色 [英] How to back color a control in Gridview

查看:71
本文介绍了如何在Gridview中为控件添加颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在网格视图中返回备用行的颜色。有用。同时如何使用相同颜色对备用行的控件进行着色。对于boundfield,它可以,但对于像Textbox这样的其他控件,如何制作它。其他控件的背面颜色为白色,看起来不太好。



I want to back color alternate rows in a gridview. It works. At the same time how to color back of controls of alternate rows with the same color. For boundfield it is OK but for other controls like Textbox , how to make it. The back color of other control is white and does not look nice.

<asp:GridView ID="grvcart" runat="server"   style=" margin-top:447px; margin-left:450px ; "   BorderStyle="Groove" BorderWidth="1" BorderColor="White"

                ShowFooter="True" AutoGenerateColumns="False" GridLines="None"  Width="787" HeaderStyle-Font-Size="Small" HeaderStyle-ForeColor="White"

                CellPadding="4" ForeColor="#999999"  OnRowDeleting="grvcart_RowDeleting" HeaderStyle-BackColor="#666666"  RowStyle-BackColor="White" AlternatingRowStyle-BackColor="#cccccc" >
    <Columns>
        <asp:BoundField DataField="RowNumber" HeaderText="SNo"  />

        <asp:TemplateField HeaderText="Product Id" >
        <ItemTemplate>
        <asp:TextBox ID="TBProductId" Width="44"     runat="server" ReadOnly="true" ForeColor="Black"  BorderStyle="None" Style=" text-align:center"

        Text=''></asp:TextBox>
        </ItemTemplate>
        </asp:TemplateField>

推荐答案

尝试下面的代码:



protected void grvcart_RowDataBound(object sender,GridViewRowEventArgs e)

{



if(e.Row.RowType == DataControlRowType.DataRow)

{

if(e .Row.RowIndex%2 == 0)

{

TextBox TBProductId =(TextBox)e.Row.FindControl(TBProductId);

TBProductId.BackColor = System.Drawing.ColorTranslator.FromHtml(#ffffff);

}

else

{

TextBox TBProductId =(TextBox)e.Row.FindControl(TB ProductId);

TBProductId.BackColor = System.Drawing.ColorTranslator.FromHtml(#cccccc);

}

}



}
Try below code:

protected void grvcart_RowDataBound(object sender, GridViewRowEventArgs e)
{

if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowIndex % 2 == 0)
{
TextBox TBProductId = (TextBox)e.Row.FindControl("TBProductId");
TBProductId.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
}
else
{
TextBox TBProductId = (TextBox)e.Row.FindControl("TBProductId");
TBProductId.BackColor = System.Drawing.ColorTranslator.FromHtml("#cccccc");
}
}

}


嗨..

看到它的帮助全部到你使用jquery。

Hi..
See this its help full to u using jquery.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script type="text/javascript">


(文件).ready(function(){
(document).ready(function () {


这篇关于如何在Gridview中为控件添加颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆