C# - How To Format Individual DropDownlist Items (color, Etc.) During OnDataBinding Event

Apr 9, 2010

I have a basic DropDownList bound to a ObjectDataSource:

<asp:DropDownList ID="DropDownList1" runat="server"
AutoPostBack="True" DataSourceID="objDataSource1"
DataTextField="FieldName" DataValueField="FieldID" />

The DataTable from which it receives the DataTextField and DataValueField values also returns some other interesting information about the records. Say Active = Y/N for simplicity's sake.

What I'd like to do is to set the background-color property of the DropDownList Item based on that Active field in the DataSource results. Further, I'd like to do this "in the same pass" as when the DropDownList is bound to the data. So my guess is that it has to happen during OnDataBound.

I could go back and loop through the DropDownList items later. But it would involve embedding loops and re-visiting the DataTable rows and it just seems inefficient

int row;
for (row = 0; row < DropDownList1.Items.Count - 1; row++)
{
[[if this row = that data row]]
DropDownList1.Items[row].[[DoStuffHere, etc.]]
}

View 2 Replies


Similar Messages:

Databinding - OnDataBinding Event For EditItemTemplate DropDownList?

Mar 2, 2010

I have a dropdownlist control in an edititemtemplate for a details view defined like this:

<asp:TemplateField HeaderText="Primary Use">
<EditItemTemplate>
<asp:DropDownList ID="ddlPrimaryUseEdit" runat="server" OnDataBinding="DropDownList_DataBinding"

[code]...

I have a datasource definded as a query to my database that has a column named "PrimaryUse". Sometimes there can be a value in the PrimaryUse column that isn't listed as one of the dropdownlist items and so my application crashes when trying to bind the dropdownlist's selectedvalue to that field. I'm trying to create code in the edititemtemplate's OnDataBinding event that will check if the value being returned from the datasource is a valid value listed as an item in the dropdownlist options. My problem is that I'm not sure how to get the datasources fieldvalue for that column in the behind code. Is this possible? Is so, can some one give me an example or point me in the direction on how to do this?So, in the OnDataBinding event for the edititemtemplate listed above, I would like to do the something like the following (psuedo code):

if datasource.datafieldvalue("PrimaryUse") is in dropdownlist.Items then Valid
else set dropdownlist.Selectedvalue = "Default"

View 2 Replies

Dropdownlist With Certain Items In A Different Color?

Mar 22, 2010

I have a drop down list as follows:

[Code]....

[Code]....

View 1 Replies

Web Forms :: How To Apply Color To Selected Number Of Items In Checkbox List And Dropdownlist

Sep 9, 2010

i want to apply color to selected number of items in checkbox list and seleted number of items in drop downlist for e.g color red for few items and black (default). I have a bit value set in data base so if bit is set to 0 then red and if 1 then back.

View 5 Replies

Web Forms :: How To Add Color For Individual Events In Day Pilot Lite Calendar

Jan 14, 2010

If anyone is using the Day Pilot Lite Calendar, Is there a way we can add the color for individual events

I founf this link, but it

[URL]

View 1 Replies

.NET Grabbing Individual Items For Stored Procedure?

Jan 18, 2011

DataTable siteParams = new DataTable();
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlCommand cmd = new SqlCommand("siteParametersGetAll", con))
using (SqlDataAdapter da = new SqlDataAdapter(cmd))

Now, I want to be able to grab certain rows without using 0,1,2,3

View 1 Replies

Page Throws ViewState Error When Items Collection Of Dropdownlist Is Modified In IndexChanged Event

Feb 25, 2011

I have an ASCX control which is a special dropdownlist. I add that control dynamically to the page and fill it with data. This control has a postback that will change the contents of a second dynamically created standard dropdownlist.

When I change the selection on the first dropdown, the indexchanged fires and I get new data and attempt to place it in the second dropdownlist's items collection, by first clearing it then filling it with new data.

This works fine the first time a change the selection, but when I select a second time the following error is thrown:

The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request.

I'm not adding or removing new controls in the fired event, only changing data. And again, it works the first time, but doesn't subsequent times.

If I disable stateview on the child control, then the control just doesn't get updated with data at all.

View 1 Replies

Forms Data Controls :: Changing The Color Of An Individual Data Point In A Columns Chart

Feb 7, 2011

In my web forms application I have a site.master page with an update panel (Java Script ToolKit). Inside the update panel I have a survey and a columns chart to show its results. The chart properties are

