how to make the dropdown value first item as not selected

Posted by Krishnamanohar under ASP.NET on 1/24/2014 | Points: 10 | Views : 708 | Status : [Member] | Replies : 3
Hi experts,
i have a dropdown(ddloptions) and i am binding the dropdown after that i am adding 00 as first option.the problem is when page is loaded 00 option is selected.my requirement is first item is not selected when the page is loaded
the code is like this
DataSet ds = new DataSet();
ds = objBus.getdropdownvalues();

ddloptions.DataSource = ds.Tables["Data"];
ddloptions.DataTextField = "PBL_BRANCH_CD";
ddloptions.DataValueField = "PBL_BRANCH_CD";
ddloptions.DataBind();


ddloptions.Items.Insert(0, "00");

Thanks in advance
Krish




Responses

Posted by: kgovindarao523-21772 on: 1/24/2014 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,

Try the following code
DataSet ds = new DataSet();
ds = objBus.getdropdownvalues();

ddloptions.DataSource = ds.Tables["Data"];
ddloptions.DataTextField = "PBL_BRANCH_CD";
ddloptions.DataValueField = "PBL_BRANCH_CD";
ddloptions.DataBind();

ddloptions.Items.Insert(0, "00");
ddloptions.SelectedIndex=1; // Or your required index here


Thank you,
Govind

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

Posted by: muralikrishnasurap-12704 on: 1/24/2014 [Member] Starter | Points: 25

Up
0
Down
Hi Manohar,
When you bind DropDownlist by default first Item will be displayed this you can control by DropDownlist.SelectedIndex=indexValue(int).


Best Regards
Murali Krishna.S

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

Posted by: Snaveen on: 2/13/2014 [Member] Starter | Points: 25

Up
0
Down
Hi,

I can't get your requirement properly.
What do you want exactlly, you want to set default value of dropdown right..?

What's the wrong in your code.
That's work fine, are you getting any error or you want to set default selection of that.

If you want to set the dropdown default selection then use below sample

EX:

ddl.SelectedValue="value";


or

ddl.SelectedIndex="index here";


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

Login to post response