我的一个Datalist每一行里有一个html单元格,我要求每一行的背景色都不一样,取一个随机的颜色,我自己在itemdatabound事件里写了,但是不对,结果每行颜色都一样,请教正确的写法?private void dl_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
HtmlTableCell myt=(HtmlTableCell)e.Item.FindControl("td1");
if(myt!=null)
{
Random rd=new Random();
Color myco=Color.FromArgb(rd.Next(255),rd.Next(255),rd.Next(255));
myt.BgColor=myco.ToString();
}
}
{
HtmlTableCell myt=(HtmlTableCell)e.Item.FindControl("td1");
if(myt!=null)
{
Random rd=new Random();
Color myco=Color.FromArgb(rd.Next(255),rd.Next(255),rd.Next(255));
myt.BgColor=myco.ToString();
}
}
解决方案 »
- window.open内存不足
- 后台调用JS 关模式闭子窗口,刷新页面!!!急!!!
- aspnet 导出数据显示进度条
- TreeView获取不到选中的子节点的值
- 可以同时进行打开网页和更新数据库记录这两件事吗?
- SQL语法问题!很简单!我就是不明白为什么出错??
- asp.net2.0中,如何实现源页写查询条件,目标页出结果?
- 这是啥意思?无法找到脚本库“/aspnet_client/system_web/1_1_4322/webuivalidation.js“。请尝试手动放置此文件
- gridview怎么实现后台动态超链接?
- 谁能为小弟发一个使用了事件的TreeView的例子!!!最好是C#写的!!!!分不够还可以在加
- 求助!!如何在DataGrid中传递多值?在线等!!!!!!!
- 谁看过wrox的asp.net 电子商务高级编程或者对电子商务中打折和购物券有经验的进来~~~
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{ e.Item.Attributes.Add("onmouseover","currentcolor=this.style.backgroundColor;this.style.backgroundColor='48d1cc'");
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=currentcolor");这是一个当鼠标滑过时改变颜色的代码!
你改一下!
即myt.AlternatingItemstyle
If e.Item.ItemIndex = 0 Then
' e.Item.Attributes.Add("style", "cursor:hand")
e.Item.CssClass = "HeaderStyle" ElseIf e.Item.ItemIndex <> Session("row") - 1 Then
Dim i As Int32
For i = 0 To e.Item.Cells.Count / 2 e.Item.Cells.Item(2 * i).BackColor = System.Drawing.Color.Honeydew
Next End If
If e.Item.ItemType = ListItemType.Footer Then
Dim myGrid As DataGrid = CType(sender, DataGrid) CType(sender, DataGrid).Items(myGrid.Items.Count - 1).CssClass = "FooterStyle"
End If
End Sub这是设置datagrid的表头、表尾和列间隔不同的颜色
private void dl_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
Random rd = new Random();
Color myco = Color.FromArgb(rd.Next(255),rd.Next(255),rd.Next(255));
e.Item.BgColor = myco.ToString();
}e.Item 可以取到 TableRow。
e.Item.Cells 可以取到 TableCell。e.Item 有没有 BgColor?或者你用 e.Item.Attributes.Add() 也可以。
出来就该不同了