Forms Data Controls :: Assigning Colour To List Items Based On Their Values?

Feb 9, 2010

Is it possible to assign a colour to a drop down list item based on it's value?For example: I have a drop downlist where I've got a bunch of items that have integer

values. I would like to highlight the items with values in 1000s in grey.

Here is what the list looks like:

list_item_name list_item_value
HEADING1 1000
HEADING2 1000
HEADING3 1000
item1 1
HEADING4 1000
item4 4
item5 5
HEADING5 1000
HEADING1 2000
HEADING2 2000
item2 2
item3 3
HEADING3 2000
HEADING4 2000
HEADING5 2000

I've boldified the items I'd like to be highlighted in grey ,For added complexity I need to highlight the items with values 1000 in a light shade of gray and items with values 2000 in a darker shade of grey. I'm using Web Developer, and C#

View 4 Replies


Similar Messages:

Forms Data Controls :: Listview: How To Get The Background Colour Changed Based On A Boolean Value In A Table

Sep 17, 2010

I come across the technique on how to apply a different CSS class to make a row stand out from the others. However, the original code is for gridview whilst I am trying to get it works on a listview. The original code for the gridview is as follows and how to get it done on listview.

-----------------------------------------------------------------------

[Code]....

View 5 Replies

Forms Data Controls :: How To Change The Colour Of Particular Row In Data Grid View Based On Drop Down Selection

Dec 15, 2010

How to change the colour of particular row in data Grid view based on drop down selection.

View 9 Replies

Forms Data Controls :: Dynamic Gridview With Dropdownlist / Dynamically Set The List Values Based On Parameters (of The Row They Are On)

May 28, 2010

I'm new to web dev and c# so please bare with me. I am trying to create a dynamic gridview in a web form for users to to answer questions with (code below).

The dificulty im having is that i am nesting a dropdwonlist in the gridview and want to be able to dynamically set the list values based on parameters (of the row they are on). These values are in the main dataset for the gridview as each row represents a questionid and question text and then a ddl for the criteria...

I just don't know how to set the values for the dropdown all the code so far is below... just need to be able to populate the dropdowns with the relevant values.

I have created a stored proc to return the different criteria based on the questionid and questionGroupid which is the dataset that populates the other fields in the gridview: dbo.usp_QuestionCriteria @QuestionGroupId, @QuestionId

I have added this as a tableadapter called criteriaTableAdapter in a xsd file as well using the wizard... not sure if this is the right option though or just use the same method as i have for the other stored procedure as in the code below:

