[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Pascal

2/23/2004 3:09:00 PM

hi,

does anybody know how to set the selected index in a dropdownlist
when page is loaded for the first time? my code looks like:

int iCountryID = Int32.Parse(countryID);
dsCountryList = ds.getCountryList();
dropCountry.DataSource = dsCountryList;
dropCountry.DataValueField = "ID";
dropCountry.DataTextField = "Name";
dropCountry.DataBind();
dropCountry.SelectedIndex = iCountryID;

always first entry in dropdown is selected per default...

thx
pascal




-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.new... - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
4 Answers

Ignacio Machin \( .NET/ C# MVP \)

2/23/2004 3:28:00 PM

0

Hi Pascal,

SelectedIndex should do the trick fine, I would check a couple of things:
1- iCountryID is parsed to a number different than 0
2- That you do not call DataBind again after that.


Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Pascal" <pschriber@freesurf.ch> wrote in message
news:403a17a6$1_8@corp.newsgroups.com...
> hi,
>
> does anybody know how to set the selected index in a dropdownlist
> when page is loaded for the first time? my code looks like:
>
> int iCountryID = Int32.Parse(countryID);
> dsCountryList = ds.getCountryList();
> dropCountry.DataSource = dsCountryList;
> dropCountry.DataValueField = "ID";
> dropCountry.DataTextField = "Name";
> dropCountry.DataBind();
> dropCountry.SelectedIndex = iCountryID;
>
> always first entry in dropdown is selected per default...
>
> thx
> pascal
>
>
>
>
> -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
> http://www.new... - The #1 Newsgroup Service in the World!
> -----== Over 100,000 Newsgroups - 19 Different Servers! =-----


Pascal

2/23/2004 3:39:00 PM

0

I called a datagrid-databind after that.
after I replaced this two methods it works.

thx a lot!
Pascal


"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>
schrieb im Newsbeitrag news:OOlVQGi%23DHA.3808@TK2MSFTNGP09.phx.gbl...
> Hi Pascal,
>
> SelectedIndex should do the trick fine, I would check a couple of things:
> 1- iCountryID is parsed to a number different than 0
> 2- That you do not call DataBind again after that.
>
>
> Cheers,
>
> --
> Ignacio Machin,
> ignacio.machin AT dot.state.fl.us
> Florida Department Of Transportation
>
> "Pascal" <pschriber@freesurf.ch> wrote in message
> news:403a17a6$1_8@corp.newsgroups.com...
> > hi,
> >
> > does anybody know how to set the selected index in a dropdownlist
> > when page is loaded for the first time? my code looks like:
> >
> > int iCountryID = Int32.Parse(countryID);
> > dsCountryList = ds.getCountryList();
> > dropCountry.DataSource = dsCountryList;
> > dropCountry.DataValueField = "ID";
> > dropCountry.DataTextField = "Name";
> > dropCountry.DataBind();
> > dropCountry.SelectedIndex = iCountryID;
> >
> > always first entry in dropdown is selected per default...
> >
> > thx
> > pascal
> >
> >
> >
> >
> > -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
> > http://www.new... - The #1 Newsgroup Service in the World!
> > -----== Over 100,000 Newsgroups - 19 Different Servers! =-----
>
>




-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.new... - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----

Sarmad Aljazrawi

2/23/2004 7:30:00 PM

0

I'd do it like this:

Dim oListItem as ListItem
olistitem = dropCountry.items.FindByValue(iCountryID)
if not (olistitem is nothing) then
dropCountry.selectedItem.selected = false ' this if already have
a selected item.
olistitem.Selected = true
end if




--
Sarmad Aljazrawi
B.Sc. Computer Science, MSDBA, MCP
www.aljazrawi.net


"Pascal" <pschriber@freesurf.ch> wrote in message
news:403a17a6$1_8@corp.newsgroups.com...
> hi,
>
> does anybody know how to set the selected index in a dropdownlist
> when page is loaded for the first time? my code looks like:
>
> int iCountryID = Int32.Parse(countryID);
> dsCountryList = ds.getCountryList();
> dropCountry.DataSource = dsCountryList;
> dropCountry.DataValueField = "ID";
> dropCountry.DataTextField = "Name";
> dropCountry.DataBind();
> dropCountry.SelectedIndex = iCountryID;
>
> always first entry in dropdown is selected per default...
>
> thx
> pascal
>
>
>
>
> -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
> http://www.new... - The #1 Newsgroup Service in the World!
> -----== Over 100,000 Newsgroups - 19 Different Servers! =-----


Julie J.

2/23/2004 10:11:00 PM

0

The SelectedIndex is a 0-based number that specifies the literal index into the
list of items. So, the first item is index 0, second is 1, third is 2, etc.

If you are attempting to select based on some other identifier, you need to
find the physical index first. Use FindStringExact to lookup the name, or
iterate over the items looking for the appropriate country ID and then set that
item to selected.

Pascal wrote:
>
> hi,
>
> does anybody know how to set the selected index in a dropdownlist
> when page is loaded for the first time? my code looks like:
>
> int iCountryID = Int32.Parse(countryID);
> dsCountryList = ds.getCountryList();
> dropCountry.DataSource = dsCountryList;
> dropCountry.DataValueField = "ID";
> dropCountry.DataTextField = "Name";
> dropCountry.DataBind();
> dropCountry.SelectedIndex = iCountryID;
>
> always first entry in dropdown is selected per default...
>
> thx
> pascal
>
> -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
> http://www.new... - The #1 Newsgroup Service in the World!
> -----== Over 100,000 Newsgroups - 19 Different Servers! =-----