Add Ability To Provide List Items To Composite Control With DropDownLIst?
May 7, 2010
I'm creating a composite control for a DropDownList (that also includes a Label). The idea being that I can use my control like a dropdown list, but also have it toss a Label onto the page in front of the DDL.
I have this working perfectly for TextBoxes, but am struggling with the DDL because of the Collection (or Datasource) component to populate the DDL.
Basically I want to be able to do something like this:
<ecc:MyDropDownList ID="AnimalType" runat="server" LabelText="this is what will be in the label">
<asp:ListItem Text="dog" Value="dog" />
<asp:ListItem Text="cat" Value="cat" />
</ecc:MyDropDownList>
The problem is, I'm not extending the DropDownList class for my control, so I can't simply work it with that magic. I need some pointers to figure out how I can turn my control (MyDropDownList), which is currently just a System.Web.UI.UserControl, into something that will accept List items within the tag and ideally, I'd like to be able to plug it into a datasource (the same functions that the regular DDL offers).
I tried with no luck just extending the regular DDL, but couldn't get the Label component to fly with it.
I need a few options on how I will allow a user to post simple text comments to my website page(s). I will require login to post comments in order to prevent spam posters.
I'm using Visual Web Developer 2010 to design my website. I'm not real familiar with it and do not know if it includes the tool I need to accomplish this task easily.
After this, the text box continues to work correctly, but the _state member does not pick up the posted back values and instead just sticks to the declared value. I've checked the raw posted values in the Request object, and the new value for the list's UniqueID is there, but _state doesn't pick it up.
I have a composite control that returns a different control depending on a property value. The works however I can't seem to set the value of a textbox or the selected item in a dropdown list. Code does not produce error. What am i missing here??
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 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?
I have a page with some bound DropDownLists (DDLs) for a Call Logging system. The Calls are categorised on three levels for example:
Call: 3069, Category 1: Incident, Category 2: Microsoft Application, Category 3: Word would be used to organise calls for problems with Microsoft Word. On testing the system, I noticed that there was no handling for opening a call if the category had been deleted - say for reorganisation/systems no longer supported whatever. So I set about trying to make the program behave in the following manner:
Check category ID exists in DDL before bindingIt doesn't: set the displayed text of the DDL to Category Name + "(Deleted)"Disable the control to prevent user changingMove on to next control Seemed simple enough, however no matter which way I try and do it I always get the messase ddl_Cat1 has a SelectedValue which is invalid because it does not exist in the list of items. What's really puzzling me is that the exception doesn't seem to be being thrown in the code behind. I've gone through line by line from Page_Init and it never throws and exception. Just when the page loads this appears.
Does anyone know of a reason as to why this wouldn't work? (I've already tried setting the selected value to an existing item, adding a new list item with the value and setting DataSource property to Nothing - in all different combinations.)
I got this error when select a row from a grid view to update
'ddl_ctegOf_Product_update' has a SelectedValue which is invalid because it does not exist in the list of items.Parameter name: value 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.ArgumentOutOfRangeException: 'ddl_ctegOf_Product_update' has a SelectedValue which is invalid because it does not exist in the list of items.Parameter name: value
Source Error: Line 265: txt_prodID_update.Text = gridTo_updateFrom.SelectedRow.Cells[1].Text; Line 266: txt_prod_name_update.Text = gridTo_updateFrom.SelectedRow.Cells[2].Text; Line 267: ddl_ctegOf_Product_update.SelectedValue = gridTo_updateFrom.SelectedRow.Cells[3].Text; Line 268: txt_cateIn_hardCopy_update.Text = gridTo_updateFrom.SelectedRow.Cells[4].Text.Replace(" ", ""); Line 269: txt_prodID_update.ReadOnly = true;
The code of update:
private void PopulateDropDownList() { string constr = ConfigurationManager.ConnectionStrings[1].ConnectionString; using (SqlConnection con = new SqlConnection(constr)) { using (SqlCommand cmd = new SqlCommand("SELECT CategoryProd_ID,Cate_Pro_Name FROM CategoryOfProduct", con)) { using (SqlDataAdapter da = new SqlDataAdapter(cmd))
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.
I'm using a text book to teach myself ASP.NET 3.5. I'm using Visual Web Developer 2008 express to create my pages. At this point in my text, the author has me drag a DropDownList control to the Web page and then tells me to go to the Properies window and look at the Items property. I don't see an Items property. I've doublechecked that I'm on my DropDownList control, but I see no Items property. Is this a bug in VWD, an error in the book, or just plain old User error?
I'd be willing to hard-code the property in the source window, but I don't know the syntax. I tried items="Vanilla, Chocolate" but nothing appears in the list when I view the screen.
I have a list of objects that have values to them. Specifically one of these values if a boolean (isAbnormal) to determine whether or not the value itself is classified by our application logic as "Abnormal" or not.
I have composed a list of a mixture of abnormal/not abnormal items. I want and need to remove items from this list that aren't clsasified as being abnormal (in programming logic, isAbnormal will be false)
I have tried several ways and can think of some dirty/ugly ways to get it, but there has to be something better:
I'm working with a custom DropDownList control in ASP.Net and there's been a request to display certain items in the list with a bold typeface (NOTE - the control inherits from CompositeDataBoundControl so it can be data bound... not DropDownListBox). The control is bound to a table and there's a column in the table named IsUsed - if this is set to true, the corresponding item in the list should be rendered bold. (It should be noted here that this will only ever be viewed in FireFox.)
My experience is all in the middle backend tiers so the presentation layer is very new to me - can someone point me in the right direction? My initial thought was that somewhere in the custom control I would have access to all the rows that are returned from the data source which I could cycle through etc but I'm not sure if that's possible... There's also RenderContents which I can override... looks interesting!
I am trying to create a list view to provide functionality similiar to the pages in this article(will end up being much simpler in my case)
[URL]
Basically I need three columns. Column 1 will be populated on page load with a list of user names and some data. Clicking on a user from column 1 will query for data regarding that user and bring back multiple rows to be displayed in Column 2. Clicking on data from a row in column 2 will return rows to be displayed in column 3. I am just curious as to how some of you guys would approach this. Ive looked at grouping templates and some articles regarding listviews with multiple rows but. Would it be easier to use 3 seperate listviews? Any ideas or articles to point me in the right direction?
I'm writing a custom ASP.NET webcontrol and would like it to have a collection of custom items which can also be specified in the XML markup. Something like this:
class MyControl: WebControl { public IList<MyItemType> MyItems { get; private set; } }
How do I do this? I though this was all about implementing some interface on the collection or adding some special attributes to the property, but nothing I do seems to work.
I am trying to included a rating control in a composite control that renders many different type of controls. I render the controls by overriding the rendercontents so that I can control the layout of the controls. When I try to add the rating control to the output i get a Page cannot be null error. Can someone provide me with the proper way to render a rating control from a composite control and be able to control the layout of the child controls.
I have question about dropdownlist control.I have a dromdownlist control which shows the list of dealers.I want to add a sub-list to each dealer which should populate the products available at that particular dealership.I don't want to select value from sub-list display.