使用SQL绑定DataList项目字段(按钮返回颜色) [英] Bind DataList Item Field (Button Back Color) With SQL

查看:74
本文介绍了使用SQL绑定DataList项目字段(按钮返回颜色)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想绑定Datalist项目模板返回颜色与SQL Server表

如果在表中颜色绿色比按钮颜色也应该是绿色

谢谢。

Hi ,
I want to Bind Datalist item Template back Color with SQL Server Table
If In Table Color Green Than Button Color also should be Green
Thanks.

推荐答案

实现下面的方法并在任何模板中更改颜色,确保你绑定datalist的同一个表然后在datalist将具有颜色名称,然后从e.item [index]获取颜色,然后找到按钮控件并设置按钮的背面颜色。下面只是一个如何获取intem事件的例子。

protected void DataList1_ItemCreated(object sender,

EventArgs e)

{

switch(e.Item.ItemType) )

{

case ListItemType.Item:

e.Item.BackColor =

System.Drawing.Color .LightGoldenrodYellow;

休息;

case ListItemType.AlternatingItem:

e.Item.BackColor = System.Drawing.Color.DarkGoldenrod;

break;

case ListItemType.SelectedItem:

e.Item.BackColor = System.Drawing.Color.Yellow;

break;

默认值:

//这里添加代码来处理页眉,页脚和

//分隔符模板。

休息;

}

}
Implement below method and change your color in any template, make sure your the same table binding the datalist then have a hidden column in the datalist which will have the color name, and then get the color from e.item[index] and then find the button control and set the back color of button. below is just an example how to get the intem event.
protected void DataList1_ItemCreated(object sender,
EventArgs e)
{
switch (e.Item.ItemType)
{
case ListItemType.Item :
e.Item.BackColor =
System.Drawing.Color.LightGoldenrodYellow;
break;
case ListItemType.AlternatingItem :
e.Item.BackColor = System.Drawing.Color.DarkGoldenrod;
break;
case ListItemType.SelectedItem :
e.Item.BackColor = System.Drawing.Color.Yellow;
break;
default :
// Add code here to handle the header, footer, and
// separator templates.
break;
}
}


谢谢。

但我发现它我自己。这是解决方案。











< itemtemplate>

< asp:button id =Button6runat =serverxmlns:asp =#unknown>

BorderColor = MaroonBorderStyle =DoubleFont-Bold =TrueForeColor =White

Height =40pxText =''<%#Eval(qid)%> ''Width =40pxBackColor =''<%#Convert.ToString(Eval(color))==Red? System.Drawing.Color.Red:

Convert.ToString(Eval(color))==Blue? System.Drawing.Color.Blue:Convert.ToString(Eval(\"color))==黄色? System.Drawing.Color.Yellow:Convert.ToString(Eval(color))==Green? System.Drawing.Color.Green:System.Drawing.Color.Purple%>''

/>


Thanks.
but i find it myself.Here is Solution.





<itemtemplate>
<asp:button id="Button6" runat="server" xmlns:asp="#unknown">
BorderColor="Maroon" BorderStyle="Double" Font-Bold="True" ForeColor="White"
Height="40px" Text=''<%# Eval("qid") %>'' Width="40px" BackColor=''<%# Convert.ToString(Eval("color")) == "Red" ? System.Drawing.Color.Red:
Convert.ToString(Eval("color")) == "Blue" ? System.Drawing.Color.Blue:Convert.ToString(Eval("color")) == "Yellow" ? System.Drawing.Color.Yellow: Convert.ToString(Eval("color")) == "Green" ? System.Drawing.Color.Green: System.Drawing.Color.Purple%>''
/>

这篇关于使用SQL绑定DataList项目字段(按钮返回颜色)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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