I'm trying to bind a List<String> to a DropDownList in a user control. I think I'm doing the right thing, but it seems that after my code executes the bindings are cleared. Here's the code for review!
User control: <asp:DropDownList ID="subjectNameDropDown" runat="server"/> <asp:DropDownList ID="yearLevelDropDown" runat="server"/> Auto-generated designed code-behind: public partial class NewSiteMetadataUserControl { protected global::System.Web.UI.WebControls.DropDownList subjectNameDropDown; protected global::System.Web.UI.WebControls.DropDownList yearLevelDropDown; } Code-behind: public partial class NewSiteMetadataUserControl : UserControl { protected override void CreateChildControls() { subjectNameDropDown = new DropDownList(); yearLevelDropDown = new DropDownList(); } protected override void OnLoad(EventArgs e) { base.OnLoad(e); EnsureChildControls(); // Attempt 1 List<String> subjectNames = GetSubjectValues(); foreach (var subjectName in subjectNames) subjectNameDropDown.Items.Add(subjectName); subjectNameDropDown.DataBind(); // Attempt 2 List<String> yearLevels = GetYearLevelValues(); yearLevelDropDown.DataSource = yearLevels; yearLevelDropDown.DataBind(); } }
Should this approach work? If it should, how can I debug what happens after the code executes?
I have a country table that has a list of countries. However, instead of just displaying the list alphabetical, I need to list the United States first, and then all the other countries in Alphabetical order. My select statement is pretty simple, jsut don't know how to get the US listed first...
private void AddDBDataToControl(DataSet app_Support,int count) { int i = 0; while (count != 0) { DateTime dt = Convert.ToDateTime(app_Support.Tables[0].Rows[i]["FromDate"].ToString()); //dt=23/08/2010 10:04:00 AM DropDownList h1 = (DropDownList)GVDate.Rows[i].Cells[1].FindControl("txthour"); h1.SelectedValue = dt.Hour.ToString(); DropDownList m1 = (DropDownList)GVDate.Rows[i].Cells[2].FindControl("txtmin"); m1.SelectedValue = dt.Minute.ToString(); DropDownList h2 = (DropDownList)GVDate.Rows[i].Cells[5].FindControl("txthourto"); DateTime dt2 = Convert.ToDateTime(app_Support.Tables[0].Rows[i]["ToDate"].ToString()); //dt2=28/08/2010 14:25:00 PM h2.SelectedValue = dt2.Hour.ToString(); DropDownList m2 = (DropDownList)GVDate.Rows[i].Cells[6].FindControl("txtminto"); m2.SelectedValue = dt2.Minute.ToString(); count--; i++; } } When the function executes h1.SelectedValue = "10"; and m1.SelectedValue ="04"; but when it reaches to count-- h1.SelectedValue takes the value "14"; rather than h1.SelectedValue = "10"; and h2.SelectedValue = "14"; and m1.SelectedValue ="25"; rather than m1.SelectedValue ="04"; and m2.SelectedValue = "25"
these order numbers in table t2 have many part numbers(and hence the need for a second table t2)
I can display t1 using gridview just fine
In that same gridview iI have added a template column containing a dropdownlist(to show partnumbers)
now how can I bind this dropdownlist to the order number so that when the page is loaded the user can click on the dropdownlist to see all the partnumbers associated with that order number.
I have a gridview where I can browse an user's information. Through the gridview I'm also able to edit some of this information. A recent change in my client's needs demands that one of these fields is now a DropDownList. This field represents a user's "schedule" (not literally a schedule but works like one), and the different schedule options to be assigned to a user are shown in the drop down list.
Problem: In the drop down list I want to show list items like "9-12 15-17", "10-14 15-18" so that it is easy for the administrator to tell which schedule he's assigning to an user. However, that shouldn't be their actual value. I need "9-12 15-17" to actually be '1' since this is the schedule ID that I'm trying to pass on to the DB.
Here's what I have so far: [Code]....
And with this last method I change the selected item's value to the Index. Meaning that if I select "9-12 15-17" which has an Index of 1 in the dropDownList, the actual value is now 1. Again, this is the behavior I expect. My experience with ASP is quite little as I'm new on this, but as far as I know, this only actually updates the string array. How would I go about modifying this to reflect my updates on the database? All input is taken into account.
I'm having trouble binding my textbox to my dropdownlist. I got it to work but I don't think it is the correct way of doing it. I have my DDL bound to a datasource and populating everything correctly. However, I couldn't find a better way of binding my textbox to it besides using the FormView control and its counterpart, Templates (edit,insert,etc) It looks messy and i was hoping there was a better way of doing it. I've researched it online for awhile now but I couldn't understand how to implement for my situation.
My DDL has company names in it and the datasource has all the information from the table including what I'm trying to have my textbox pull (Address).
I have a Dropdownlist in an itemTemplate in a gridview. My gridView binds to dataTable1 (from which the selected value for dropdown comes from) and dropDown binds to dataTable2 (i need to get DataValueField and DataTextField from here).
I'm trying to bind a value to a dropdownlist. Here how the code looks like in the aspx page...Bind the textboxes below is not a problem...but its not working with the dropdownlist..
So basically, what i want is the value selected from the dropdownlist to be remembered after i press next button and back button..
Now i want to do search, sorting & Paging in the GridView with out Postback of the Page & with out hitting the DataBase when do Paging or searching in GridView.
I have a form in which I have a dropdown list and a list box.
This dropdownlist is populated by a column in thetable . This drop down list may have values ranging from 1 to 5.
This values in the dropdownlist are to be made the caption headings of the list view control.
For insance if there are three values in the dropdown there should be three columns in the list box with the heading as the values of the dropdownlist.for 5 it should be 5.
Also there are two additional columns which would be constant.
I select a item from gridView and trying to show/update/delete in From view. In Form View I am using the dropdownlist filling it in Code behind. Then i bound the list. But the problem is it is not showing the slected value. Here is the code
I have a gridview that displays query results on a reporting page for a "home-grown" CRM application. From the gridview, a link can be clicked which opens a modal window that contains an iframe linked to a "details" page where record specific info can be viewed/altered. On the details page there are 10 or so dropdownlists (ddls) that are bound every time the page is called. The ddls are bound using a method similar to the example below. I am looking for a way top speed things up a bit. The details page could be called 10-20 times in one session and every time the page loads these ddls have to be bound from the same methods but for different records. What are some options for speeding up the load time for this page??
I am having problem to do a 2 way binding with DropDownList inside DetailsView, my markup declaration is:
[Code]....
But I am getting the following error messages on the line ddlCategoryId.DataBind(): ArgumentOutOfRangeException: 'ddlCategoryId' has a SelectedValue which is invalid because it does not exist in the list of items.sometimes I get different error: InvalidOperationException: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.]
- i have two drop down lists- ddl_SelectClient, ddl_SelectApplication
- when a client is selected in ddl_SelectClient, i have to show the list of the clients applications in ddl_SelectApplication
- i have written the below code in the ddl_SelectClient_SelectedIndexChanged routine to do the same
- i am getting the error("Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack") in the catch block when the ddl_SelectApplication gets binded
I have a List<string> that I want to use as a datasource for the gridview, making the column a HyperlinkField type and passing the value clicked in the column in the url. My code: