Color by color in DataList

I use the DataList, and I want to set the background color in each item in a random way, anybody help me ?

Thank in advanced
MSN: unfriendlyboy@hotmail.com

ASP.NET fan.
0
boy_behind_glasses
8/22/2003 1:14:11 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

4 Replies
1330 Views

Similar Articles

[PageSpeed] 52

You can set the background color of items in the DataList in ItemCreated. This method is called as each item is created. Within your ItemCreated method, you can use e.Item.BackColor to set the background color.

To randomize the colors, take a look at the Random class. You'd probably want to use one of the "Next" overrides to generate your color number or numbers.
Jim


MS MVP ASP.NET [VC++/MFC emeritus]


Old Dog Learns New Tricks

Preferred programming language: cuneiform on clay tablets
0
JimRoss
8/22/2003 4:14:21 PM
Thank you for replying, but because I'm new of ASP.NET, so can you give me an example?

Thank in advanced
MSN: unfriendlyboy@hotmail.com

ASP.NET fan.
0
boy_behind_glasses
8/23/2003 4:19:26 AM
Here is an example of how to set the color on a row in a DataGrid in ItemCreated. A datalist will be almost identical I have never used Random, so you'll have to work from the documentation to figure out how to use it to generate a color number. It shouldn't be that hard.
    Private Sub dgUsers_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgUsers.ItemCreated

Dim lb As LinkButton
If e.Item.ItemType = ListItemType.AlternatingItem
e.Item.BackColor = Color.Green
Else
if e.Item.ItemType = ListItemType.Item Then
e.Item.BackColor = Color.Red
End if
End If
End Sub

Jim


MS MVP ASP.NET [VC++/MFC emeritus]


Old Dog Learns New Tricks

Preferred programming language: cuneiform on clay tablets
0
JimRoss
8/24/2003 1:40:59 AM
It's really a good code. The problem is solved.

Thank a lot.
MSN: unfriendlyboy@hotmail.com

ASP.NET fan.
0
boy_behind_glasses
8/24/2003 2:01:50 AM
Reply:

Similar Artilces:

Generating Color 3d-Chart in VB.NEt using 2 giving colors and number of colors as argument
I was wondering if anyone has an idea of how I can program a color-gradient value capturing function. My program will recieve 2 values as input ( StartColor and EndColor). The function will then return an array of 20 colors that exist between the two inputted colors. What I then intend to do with the values returned, is create an XML file and then using the gradient values to plot a 3d Chart or Graph. Does anyone have any idea how I can go about dealing with this? Can anyone help please?.NET Newbie...

C# Graphics.Clear(Color color) did not update color!
Hi, I have code that resizes an image and fills border spaces with certain color. This works fine, but when i changed the original color to a different one it still fills it with the original color. I rebuilt and built my project to try and get it to update right, but it still uses the original color. Any suggestions will be very much appreciated. E  Are you using any dll for doing that. If so mention the dll name , you can post your code here not the full one the part where there is a trouble.usually the syntax "Graphics.fill(Color color)" to update c...

Color Control in DataList Codebehind
My DataList for products is populated in my Codebehind file, the sql being a stored procedure which takes in page, number of products per page, and categoryid. Each category has a particular color, which I want to display as a heading outside of the datalist. At the moment, the color value is coming from an Inner Join in my sql statement. I have referenced this value before as such... ForeColor=<%# System.Drawing.Color.FromName(Eval("Color").ToString()) %> This obviously in my aspx page. I want to transfer this to my code behind file. My label is at the top of the page, above the d...

About colors
Hi In some of our DW, we change the background color of every alternate row to make the DW more readable (huge list) The main color is 'windows backgroud' ( = 1073741824) , and the alternate color is "a_little_bit_more_grey_than_windows_background" The thing is : to define alternate color, I need to know the RGB value of 'windows background'. At the moment, i take this value from the registries, but I cannot really trust that method as users could have a different registry setting ( you never know...). I had a problem on a test machine where the windows c...

FormView control
When a user modifies the value in a textbox in a "EditTemplate" of the Form View, I would like the font color or back color of the text box to change - even before the update is submitted. How can I do that? Thanks. You can add an onchange event to your textbox: onchange="this.style.backgroundColor='yellow';" Or use the onkeyup event as well. You may need to add the handler for this if your textbox box is being created in the client side.Please mark as "answer" if this helped you in anyway. Thanks. here is how I did it:Protected Sub FirstName...

How to make template field control color same as row background color
This is really a two part thing:  1.)  I want to make a linkbutton control in a templatefield the same color as the row color. I have alternating row colors, so I can't just hard code it. 2.) I want to make the link button change colors when the mouse goes over the ROW. Then go back to row color onmouseout.  So basically, the link will be invisible until the row is moused over.  Thanks! Here are a couple of examples.  In GridView1, the HyperLink color is set to match the background color.  Note the RowStyle and AlternatingRowStyle do not override ...

Upload control / color chart control / calendar control
Does anyone know of an advanced upload control with all the bells and whistles available? The same for a color chart and calendar control. Thank you, Steve About a chart control you can try one I wrote: WebChart Control It is free. Chart FX for .NET is the most advanced charting control for ASP.NET. You can check it out at www.softwarefx.com --- IG Software FX Yep. But Dundas isn't shabby either. DonDon Kiely, MCP, MCSDIn the Last Frontier, Interior AlaskaPlease post questions and replies to the forum! And remember to MARK AS ANSWER when someone defi...

32Bit Color / 16Bit Color
Our applications uses graphs. We recently found that if the client system was set to True Color(32Bit)all graphs display without color but with various types of lines. Change the client to High Color(16 Bit) and all is well! Is there any solution other than switching the individual system to utilize 16bit color? Any help appreciated! Thanks! -- http://www.genesis-software.com jdouglas@genesis-software.com We found this too, the answer from PowerSoft was 'No'! Jim Douglas wrote in message <6ia2ss$agq@bgtnsc03.worldnet.att.net>... >Our applica...

color email does not print in color
The user is saying a color email won't print in color anyone know how to get this to work? thanks Ralph wrote: > The user is saying a color email won't print in color > > anyone know how to get this to work? > > thanks > Printer driver dependent. Most things do not print in color correctly in GW. Laugh at user, and insult. ...

Coloring my own keywords, (Syntax Colors)
How can I get the editor to highligth keywords like WInt WULong... Jostein. ...

Celendar Colors and Category Colors
Hi, using Sunbird 0.5, I wonder how I could swap the colors used for displaying the category and calendar. This means currently I get a box filled up with the color of the calendar, surrounded by a rectangle colored in the category color. I simply would like to swap both colors since I can differentiate better e.g. if this is a birthday event or a private event. For now you have to look very closely since all events look more or less the same because of the small used border with used to display the category. Is there an option for this? Thanks! -- cu, Michael On Aug 3, ...

colors in a datalist
is there a way to color the field according to its value (linked to a database) . For example, if I have a binary field named empty with values true false, I would like the record in the datalist to be blue if record in binary field is true, black if not. You need to use ItemDataBound event. Follow this very good article http://www.asp.net/learn/data-access/tutorial-30-cs.aspxVishal 333bob:is there a way to color the field according to its value (linked to a database) . For example, if I have a binary field named empty with values true false, I would like the record in the datalist...

Color converter mixes colors up
I am trying to make the colors of certain controls databound. The colors are in a database in long format. For exampleLong: 16711680which I took with a color picker and is dark blue (#0000FF)A function which I took from the net converts the long rightly to 0000FF. However:Dim converter As New System.Drawing.ColorConverterDim hiscoloris As Drawing.Color = converter.ConvertFromString(-the long value casted to int32-)Dim htmlstring As String = System.Drawing.ColorTranslator.ToHtml(hiscoloris)Dim anothercolor As Drawing.Color = System.Drawing.Color.FromArgb(hisintis)seems to reverse the string: ...

color
Name: Jay Product: Shiretoko Summary: color Comments: nice job in getting rid of that shit brown default skin for firefox. (exaggerating) i actually won't need to install any skins anymore. (/exaggerating) Browser Details: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1b3) Gecko/20090305 Firefox/3.1b3 (.NET CLR 3.5.30729) From URL: http://hendrix.mozilla.org/ Note to readers: Hendrix gives no expectation of a response to this feedback but if you wish to provide one you must BCC (not CC) the sender for them to see it. ...

Web resources about - Color by color in DataList - asp.net.presentation-controls

Email Domain Datalist Helper
What if someone signs up for your web app and they type in their email address as susan_smith@gmaoil.com? They don't notice, they never get their ...

South-west Marine Reserves Network - Resources
[toc on_off::hide=0 on_off::automatic=0 on_off::min_limit=5 box::title=Contents box::minlevel=2 box::maxlevel=2 box::hide_show=1 box::collapsed=1 ...

HTML5无障碍支持解决方案
工作正在进行中:实例解决方案 返回 表的图例 & 说明: “不支持" - 意味着如果提供有建设性意义的变通方案仍不能被浏览器支持。 “部分支持” - 意味着建设性意义的变通方案在浏览器中提供一些无障碍支持。 “没实现” - 意味着新特性在浏览器中仍然没有实现。 “支持” - means ...

銆婄函鐪熺殑骞翠唬銆嬬1闆哶楂樻竻鍦ㄧ嚎瑙傜湅_鏂版氮澶х墖_鏂版氮缃?/title>
... 鏂扮櫧鍙戦瓟濂充紶 鏄庢湞澶╁惎鍥涘勾锛屽箍鍏冨湴鍖鸿繛骞撮ゥ鑽?.. 娓╁窞涓€瀹朵汉 銆婃俯宸炰竴瀹朵汉銆嬩互涓€鎴锋櫘閫氫汉瀹剁殑... 闃垮浣块亾浼?/a> 銆婇樋濞樹娇閬撲紶銆嬩互鏈濋矞鏃朵唬涓鸿儗鏅?.. 鐑棬瑙嗛 姝e湪鍔犺浇...璇风◢绛墌 ${++dataList_index} ...

Adactio: Journal
The thoughts and ramblings of Jeremy Keith, a web developer living in Brighton in southern England.

datalist experiment
demo implementation of datalist element

Issues for pfeldman - Code Review
Keyboard Shortcuts File u : up to issue m : publish + mail comments M : edit review message j / k : jump to file after / before current file ...

Google’s new Chrome Beta 24 is 26% faster than last year’s browser
... the Octane Javascript benchmark. For developers, there are tons of new features in Chrome Beta 24 including new un-prefixed APIs, MathML, datalist ...

Accessible Mozilla: Firefox 24
Alex's blog Wednesday, July 10, 2013 Here's a list of Firefox 24 (currently Aurora ) improvements for assistive technology. ARIA We supported ...

Google Chrome 24 Released, Claims 26% Speed Improvement
Google today released a new version of its browser. On the Octane benchmark, this version is claimed to have 26% speed improvement over the last ...

Resources last updated: 1/22/2016 10:15:58 PM