visible = false
ImageStorageMode = UseImageLocation
RenderType = ImageTag

When the user votes, his/her vote is stored in a sql server table The chart is rebound to its data source
The chart visibility is set to true and the survey's questions are hidden. I've been trying to set the columns for the maximum and minimum values to a different color using the code I found in "Samples Environment for Microsoft Chart Controls" [URL] under Working with Chart Data Data Manipulation Finding Data Points Find Maximum and Minimum Values:

[Code]....

I have not got the columns to change their color. I have put the code inside every event handler I could think of (after it failed to work inside the page load event handler): Inside the chart Init, load, and pre_render handlers. Inside the click event handler for the voting button (before and after I call the chart.DataBind() method). Inside the page pre_render handler. Inside the ToolKitScriptManager pre_render handler. I checked the code behind the environment samples. All, to no avail.

View 2 Replies

C# - Click Event For A Individual Cells In Gridview?

Mar 31, 2011

i am working on asp.net3.5 c#,i want make the click event for a cell in grid view, actually i'm using data table and assign this to grid view,i want click event for a cell .is it possible?

View 2 Replies

Web Forms :: Accessing Data On Ondatabinding?

Nov 8, 2010

I have a dynamically created dropdownlist I'm databinding. Everything seems fine until I trigger the ondatabinging to change the text of the item bound. How can I access the source data from here?

View 2 Replies

Web Forms :: How To Change Linkbutton Selected Items Color

Apr 27, 2016

I use datalist and linkbutton in page that bind from database below is code:

<asp:DataList ID="DLclass" runat="server" Visible="false">
<ItemTemplate>
<asp:LinkButton ID="Linkbtnclass" runat="server" CssClass="lbldasteM"
CommandArgument='<%# Eval("Name") %>' OnClick="Linkbtnclass_Click"><%# Eval("Name") %></asp:LinkButton>

[Code] ....

And behind code:

protected void Linkbtnclass_Click(object sender, EventArgs e)
{
rptPager.Visible= Lblcontinue.Visible = !(rptPager2.Visible = DLMostanad.Visible=true);
(sender as LinkButton).ForeColor = System.Drawing.ColorTranslator.FromHtml("#fb00c2");
this.GetCustomersPageWiseMC(1, (sender as LinkButton).CommandArgument);
BindDataListD(DLclassC, "classTI_documentry");
}

in above code in this line:

(sender as LinkButton).ForeColor = System.Drawing.ColorTranslator.FromHtml("#fb00c2");

I define that when I select Item from datalist( linkbutton) that bind from database color of text will be change below is image:

I show it with red arrow now here when I select other linkbutton (i.e text under last text) it dosen't change last selected text to defualt color:

as you see in above image second selected text show with green arrow

I want when I select second text(link button) it changes first selected text to default color...

View 1 Replies

Web Forms :: Display All Items In Child DropDownList When ALL Is Selected In Parent DropDownList

Sep 6, 2012

protected void DDLzone1_SelectedIndexChanged(object sender, EventArgs e)
{
BindDistrict();
}

[Code]......

here when i click on ALL item from ddlzone1  it just "ALL" item in ddldistrict

i want when i select "ALL" item from ddlzone1 in ddldistrict14 show all data from database

View 1 Replies

Web Forms :: Changing The Selection Color(blue) For The Items In The List Item?

Mar 3, 2011

Is there a way that we can change the color (which is defaulted to blue) when the items in the list box are selected? If so can you provide me a sample for it?

View 1 Replies

Data Controls :: Highlight Searched Text In Color In DataList Items

May 15, 2013

I have 1 Datalist and BTNsearch in my page below is SP

ALTER procedure [dbo].[AdminSearchP]
AS
BEGIN
SELECT * FROM House_p WHERE ID IN( SELECT DISTINCT houseP.ID FROM House_p houseP,SearchTerm WHERE [Description] LIKE '%' + SearchTerm.Name + '%')
END

this SP show in dataList  data that contain some words that I define in SerachTerm table

refer

Select-records-from-one-Table-and-Search-in-other-table-in-SQL-Server/

Now I want when I click on button and it show data in datalist it highlight the words in datalist that I define in SearchTerm Table i.e in serchTerm table i define below words

Paris-India-Itally-Germany

when I click on button it search in House_p table in Description Column and if in this column be above words show it in datalist

Like below

Name
Description
Sara
She is from India

Now I want when show data in datalist it bold or Highlight the words that I define in SearchTerm table Like below

Name
Description
Sara
She is from India
How I can do it? 

View 1 Replies

Forms Data Controls :: Highlight Color On Duplicate Items In Listview In Vb2005

May 27, 2010

Highlight color on duplicate items in listview in vb2005

View 1 Replies

Web Forms :: How To Get Font Color Name From Dropdownlist

Aug 25, 2010

I have add some item in dropdownlist and add attribute to that items.Then how i reterive that font color name in label or string.

I have paste some code snippest.

[Code]....

I want reterive font color name when click on button .

View 5 Replies

Dropdownlist - Dropdown Menu Item Color

Aug 10, 2010

I have a DropDownList on an ASP.NET page that gets populated by a SQL database.

<asp:DropDownList ID="ddlName" runat="server"></asp:DropDownList>

The population is down in the code behind file:

ddlName.DataSource = SqlDataSource1;
ddlName.DataValueField = (this.ddlName.SelectedValue);
ddlName.DataTextField = "ccName";
ddlName.DataBind();

I was wondering if it was possible to change the background or text color of an item in the list based on it's value? I just noticed that the example below works when the page first loads but on postback the text color disappears even though that is where the code is. Is there something I am missing?

protected override void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ddlName.DataSource = SqlDataSource5;
ddlName.DataValueField = (this.ddlName.SelectedValue);
ddlName.DataTextField = "ccName";
ddlName.DataBind();
foreach (ListItem item in ddlName.Items)
{
if (item.Value == "Item 1")
{
item.Attributes.Add("style", "color:red");
}
if (item.Value == "Item 2")
{
item.Attributes.Add("style", "color:red");
}
}
}
}

View 1 Replies

Web Forms :: Change Color Of DropDownList Selected Item

Dec 6, 2013

I use DropDownList in my page.I want when I select Item from DDL it changed selected Item's color that show in DDL..How I can do it?

View 1 Replies

VS 2008 Is It Possible To Change The Color Of A Row During The RowEditing Event

Jun 17, 2010

Is it possible to change the color of a row during the RowEditing event? I'd like to have the color change when a user clicks the EDIT link

View 2 Replies

Forms Data Controls :: How To Send The Cart Items As Email In Pdf Format

Sep 29, 2010

I am working on Shopping Cart its almost done. But i need small help from you guys.In my application final Step when customer try to CheckOut the products cart should be email with attachment as a PDF.

This application developed using vb.net.

I have completed till the checkout page. After that i am not geting any Idea how to send the cart Items to email as a PDF.

I tried to convert the webpage, repeater control to pdf but no luck...I can't spend money on thirdpaty tools.

Even i tried free One itextsharp but i could not get it..

check out page has the following

1.products on a repeater control and some labels.and other server controls.

2.Images company Logo

Can any one tell me how to send the cart items as email in pdf format.

Is there any other best way to send sales Quotation to customers on products.

View 3 Replies

Data Controls :: Change Color Of DropDownList Based On Values

Apr 27, 2016

How can change the color of dropdownlist with based on their Text 

If  dropdownlist have  listitem Santosh  and Arati if santosh color is  red if Arati color is blue when page is loading

View 1 Replies

Web Forms :: Change Color Of Previous Selected Item In DropDownList

Dec 10, 2013

URL...I mean when page is loading it show default Item in DDL in red color and show other Item in black color but when  I selected  another Item from DDL it changed all Items color to red.I want when I changed DDL's Item like before it show selected Item in red color and other items in black color.

View 1 Replies

Forms Data Controls :: Change Particular Row Color / CSS On RowDataBound Event Using C#

Jan 15, 2011

i have a gird and i want to change particular row color when i found such particular row on row data bound ..

for example when i found a text from "lblRowId" than how can i change current row color or css[Code]..

View 6 Replies

Forms Data Controls :: Click Event For Color Change?

Aug 7, 2010

i am doing one grid view concept.if you update one column in grid view.you click after change color for during update column.

example:if you open your email and click to open unread mail.or select particular mail to open mail color will changeing.are you see that i need same concept in my grid view.

View 2 Replies

Data Controls :: Preserve (Retain) Background Color Of DropDownList Item On PostBack

May 7, 2015

I have a dropdown populated with data , based on a true / false condition i change the dropdown item color when dropdown gets loaded initially the item color are proper based on condition. but if i select a particular item & then again click on dropdown the item color disappear show to retain the item color.

View 1 Replies







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