Display the items in DropDownList - c#

In my project i have used four number of dropdownlists in a single form.
when im selecting an item from the 1st dropdownlist,the dropdownlist2 has to display the items that matches the selected item from dropdowmlist1.
Please clear my doubt.,

Use the SelectedIndexChanged-event on the first dropdownlist. Everytime the user selects a different item in the dropdownlist, this event is fired. In the method body you can now react to the change and filter the items of the second dropdownlist to match the selected item of the first dropdownlist. You can either do that manually in a loop or use LINQ (Enumerable.Select).

first of all its called a combobox.
Implement the OnSelectedItemChanged event from the combobox to fill the 2nd combobox
linky

Related

To get value dynamically in gridview based on button click

i have one dropdownlist drpSelectCollege and 2 tables College_M and CollegeSubject_M.In dropdown collegeid is been selected from College_M and now on the basis of College Id another field Subject along with corresponding value of Collegeid is to be displayed in gridview on a click of button search in c#.Plz help me out....
I guess you have a list which you use to bind in the DropDownList.
Look for the SelectionChanged event, when the event is fired you can use the SelectedIndex to use in your list and get the value you want.

How to pass selected list value from popup into a textbox using C# webforms?

I have a table called Vendor that has two columns: VendorNum & VendorName.
Is there a way to create a list or a listbox or a listview that when a button is clicked, this vendor list will pop up. Then the selected popup list's row will pass the selected VendorNum into a textbox that's in the parent page..
I only know GridView has the select row option, but is it a proper way to put the gridview into a Listbox so the list can be scrolled up/down all within a fixed box?
You might want to take a look at the ListBox.SelectValue and/or ListBox.SelectedItem properties

How to use ensurevisible method in listview?

I have a ListView contains 100 items, and we can do certain activities based on selected items. I have used EnsureVisible() method to adjust the visibility and my ListView refreshing time to time to update the data.
The problem now i am facing is if I select the first item in the list, I then start paging down (maybe select the 21th, 59th
and 75th) during this select, I could have highlighted the 1st, 24th and
56th when the control suddenly refreshes the page in this instance, only the 1st selected retains the focus and I have lost my other selections and have to go through again either individually or just quicker.
So my question is how i can select multiple items and do the action while ListView is refreshing during certain interval to fill data though EnsureVisible() is used?
This is my exisitng code:
if (_listviewFirst.SelectedItems.Count > 0)
{
_listviewFirst.SelectedItems[_listviewFirst.SelectedItems.Count - 1].EnsureVisible();
_listviewFirst.SelectedItems[0].EnsureVisible();
}
I would use the ListView.ItemSelectionChanged (MSDN) event and add/remove items (or their references) from a List of selected items. When your control is refreshed you should then iterate your selected items and update the items to selected in your ListView.
You will be able to take advantage of e.IsSelected and e.Item or e.ItemIndex in the event handler to do this.
I wouldn't use EnsureVisible at all for this.

Unable to fire SelectedIndexChanged Event for a single item in a combobox

I had gone through through some of the common questions here in the forum only:
Select Index does not fire for a single item
But I have two combobox related to each other, the value selected in the A determines the value in the B and on selcting the B combobox item, data is displayed.
So I want the event, even for a single item in the B combobox.
Should I append a select item in the B Combobox so that user selects( but that is the last option).
There are other solution as well, one is to call the event of the same selected index event in the page load method.
So in this manner we can show the result of single item as well. This is not the best way but it worked out for me.

Dropdown list selected item always set to default value

I wish to pass values of the selected items into a database and however noticed that the selected item is not what is sent into the database you can see in the snap shot below.
during run time the following value is recorded.
Where did it all go wrong with the dropdown lists selected item?
Counting on your intelligence...thanks.
Put your call to load the dropdownlist in
if (!Page.IsPostBack)
{
//LoadDropdownListHere();
}
Try DBNull.Value instead of null.
Edit:
I think you need to specify the type using this overload: http://msdn.microsoft.com/en-us/library/cc491445.aspx
CSMDataSource.InsertParameters.Add("CaseID", DBType.Int32, CaseIDDropDownList.SelectedItem.Text);
I found the problem for the dropdownlist always selecting the first value. It appears the dropdown list is always rebinded anytime i click a button that requires a post pack as such the data tha was binded at page load re binds a gain before the selected item gets picked as such the default first value gets picked all the time. to solve my problem i first disabled enable auto postback on the dropdownlist and in the code behind that is my .cs file during the page load, where i first binded the data to the dropdown list, i used a condition like if(!ispostback) to bind my data. what this does is when the page loads first time the dropdownlist is binded and if i should select an item from the drop down list, the "auto post back" that i disabled earlier on keeps the selected item selected and when i click and button that requires a post to the server, the (!ispostback) prevents the dropdownlist to be binded again before selection. so in effect, the selection is done first and afterwards if the page should load anew, the drop down list is binded again.
i was in a bit of a rush while typing so please bare with my typo errors. do call in anytime for more clarification...peace

Categories

Resources