Showing posts with label .Net Error. Show all posts
Showing posts with label .Net Error. Show all posts

Tuesday, December 16, 2008

Cannot have multiple items selected in a DropDownList

This problem occurs when we try to select more than one item in the drop down at the same time. Also however the most common reason I found this to happen is that the same list item is added to multiple drop downs. Then we to select different values in these different drop downs where same list item was added. Ideally in order to avoid this, we should add new list items to each drop downs. We should carry list item added from one drop down to another
Sample code:
The following code causes error

//bind first dropdown
ListItem listCommon = new ListItem("Please Select One", "0");
ddlFirstDropDown.Items.Clear();
ddlFirstDropDown.Items.Add(listCommon);
ddlFirstDropDown.Items.Add(remaining items);

//bind second dropdown
ddlSecondDropDown.Items.Clear();
ddlSecondDropDown.Items.Add(listCommon);

ddlSecondDropDown.Items.Add(remaining items);

Fix:

//bind first dropdown
ListItem listCommon = new ListItem("Please Select One", "0");
ddlFirstDropDown.Items.Clear();

ddlFirstDropDown.Items.Add(listCommon);
ddlFirstDropDown.Items.Add(remaining items);

//bind second dropdown
ListItem listNewItem= new ListItem("Please Select One", "0");

ddlSecondDropDown.Items.Clear();
ddlSecondDropDown.Items.Add(listNewItem);
ddlSecondDropDown.Items.Add(remaining items);


And secondly always use the following code to select the particular value from drop down
ddlSecondDropDown.SelectedIndex = ddlSecondDropDown.Items.IndexOf (ddlSecondDropDown.Items.FindByValue(string value)));

Never use ddlSecondDropDown.SelectedValue or ddlSecondDropDown.SelectedItem for selecting a particular value from the drop down.


Keeping the above two things in mind should solve the problem.


Cheers

Monday, December 15, 2008

Cannot Use Leading..... to exit Top Directory

hey all,

We get this error message, when ever we are migrating an application from .Net frame work 1.1 to 2.0. The main cause of this issue is, in our 1.1 code we refer to urls using ".." syntax, to move to parent directory. This is not allowed in 2.0 frame work. So in order to make the code work in 2.0, we need to convert all the urls in the format using "~/" or "/" directly.
Eg: if url ="../images/image.gif" is the code present in 1.1 framework
then this image url needs to changed to url = "~/images/image.gif" for the code base to work with .Net framework 2.0.

Happy Coding