The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
|
|
manually loading a combo box in web
Posted: 02 Feb 10 3:35 PM
|
i'm trying to load a combo box or list box with the followoing code:
PanelRefresh.RefreshTabWorkspace();
QFListBox.Items.Add("ABC", "456"); Gives the error (sumarized) smart part failed to load; error;no overload for method 'Add" takes '2' arguments.
QFListBox.Items.Add("ABC"); This yields no erros, but doesn't seem to do anything.
PanelRefresh.RefreshTabWorkspace(); I added this to the end, but no change
Ultimately, I have a set of data (text and values) that I need to load into a combo. I am getting the values back from a dll I wrote.
|
|
|
|
Re: manually loading a combo box in web
Posted: 02 Feb 10 4:02 PM
|
You need to add a list item:
ListItem i = new ListItem("ABC", "456"); QFListBox.Items.Add(i);
ListItem is located in System.Web.UI.WeControls |
|
|
|
Re: manually loading a combo box in web
Posted: 02 Feb 10 4:19 PM
|
Looks good , but I can't get it to work.
mabe it cause I don't know if I need to do anything with this: >>ListItem is located in System.Web.UI.WeControls
I'm trying he code from a button using a OnClick C# snippet. Are the above 2 lines all I need? |
|
|
|
Re: manually loading a combo box in web
Posted: 02 Feb 10 4:23 PM
|
It should be. If you don't have a 'using' in your code, you'll need to spell out the assembly name for ListItem:
System.Web.UI.WeControls.ListItem i = new System.Web.UI.WeControls.ListItem("ABC", "456"); QFListBox.Items.Add(i);
|
|
|
|
Re: manually loading a combo box in web
Posted: 02 Feb 10 4:26 PM
|
I had some values stored in the Items.collection property area. When I cleared that out the codes started working.
Still, I feel like you're trying to tell me something with this bit of information, but I don't know what. >>ListItem is located in System.Web.UI.WeControls
thanks very much for your help. |
|
|
|
Re: manually loading a combo box in web
Posted: 02 Feb 10 5:31 PM
|
I was just letting you know where the List class is located. However, I had a typo in there and missed a 'b'. It should read "System.Web.UI.WebControls" |
|
|
|
Re: manually loading a combo box in web
Posted: 03 Feb 10 2:29 PM
|
This works great: ListItem i = new ListItem("ABC", "456"); QFListBox.Items.Add(i);
The dropdown displays "ABC" and the form saves "456", but when I re-open the form 456 is displayed. Do I have to manually code around this to fix it or is there a better solution?
I guess I have to build the combo box on form open and make sure it displays the proper text & value?? |
|
|
|
Re: manually loading a combo box in web
Posted: 03 Feb 10 2:37 PM
|
Hmm - sounds like some sort of issue there. I've always loaded them up when the form opens up, so having existing items when the form is opened has not been an issue for me in the past. |
|
|
|
Re: manually loading a combo box in web
Posted: 04 Feb 10 11:38 AM
|
Since the value is saved in the Database and not the text, the item needs to exist in the list before it binds or else it will just display the value.
What I tend to do in this situation is stick the following after I've generated/modified the list
try { QFListBox.DataBind; } catch { } Also, the way you create the list item isn't the only way. I tend to do the following, only because it's slightly quicker to write...
QFListBox.Items.Add(new ListItem("ABC", "456")); |
|
|
|