I am using asp.net 3.5 c#.If i want the application (user) to pick multiple things from a dropdownlist, view them and then insert into database.. how can i do that?Is it possible to make it so that once he picks something from the dropdownlist it is added to a list (or a table) ,, so he can check them before inserting to DB??
I seem to be having some challenges with the data I am retriveing from a Webpage using the Webclient class. The code works fine, however I observe that the regular expression is not picking up the negative or positive sign in the Daily_Movement data. For example, a daily movement can be -0.31 or +0.31 but the code is not picking the sign in front of the decimal values.Here is my code
[Code]....
I think where the problem lies is the part of the code Regex r1 = new Regex("<span class="quoteData">.*</span>"); It picks up the values between the tag quite well, but not the signs in front of it. [Code]....
I have more than 50 counties in DropDownList. Instead of entering all the 50 counties into DropDownList, Is there any other way, that give best results.?
I've got a class that implements IListSource and returns a generic List of ListItem objects (List<ListItem>). in this list one of the ListItems has the Selected attribute set to true.On the web page I have a standard asp:dropdownlist and I set it's datasource to the getList method of my class and databind it.The problem is that the databind seems to loose the selected Item and the first item in the generic list becomes selected.
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 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.
In my project requirement user wants to enter a manual entry if they can not find an item in the drop down list.
Right now what I am doing is:
I set the dropdown list autopost back true and on selectedchanged event I am hiding the drop down list and showing a text box to enter a manual entry...
This is working perfect and no problems..
but the drop down list needs to change to a text box on only selecting a "unknown" option in the list...all other list items are doing unnecessary post back to the server with no use...
I have a problem with binding a DropDownList. Let's assume a database five years old with many historical records. In order to enable just working with active data every datasource has a column hidden which is occasionally set by administrator in order to clean up old records. The selection looks like
1) SELECT Id, Value FROM Table WHERE Hidden = 0
The issue arises when the user opens a form with old data. As some records in DropDownListhave have already been hidden an exception is raised as the component cannot find the data for the list. For this case the following selection is valid
2) SELECT Id, Value FROM Table
it is possible to combine these two selection queries? The display value should always use query 2 while the listed values should use the query 1.
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 have a DropdownList where some of the items are longer then the width of the list. Firefox expands the width of the list and shws the full length of the ListItem, but Explorer (som people still use that) doesn't do that which results unability to read the whole of the ListItem. I added a "Title" attribute (Tooltip) to the ListItems which shows the full text but even though, the client asks if it's possible to split long ListItems in several lines so user will be able to read it without needing the Tooltip.
I have many controls on my form, but in particular, I have 2 dropdownlists. 1 dropdown list has 2 values, and each value controls what the second dropdownlist displays. This is an edititemtemplate and both dropdowns have the selecteditem set via '<%# Bind("fieldname") #>' on page load.
THe problem is, if I change the value of the first dropdown, it errors out because the second dropdwon has a bound value that is no longer acceptable.
Can I cancel the bind of the second control, if the the first one is changed? I would like to cancel the bind, and update the values by using a different datasource depending on the value of the first dropdown or hardcode the new values.
If Dropdown1 has a value of "A" for example Dropdown 2 Shows Values "1", "2", "3"
If Dropdown 1 has a value of "B" , Dropdown2 Shows Values "4", "5", "6".
It binds fine initially, but if I change Dropdown1 from A to B, I want Dropdown2 to show the new values, maybe with a default of "Select an Item" and not error out b/c it's attempts to bind a value of 1, 2, or 3.
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 have a standard gridview and detailsview. My detailsview has some fields which are templates, with dropdownlists. The user selects a record in the gridview, then can go down to the detailsview, select Edit, and change some values (using dropdownlists).I am getting the error, "DDL has a selectedvalue which is invalid because it does not exist...." when I click Edit in the detailsview.
I know the problem has something to do with the dropdownlists not being instantiated or bound until I enter Edit mode. Is that right? In what event should I databind my dropdownlists? I've tried several things but could not get it to work. Do I have to loop through all the rows of my details view looking for the dropdownlists, or can I access them directly from some event?
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]; } }
This has to be a simple thing, but for whatever reason, I'm just not finding it.I want to use the HTML Helper function to create a DropDownList based on a List<string> (and actually have it bind to the data field on the model). The simplest example, I suppose, would be:
<%: Html.DropDownList("Material", new SelectList(new[][code]....
This creates the items in the drop-down, but of course, there's nothing in this line that would bind it to my model (model.Material). I've done drop-downs with collections of models, where you can bind the Data and Display attributes to properties of the class, but I don't have a class here, just a List.
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?