PC Review


Reply
Thread Tools Rate Thread

Asp:DropDown - get selected item

 
 
Ronny Mandal
Guest
Posts: n/a
 
      11th Oct 2007
Hi!

I have an .aspx with some controls that are created dynamically. The
items are populated into the box by setting the DataSource-property to
a list. In addition I specify the text and value with DataTextField
and DataValueField; this works as expected.

However, my problems arises when I want to read the selected value
(i.e. after a postback caused by a change in the DropDown), the
selected item is always the first item in the DropDown. I do call the
DataBind-method, I believe that this might cause this.

My idea is to parse the selected value for a pattern and perform
operations on background of what this contains.

Anyone who know how to accomplish this?

Regards,

Ronny Mandal

 
Reply With Quote
 
 
 
 
MDoyle
Guest
Posts: n/a
 
      11th Oct 2007
Are you repopulating the DropDown after the the postBack? You may be
having an issue where the drop down isn't populated yet when you are
reading the selected item.
On Oct 11, 12:25 pm, Ronny Mandal <ronn...@math.uio.no> wrote:
> Hi!
>
> I have an .aspx with some controls that are created dynamically. The
> items are populated into the box by setting the DataSource-property to
> a list. In addition I specify the text and value with DataTextField
> and DataValueField; this works as expected.
>
> However, my problems arises when I want to read the selected value
> (i.e. after a postback caused by a change in the DropDown), the
> selected item is always the first item in the DropDown. I do call the
> DataBind-method, I believe that this might cause this.
>
> My idea is to parse the selected value for a pattern and perform
> operations on background of what this contains.
>
> Anyone who know how to accomplish this?
>
> Regards,
>
> Ronny Mandal



 
Reply With Quote
 
Ronny Mandal
Guest
Posts: n/a
 
      11th Oct 2007
On Oct 11, 6:29 pm, MDoyle <MatthewRDo...@gmail.com> wrote:
> Are you repopulating the DropDown after the the postBack? You may be
> having an issue where the drop down isn't populated yet when you are
> reading the selected item.

Yes, I am populating after the post-back. But if the the drop down
isn't populated,
how come that I always get the first item when I get the current
selected?

Regards,

Ronny Mandal


 
Reply With Quote
 
David Wier
Guest
Posts: n/a
 
      11th Oct 2007
You will always get the first item, if you don't enclose the population of
the DDL inside an if/then/postback block
if not page.ispostback then
- - populate ddl
end if

David Wier
http://aspnet101.com
http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
bloated markup


"Ronny Mandal" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Oct 11, 6:29 pm, MDoyle <MatthewRDo...@gmail.com> wrote:
>> Are you repopulating the DropDown after the the postBack? You may be
>> having an issue where the drop down isn't populated yet when you are
>> reading the selected item.

> Yes, I am populating after the post-back. But if the the drop down
> isn't populated,
> how come that I always get the first item when I get the current
> selected?
>
> Regards,
>
> Ronny Mandal
>
>



 
Reply With Quote
 
bruce barker
Guest
Posts: n/a
 
      11th Oct 2007
this method requires Viewstate to be turned on (bad idea). just recreate
the dropdown in OnInit, then the databind will be before the postback
data load event.

-- bruce (sqlwork.com)



David Wier wrote:
> You will always get the first item, if you don't enclose the population of
> the DDL inside an if/then/postback block
> if not page.ispostback then
> - - populate ddl
> end if
>
> David Wier
> http://aspnet101.com
> http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
> bloated markup
>
>
> "Ronny Mandal" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> On Oct 11, 6:29 pm, MDoyle <MatthewRDo...@gmail.com> wrote:
>>> Are you repopulating the DropDown after the the postBack? You may be
>>> having an issue where the drop down isn't populated yet when you are
>>> reading the selected item.

>> Yes, I am populating after the post-back. But if the the drop down
>> isn't populated,
>> how come that I always get the first item when I get the current
>> selected?
>>
>> Regards,
>>
>> Ronny Mandal
>>
>>

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Asp:DropDown - get selected item Ronny Mandal Microsoft C# .NET 2 8th Oct 2007 08:38 PM
Selected Item in a Dropdown =?Utf-8?B?VGltOjouLg==?= Microsoft ASP .NET 0 4th Nov 2004 08:10 AM
DropDown Selected Item Default Thom Little Microsoft Dot NET Framework 1 23rd Sep 2004 11:29 PM
DropDown List Default Selected Item Kris Rockwell Microsoft ASP .NET 5 12th Apr 2004 12:04 PM
Re: Selected item in Dropdown bug Eric George Microsoft VB .NET 0 8th Nov 2003 06:48 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:17 AM.