Place item at specific position in dropdown list - asp.net

Can we place/keep dropdownlist item at particular position. Say for example I want to bind dropdownlist to datasource and then add new item which is placed at particular position in dropdownlist. How can this be possible.

You can use Insert method.
dropDownList.Items.Insert(index, new ListItem("Default Panel", "0"));

Related

Fill only selected checkbox items from checkboxlist into new list

How can i set all selected items from an Checkboxlist into a list?
I tried this code but when i run it all checkbox items where added? I only want the selected items
List<string> WeeklyDays = (from l in CheckBoxListWeeklyDays.Items.Cast<ListItem>() select l.Value).ToList();
Your snippet is C#/ASP.NET not vbscript/classic-asp
In your query add a WHERE statement to look at the "Selected" attribute of each ListItem, similar to:
List WeeklyDays = (from l in CheckBoxListWeeklyDays.Items.Cast() where l.Selected select l.Value).ToList();
Taken from: How to get values of selected items in CheckBoxList with foreach in ASP.NET C#?

How to get Multiple selected listbox items to another listbox

In my ASP.NET application I have two listboxes, say Listbox1 and Listbox2. Listbox1 having some listitems and which is in Multiple Selection Mode. If I Press the transfer button the selected items in Listbox1 should be moved to Listbox2. I have tried it for Single Selection Move and it works fine.
Now I need help for multiselection.
Code for Single Selection
strItemText = lstAvailableItems.SelectedItem.Text
iItemCode = lstAvailableItems.SelectedValue
lstAvailableItems.Items.Remove(New ListItem(strItemText, iItemCode))
lstSelectedItems.Items.Add(New ListItem(strItemText, iItemCode))
Listbox image
If I press the > button single selected item will be moved from Available Items listbox to selected items list box. How to do this for multiple selection?
A combination of my original, and #Arman's.
Dim lstRemoveItem As New List(Of ListItem)
For Each li As ListItem In lstAvailableItems.Items
If li.Selected Then
lstRemoveItem.Add(New ListItem(li.Text, li.Value))
' can't remove from the collection while looping through it
End If
Next
For Each li As ListItem In lstRemoveItem
lstSelectedItems.Items.Add(li) ' add to "selected" items
lstAvailableItems.Items.Remove(li) ' remove from the original available items
Next
Use List. Iterate all items in the listbox and whatever it finds to be selected, add it to the list.
Dim lstRemoveItem As New List(Of ListItem)
For Each _item As ListItem In lstAvailableItems.Items
If _item.Selected Then
lstRemoveItem.Add(_item)
'here, method to add item to the first list.
End If
Next
For Each _item As ListItem In lstRemoveItem
lstSelectedItems.Items.Add(_item)
Next
Not exactly what you want, but you can configure the variables easily.

New record for child grid not coming up in ax 2009

I have created a new grid in tabPage1 for ParentTable
and child grid for childTable in tabPage2.
After opening the form the data is getting displayed successfully but when i am in the tabpage2 and click on ctrl + N the new row is inserting a new row in the parent grid and not in the child grid.
How to insert a new row from the form for the child grid.
Thanks
N
Set the DataSource property of tabPage2 to the name of your child datasource.

Telerik RadComboBox AutomaticLoadOnDemand

I use Telerik RadComboBox in my project. I set EnableAutomaticLoadOnDemand="true" on RadComboBox. It works good but when I want to set selected item on load of page event, it doesn't show selected item
With load on demand mode, so combobox does not have any item. It just has item(s) when you action on it.
In my opinion, you should get the specific item and add it to combobox manually on page load event like this way (I'm not sure the structure, just an idea.)
if (!IsPostBack)
{
var itemSelected = service.GetById(Id); //item Id
this.combobox.Items.Add(new RadComboboxItem(itemSelected.Id, itemSelected.Name));
this.combobox.SeletedValue = Id.ToString();
}
RadCombo allows to set up SelectedValue and Text properties even through there are no items in it.

Change databound Drop Down List programmatically

I have a drop down list that is populated in the page load event from a database table.
The drop down has a DataTextField set to a project name and the DataValueField set to the project id (interger).
Later I change the dropdowlist selected item with this code in the selectedindexchanged event of a gridview
GridViewRow row = GridView1.SelectedRow;
ddlProjectList.SelectedItem.Text = row.Cells[2].Text;
Does Changing the drop down list with this code cause the DataValueField property to change to the correct Project ID number also? If not is there a better way to do this?
=============================================EDIT
actually this code seems to be adding an additional item to the list so that the project i set with this code is listed twice so I don't think my code is correct
This does not change anything else than the text of the selected item in your DropDownList. Do you want to change the text and value of the project, or do you want to select the project from the DropDownList that relates to the selected row in the grid?
To change the project name and id, you'll have to change it in the data source behind the ProjectList. But if you just want to select the related project, you can use this:
var row = GridView1.SelectedRow;
if (ProjectList.Items.FindByText(row.Cells[2].Text) != null)
{
ProjectList.ClearSelection();
ProjectList.Items.FindByText(row.Cells[2].Text).Selected = true;
}
Setting SelectedItem.Text does not actually change the selected item by its text, it changes the text of the currently selected item. You need to use ddl.Items.FindItemByText (or it may be worded FindByText, I forget at the moment) to find the item, then set the ListItem.Selected property to true.
HTH.
You can do
ddlProjectList.FindByText(row.Cells[2].Text).Selected = true;
This will actually set it.

Resources