Dropdownlist

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2009
Posts: 27
Reputation: Pankaj18 is an unknown quantity at this point 
Solved Threads: 0
Pankaj18 Pankaj18 is offline Offline
Light Poster

Dropdownlist

 
0
  #1
Jul 3rd, 2009
Hi,
I want to display a text, getting from database, into a DropdownList using text property.

My Code::

  1. SqlDataReader drd;
  2. if (drd.Read())
  3. {
  4. drpcompname.Text = drd.GetValue(0).ToString();
  5.  
  6. }

But It Display an error::

'drpcompname' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value

Please help me.

Thanks!
Pankaj Singh
Last edited by Ezzaral; Jul 3rd, 2009 at 1:00 pm. Reason: Added [code] [/code] tags. Please use them to format any code that you post.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,613
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 469
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: Dropdownlist

 
0
  #2
Jul 3rd, 2009
Welcome Pankaj18,

Your source code must be surrounded with bb code tags. Read this How to use bb code tags?

Error message shows that a value you are assigned to the DropDownList control is not present inside the DropDownList's items.
Yes, the DropDownControl is empty. Isn't it?

Here, I am using bb code tags - See, how a source looks !!!
  1. SqlDataReader drd;
  2. .....
  3. if (drd.Read())
  4. {
  5. drpcompname..Items.Add(drd.GetValue(0).ToString());
  6. }
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 27
Reputation: Pankaj18 is an unknown quantity at this point 
Solved Threads: 0
Pankaj18 Pankaj18 is offline Offline
Light Poster

Re: Dropdownlist

 
0
  #3
Jul 3rd, 2009
Originally Posted by adatapost View Post
Welcome Pankaj18,

Your source code must be surrounded with bb code tags. Read this How to use bb code tags?

Error message shows that a value you are assigned to the DropDownList control is not present inside the DropDownList's items.
Yes, the DropDownControl is empty. Isn't it?

Here, I am using bb code tags - See, how a source looks !!!
  1. SqlDataReader drd;
  2. .....
  3. if (drd.Read())
  4. {
  5. drpcompname..Items.Add(drd.GetValue(0).ToString());
  6. }
I want to display at runtime not add
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 27
Reputation: Pankaj18 is an unknown quantity at this point 
Solved Threads: 0
Pankaj18 Pankaj18 is offline Offline
Light Poster

Re: Dropdownlist

 
0
  #4
Jul 3rd, 2009
Originally Posted by Pankaj18 View Post
I want to display at runtime not add
drpcompname..Items.Add(drd.GetValue(0).ToString());
the above code add the items ,not display......
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,613
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 469
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: Dropdownlist

 
0
  #5
Jul 3rd, 2009
Does your dropdownlist contains items? If yes then use
  1. drpcompname.SelectedValue=drd.GetValue(0).ToString();
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 27
Reputation: Pankaj18 is an unknown quantity at this point 
Solved Threads: 0
Pankaj18 Pankaj18 is offline Offline
Light Poster

Re: Dropdownlist

 
0
  #6
Jul 4th, 2009
Originally Posted by adatapost View Post
Does your dropdownlist contains items? If yes then use
  1. drpcompname.SelectedValue=drd.GetValue(0).ToString();
but it displays the same error::
drpclienttype' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value

help me..

Pankaj Singh
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,613
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 469
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: Dropdownlist

 
0
  #7
Jul 4th, 2009
First, fill the dropdownlist with values.
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 27
Reputation: Pankaj18 is an unknown quantity at this point 
Solved Threads: 0
Pankaj18 Pankaj18 is offline Offline
Light Poster

Re: Dropdownlist

 
0
  #8
Jul 4th, 2009
Thanks.
But it working when dropdownlist have some values, i have another case when i have no items in dropdownlist,it have only one item 'Select One', it display same error::
'drpcompname' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value

Thanks!

Pankaj Singh
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,613
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 469
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: Dropdownlist

 
0
  #9
Jul 4th, 2009
Thanks,

Please, Mark this thread as Solved if you get solution.
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,613
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 469
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: Dropdownlist

 
0
  #10
Jul 4th, 2009
If dropdownlist has no items (values) then you cannot assign a value for selection. This is the fact. Do not assign value if dropdown is empty.
Last edited by adatapost; Jul 4th, 2009 at 5:56 am. Reason: Typo
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC