Dropdownlist With Certain Items In A Different Color?
Mar 22, 2010I have a drop down list as follows:
[Code]....
[Code]....
I have a drop down list as follows:
[Code]....
[Code]....
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.]]
}
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 RepliesI 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...
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
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 RepliesI 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?
Highlight color on duplicate items in listview in vb2005
View 1 RepliesI 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 .
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");
}
}
}
}
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 RepliesHow 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
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 RepliesI 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 Replieshow i handle this problem..Its in hidden filed.
Server Error in '/DentalClaimPrjt' Application.
Cannot have multiple items selected in a DropDownList.
Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: Cannot have multiple items selected in a DropDownList.
Source Error: [Code]....
Line 85: function openPopup2(did)
Line 86: {
Line 87: var hdnClm1 = document.getElementById('<%=hdnCliamid.ClientID%>').value;
Line 88: window.location="Form.aspx?DeleteRSPid=" + did + "&Editid="+ hdnClm1;
Line 89: }
Source File: d:DentalClaimPrjtForm.aspx Line: 87 Stack Trace: [Code]....
[HttpException (0x80004005): Cannot have multiple items selected in a DropDownList.]
System.Web.UI.WebControls.DropDownList.VerifyMultiSelect() +106
System.Web.UI.WebControls.ListControl.RenderContents(HtmlTextWriter writer) +124
I'm designing a web page with two dropdownlists, one for the Make of a car, the other for the Model, both bound to a database with separate SQLDataSources, and using a distinct statement. I add "All" at the top of both by setting appendDataBoundItems = true and adding items named all. Then when I fill the Make with a querystring all the model items get added twice (but only the databound items).Here's my code:
<asp:DropDownList ID="DropDownMake" runat="server"
DataSourceID="SqlMakes" DataTextField="Make" DataValueField="Make"
AppendDataBoundItems="True" EnableViewState="False" AutoPostBack="True">
<asp:ListItem Selected="True" Value="All">All</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DropDownModel" runat="server"
AppendDataBoundItems="True" AutoPostBack="True" DataSourceID="SqlModels"
DataTextField="Model" DataValueField="Model" EnableViewState="False">
<asp:ListItem>All</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlMakes" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT DISTINCT [Make] FROM [Parts]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlModels" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT DISTINCT [Model] FROM [Parts] WHERE ([Make] = @Make)">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownMake" Name="Make"
PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
'And in the VB file:
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
DropDownMake.SelectedValue = Request.QueryString("Make")
DropDownModel.SelectedValue = Request.QueryString("Model")
End Sub
If I remove the line "DropDownMake.SelectedValue = Request.QueryString("Make")" it doesnt produce duplicates anymore. What is going on?? I swear I've spent more time developing entire iphone app.
I have a dropdownlist that contains items from a database. The set of items are unlikely to ever change. At the moment, whenever a user tries to access the View with the dropdownlist, the code retrieves the data each time from the DB. I would like to change this so that the set of items are cached and load on the application start only.
Could somebody indicate the best mechanism for this scenario? I have read up on Enterprise library which is my current preference, though any alternatives (with reasons) would be welcome.
How can I copy items hardcoded from one dropdown box to another keeping the keys and values?
drpTypes.Items.Add(new ListItem("Tipos de Acções", "1"));
drpTypes.Items.Add(new ListItem("Tipos de Combustível", "2"));
drpTypes.Items.Add(new ListItem("Tipos de Condutor", "3"));
drpTypesCreateEdit.Items.AddRange(drpTypes.Items);
I have a grid with 5 rows and 5 columns, All containing templetefield(Combobox)I am trying to set the background color of my grid cell(contain combobox) depending upon which item is selected. (again, dependent on item selection, so background color is not permanent). How can i achieve this?
View 1 RepliesI have a dropdownlist in a formview that looks like this:
<asp:DropDownList ID="DropDownList5" runat="server" AppendDataBoundItems="True"
DataSourceID="SqlDataSource6" DataTextField="StaffName"
DataValueField="StaffName" SelectedValue='<%# Bind("LetterName") %>'
Width="155px">
<asp:ListItem Value=""> </asp:ListItem>
</asp:DropDownList>
I am trying to add the value from a textbox which is also in the formview into the dropdownlist as a list item. I currently have this code for it:
Protected Sub Formview1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.PreRender
Dim dropdown As DropDownList
Dim listvalue As TextBox
dropdown = FormView1.FindControl("dropdownlist5")
listvalue = FormView1.FindControl("textbox1")
dropdown.Items.Add(New ListItem(listvalue.Text, listvalue.Text))
End Sub
This code works and adds the new item to the dropdownlist if I have no SelectedValue set for my dropdownlist. However when I set the selectedValue I get the error message:
"'DropDownList5' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value"
This is the bit I dont understand because the value does now exist in the list of items as it was added in from the textbox value. Does it try to do the selectedValue before adding my list item? If so how can I add the list item first, or do I need to set the selectedValue in the code after adding the list item?
i have a database table with lot of records > 17000what is the most efficient way to let user to choose between one of the records- 1 dropdownlist with all the 17000 record ?- 1 textbox with autocomplete and a webservice that return the list of the records ?
View 3 RepliesI have a dropdownlist with items. dropdownlist got it from a List<string> object.
Now i want to set a hyphen for all the items. so i looks like this:
- a
- b
- c
Does anyone know a way to do this?
On the home page as I on work, I have a dropdown list which act as a menu. But in Internet Explorer can not figure out how to display all text in my dropdown list How it looks in Internet Explorer
How it looks in firefox, chrome and opera Do you know how to do so that Internet Explorer also displays all the text in my dropdown list like in firefox and the other
I have a cascading dropdown list on my page. The first dropdown contains a list of events. The second dropdown contains a list of attendees. When an event is selected, an AJAX call is made to get the list of attendees for that event, and populate the second dropdown.
My problem is that for the attendees dropdown, I want the user to be redirected to a URL on the SelectedIndexChanged event, with the selected value in the query string. But on the SelectedIndexChanged event, all the items in the second dropdown are reset. Here's my code:
<script type="text/javascript" language="javascript">
$(document).ready(function()
{
$('#<%= ddlEvents.ClientID %>').change(function()
{
$.ajax({
[Code]....
When the SelectedIndexChanged event is hit, ddlAttendees is empty.
Does anyone know how I can keep the items in ddlAttendees?
Using MVC2, I want to know how you add the options of a dropdownlist from a database. I have several lookup lists so I will need to do this many times. I'm stuck on part 5 of the MusicStore (which is using MVC3) at this part
[Code]....
Alternatively if someone could recommend an MVC2 tutorial which covers drop lists.