[CODE

]using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Sql"].ConnectionString);
con.Open();
SqlCommand com = new SqlCommand("usp_QuestionGroupDS", con);
com.CommandType = CommandType.StoredProcedure;
SqlDataAdapter ada = new SqlDataAdapter(com);
DataSet ds = new DataSet();
ada.Fill(ds);
for (int i = 0; i < ds.Tables.Count; i++)
{
if (ds.Tables[i].Rows.Count > 0)
{
GridView gvDynamicQuestion = new GridView();
gvDynamicQuestion.Width = Unit.Pixel(700);
gvDynamicQuestion.BorderWidth = Unit.Pixel(0);
gvDynamicQuestion.Caption = "<div id="nifty" class="QuestionGroup"> <b class="rtop"><b class="r1"></b><b class="r2"></b><b class="r3"></b><b class="r4"></b></b>" + ds.Tables[i].Rows[0]["Category"].ToString() + " Questions<b class="rbottom"><b
class="r4"></b><b class="r3"></b><b class="r2"></b><b class="r1"></b></b></div>";
gvDynamicQuestion.AutoGenerateColumns = false;
gvDynamicQuestion.ShowFooter = true;
TemplateField tf = null;
tf = new TemplateField();
tf.HeaderTemplate = new DynamicGridViewTextTemplate("QuestionId", DataControlRowType.Header);
tf.ItemTemplate = new DynamicGridViewTextTemplate("QuestionId", DataControlRowType.DataRow);
tf.FooterTemplate = new DynamicGridViewTextTemplate(DataControlRowType.Footer, ds.Tables[i].Rows.Count);
gvDynamicQuestion.Columns.Add(tf);
tf = new TemplateField();
tf.HeaderTemplate = new DynamicGridViewTextTemplate("Question", DataControlRowType.Header);
tf.ItemTemplate = new DynamicGridViewTextTemplate("Question", DataControlRowType.DataRow);
gvDynamicQuestion.Columns.Add(tf);
tf = new TemplateField();
tf.HeaderText = "Criteria";
tf.HeaderTemplate = new DynamicGridViewTextTemplate("Criteria", DataControlRowType.Header);
tf.ItemTemplate = new DynamicGridViewDDLTemplate();
gvDynamicQuestion.Columns.Add(tf);
////tf = new TemplateField();
////tf.HeaderText = "Criteria";
////tf.ItemTemplate = new DynamicGridViewDDLTemplate();
////gvDynamicQuestion.Columns.Add(tf);
gvDynamicQuestion.DataSource = ds.Tables[i];
gvDynamicQuestion.DataBind();
phDynamicGridHolder.Controls.Add(gvDynamicQuestion);
}
}
}
protected void DynamicGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Footer)
{
//
}
}
}
public class DynamicGridViewTextTemplate : ITemplate
{
string _ColName;
DataControlRowType _rowType;
int _Count;
public DynamicGridViewTextTemplate(string ColName, DataControlRowType RowType)
{
_ColName = ColName;
_rowType = RowType;
}
public DynamicGridViewTextTemplate(DataControlRowType RowType, int QuestionCount)
{
_rowType = RowType;
_Count = QuestionCount;
}
public void InstantiateIn(System.Web.UI.Control container)
{
switch (_rowType)
{
case DataControlRowType.Header:
Literal lc = new Literal();
lc.Text = "<b>" + _ColName + "</b>";
container.Controls.Add(lc);
break;
case DataControlRowType.DataRow:
Label lbl = new Label();
lbl.DataBinding += new EventHandler(this.lbl_DataBind);
container.Controls.Add(lbl);
break;
case DataControlRowType.Footer:
Literal flc = new Literal();
flc.Text = "<b>Total No of Questions:" + _Count + "</b>";
container.Controls.Add(flc);
break;
default:
break;
}
}
private void lbl_DataBind(Object sender, EventArgs e)
{
Label lbl = (Label)sender;
GridViewRow row = (GridViewRow)lbl.NamingContainer;
lbl.Text =DataBinder.Eval(row.DataItem, _ColName).ToString();
}
}
public class DynamicGridViewDDLTemplate : ITemplate
{
// Implementation of ITemplate
public void InstantiateIn(System.Web.UI.Control container)
{
// Create a DDL
DropDownList ddl = new DropDownList();
//Attach method to delegate
ddl.DataBinding += new System.EventHandler(this.ddl_DataBind);
container.Controls.Add(ddl);
}
//Method that responds to the DataBinding event
private void ddl_DataBind(object sender, System.EventArgs e)
{
//DropDownList ddl = (DropDownList)sender;
//DataGridItem container = (DataGridItem)ddl.NamingContainer;
//ddl.Data.Checked = [Data binding expression];
}
}

[/CODE]

View 7 Replies

Forms Data Controls :: Assigning Values From A Database To A Label?

Sep 30, 2010

I want to select all the values from a table in my database and then put each value in order into labels that are on the asp page.

I can Select all the values from that database fine but I am rather stuck as how to put the values into the individual labels? Here is the code I have connecting to my database.

[Code]....

How can I put the DateTime value into Label1 and the Decription into Label2??

I have had a nose about but can't seem to find the information I need.

View 5 Replies

User Controls :: Enable Disable DropDownList Items Based On Database Values

Mar 20, 2014

May i know how to create the control function in asp.net  to control the values ?

Based on the DB table, it active is Y then enable values  in dropdownlist , if N then disable the values. 

View 1 Replies

Web Forms :: Picking Random Items From A List Based On Percentages

Jun 10, 2010

I am trying to make a way so that I can have a group with items in it, each one of the items (which is an object in a list) having a double type value, the total of all the items in the group is 100 when you add up all their properties. The purpose of this is that there can be random selection of the items.

for example:

