Click here to Skip to main content
16,005,697 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted

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;
}
}
 
Share this answer
 
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%>'
/>

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900