How to set DropDownList SelectedIndex dynamically at runtime?

Posted by Raja under ASP.NET on 4/30/2007 | Views : 54215 | Status : [Member] | Replies : 7
Hi,

I have a situation where I had to set the seleted index property of the DropDonwList dynamically at runtime.

I tried using dropDownList.SelectedValue = variableName but it was giving error where there is nothing in variableName.

Please suggest as soon as possible.

Regards,
Raja, USA



Responses

Posted by: Jayakumars on: 9/29/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi
try this Code

DropDownList drp = new DropDownList();
drp.SelectedIndex = 1;



Mark as Answer if its helpful to you

Raja, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 9/29/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi
Please mark as answer if it helpful to you.

Mark as Answer if its helpful to you

Raja, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Priyagoel_24 on: 8/1/2013 [Member] Starter | Points: 25

Up
0
Down
Dear Sir ,


There is problem arising while inserting the values of month and year in my code.
And also advise me how do I prevent duplicate entries.
DataTable dt1 = new DataTable();

Because of this dt1 ,the values of month and year is not being inserted.

Regard
regrd


Raja, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 8/2/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Can you explain in detail... post us the table structure and what values you tried to insert ?

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Raja, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Priyagoel_24 on: 8/3/2013 [Member] Starter | Points: 25

Up
0
Down
hello friend,

duplicate entry fetch database asp and c#


regard
Priya

Raja, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: DeySomnath on: 7/2/2007 [Member] Starter

Up
0
Down
Please try this,

dropDown1.SelectedIndex = dropDown1.Items.IndexOf(dropDown1.Items.FindByText(Value));

OR

dropDown1.Items.FindByText(Value).selected =true




Raja, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Chinnu21 on: 7/20/2007 [Member] Starter

Up
0
Down

To set selected index using text

DropDownList1.Items.FindByText("anil").Selected = True;

Raja, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response