item 1 percent property: 25.0
item 2 percent property: 25.0
item 3 percent property: 25.0
item 4 percent property: 25.0

When a request comes in, I need to be able to pick 1 of these items at the rate of 25% so that after a while (more and more requests) that each of these gets very close to 25%. I have tried looking at random numbers but pulling a number back seems useless in this case because for example if a random number retrieved was the number 5.4, how would I send it to an item? I cannot keep a history of the item requests so that I can factor that in. I need to be able to pick a random number and over time have each of these 4 items be selected an equal amount of times, the percentages and amount of items is going to change constantly but the sum of all the percent properties within a group is 100%. What is the best way to accomplish this in C# with a web form?

View 2 Replies

Forms Data Controls :: Bind Checkbox List To Selected Items List?

May 27, 2010

I have a situation where I want to show the selected records out of total records for a product of an employee

1) There is a checkbox list bind to <List> of objects from object datasource (For total items in list)

2) Now I want to check the selected items for a particular record in this list

3) For this purpose I have another list of <List> selected items returned by data access layer (For selected items for that employee )

4) How do I bind the selected objects with the total items list ?

5) In spaghetti coding model it was all too easy just by binding the checkbox list with a sql data source and running a for each on form load

View 5 Replies

Web Forms :: Dropdown To Exclude Or Disable List Items Based On Listbox Selections?

Mar 12, 2010

I have a drop down that lists all our 40+ locations.. I then have a list box with all our locations as well. The client is presented with the question which locations have you worked at before. If they pick say 3 locations, i need to remove or disable those 3 from the drop down. I have other code for creating a drop down, but not sure where to go with this.

Here is my code for the controls and code behind:

[Code]....

View 17 Replies

Web Forms :: How To Get List Of VALUES (not Items) From A Dropdownlist

Oct 11, 2010

I see that dropdownlist has an "items" property to get the list of displayed items for a dropdown, but it doesn't seem to have an equivalent property for getting the "values" associated with the items. For example, I may have a dropdown that displays "High", "Medium" and "Low", but returns values of "H", "M", "L". How can I easily get that list of HML?

View 5 Replies

Select Values From A List, Where The Items Contain In A Different List Aswell?

Feb 5, 2010

Is it possible to select values from a List, where the items contain in a different list aswell?for example;

[Code]....

What I need are all the items from the first list "Items", where the string contains something from the second list "List".So I need something which returns the first 3 items (which contain the term "Item") from the first list.

View 3 Replies

C# - Dispay Specific Items In Dropdown List Based On Condition?

Sep 21, 2010

I have a dropdown list with four options like:

New Reviewed

To be Reviewed Presented

I need to display only specific items in the dropdown list based on some conditions.I mean sometimes with only 2 items

New Review Sometimes with 3 items

New Review To be Reviewed and sometimes all items.How can I do this? I am using C#.

View 2 Replies

Forms Data Controls :: Display Menu Items Based On Role?

Jul 13, 2010

I hv created menu using sitemap xmldatasource now i want to display that based on Category or Roles. I have Created 4 Category in my sql Server 2005. when particular user logged in based on his Category menu nodes should display.

View 7 Replies

Set The Colour Of The Columns Based On Criteria?

Mar 8, 2010

Duplicated post

View 1 Replies

Forms Data Controls :: How To Populate List With New Items

Feb 28, 2011

I have al list that I would like to populate with new items from a textbox. But when I add a new Item it overwrites the old list with te "new" list. I declared the list outside the method so I don't know what the problem is.

here is my code:

ASPX file

[Code]....

ASPX.CS file

[Code]....

View 2 Replies

Forms Data Controls :: How To Combine Some List Items Together

Jan 8, 2011

just want to have a quick question about the value of dropdownlist listitem. I have a gridview which has its datakey value linked to a dropdownlist. In the dropdownlist I have many listitems. So I decided to combine some list items together. Originally, the values of the items are 1,2,3,4,5,6,7,8. But I want to have only 5 items by combining 5,6,7,8 into one listitem called "Others." So if the listitem "Others" is selected, the gridview will show all the records that have value 5 or 6 or 7 or 8. Is it possible? How can that be done?

I hope I made myself clear. Any question, I am happy to clarify.

View 4 Replies

