For some reason this is not working either. I have this code inserted w/in a
switch block, which appears to be causing the problem... although i cannot
see how.
Using VS.NET, the intellisense doesn't automatically recognize the ListItem
when instatiated with the "new" key word. However, when i create the ListItem
"outside" the switch block, intellisense automatically recognizes the
ListItem object immediately right typing the "new" constructor to instantiate
it.
I know this makes no sense. Maybe it's a bug w/ my VS.NET?
"ED_C#" wrote:
> You might want to try something like this
>
> for (int i=0;i<=dv.Tables["Table"].rows.count-1;i++)
> {
> ListItem li=new ListItem();
> li.DataTextField=dv.tables["table"].rows[i]["ColumnName"];
> li.DataValueField=dv.tables["table"].rows[i]["ColumnName"];
> DropDownList1.items.add(li);
> }
>
> This method doesn't bind the data to the control and you should be able to
> add values later using the same method.
>
> Good Luck.
>
>
> "charliewest" <(E-Mail Removed)> wrote in message
> news:74E17511-6D6C-462E-8A8B-(E-Mail Removed)...
> >I have binded a dropdownlist control to a data view. I am trying to add a
> > listitem to this already binded control, however, i cannot figure this
> > out.
> > My code is:
> >
> > // code to create data view object (dv)
> >
> > DropDownList1.DataSource = dv;
> > DropDownList1.DataMember = "vStA";
> > DropDownList1.DataTextField = "vStAText";
> > DropDownList1.DataValueField = "vStAId";
> > if (bNewQuestion)
> > {
> > DropDownList1.Items.Insert(0, (new ListItem(" ---- ", "")));
> > DropDownList1.SelectedIndex = 0;
> > }
> >
> > Is it simply not possible to add ListItems to already binded controls? Or
> > is
> > it my code?
> >
> > Thanks!
>
>
>
|