Forms Data Controls :: How To Retrieve Items In An Anonymous List

Apr 13, 2010

i did not know how to phrase the question above but this is what I want to achieve;

using a linq to sql datacontext db, I want to retrieve a sequence of items with the code below [Code]....

View 3 Replies

Forms Data Controls :: Data Source And Items Of A Repeater From An Enumerable List?

May 22, 2010

I have got the following code:

[Code]....

This should give me the friends of the user currently logged in in the Repeater, but gives me an exception on the runtime that an instance needs to be initialized, can you please suggest a solution...

Also, what should be the value of the NavigateUrl property of a Hyperlink in an ItemTemplate if the url is:

"http://domain.com/viewprofile.aspx?id=" + 'THE UserID property of the current element in the list'

View 3 Replies

DataSource Controls :: Assigning Values To SelectParameters In Code?

May 6, 2010

I want to define SelectParameters for my SqlDataSource in markup and then assign values in code, but when I use the syntax:

[Code]....

It works the first time, but won't let me re-add the parameters on subsequent postbacks.

I can't use ControlParameters in this case because the values in the controls are loaded from xml files and some minor parsing needs to be done to the values before they're passed to the database.

View 2 Replies

Forms Data Controls :: Order Of The Items In A DropDown List Inside GridView

Sep 22, 2010

I have a DropDownList inside the EditTemplateItem (if the user clicks edit) in a GridView.The DropDownList receives all available rows from the database. My problem is,if the user clicks Edit in the GridView to edit a row and opens the DropDownList Box the original item is not selected but the first one.That means the items are sorted. Have someone an idea how I can solve this issue that the right item / the original is selected if I change to edit mode of the grid view?

View 2 Replies

C# - How To Change Colour When Refreshing And Turns Again To Original Colour Within 2 - 4 Seconds

Jun 9, 2010

For eg..in Stackoverflow site, after giving answer, if we are refreshing the page, it displays the answer with orange color and turns to white beautifully?

How we have to do this ? Can it is possible in asp.net - C# ?

View 1 Replies

Forms Data Controls :: Strategies For Removing Empty List Items From A Listview Upon Render?

Sep 29, 2010

using asp.net 4 and vs 2010 I have a listview that displays data from a database. I have to configure it to display all column data where present, however, not all columns have data, with the result that blank spaces get rendered where this data would normally be displayed.

The code:

[Code]....

So, for example, some of the individuals that exist in this table might no longer be associated with a specific department, institution or have data in the "Address2" column.

View 4 Replies

Forms Data Controls :: Letting User Update Database Using Dropdown List Items?

May 26, 2010

On my website, registered users can make a profile about themselves suchas name, Favoirite color, hobbies, etcI have a DataTable called User which hold this information.also there are other datatables for Hobbies and Colors which list all possible options.To let the user update their choices I have a FormView in Edit mode on the aspx page whichis binded to the UserTable with a GetProfileByUserId Method and objectdatasource.

Within the formview, i have added drop down lists that are binded to the hobbies and Colors tables so they can edit their previous selection.On clicking Uodate update formview calls an Update Method that adds new selections to the User databaseNow I have two questionsIs it possible to show in the dropdown list the selected value that the User has already made?If the user only changes hobbies and not colors when they click update will a null value be passed into the data table for colors that replaces their previous selection?

View 1 Replies

Data Controls :: Filter GridView Data Based On CheckBoxList Checked Items

Aug 31, 2012

I want bind  and filter gridview data with  values selected in checbox list ..

i am bind checkboxlist on pageload ....but able to filter the result the of gridview with value of checkbox list ..

when i check box  nothing happen

This my code

 <div>
<asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="True" DataValueField="cartid" DataTextField="sub"
onselectedindexchanged="CheckBoxList1_SelectedIndexChanged" >
</asp:CheckBoxList>

[Code] ....

View 1 Replies

Forms Data Controls :: Set Default Values Of Items In A Datalist In Code Behind On Page Load?

Apr 14, 2010

I've got a few labels in a datalist that are being populated based on the values of a queryString but without the query string the datalist is empty.

How can I access the labels in the datalist and set a default value to them on the load of the page?

View 14 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved