Friday, March 16, 2012

Make a value the default in a databound dropdown

I have a databound dropdown in my page. I want to make one of the
values the default value. Any ideas?

Just to explain further, I have also appended one item to the dropdown,
using the AppendDataBoundItems="True" property of the dropdown.
Unfortunately the item I have appended to the dropdown has become the
default value of the dropdown list which is not what I want.

Kind regards,

Steve.myDropDown.SelectedIndex =
myDropDown.Items.IndexOf(myDropDown.Items.FindByVa lue("yourDefaultValue"))

you can also use FindByText which uses the text, instead of the value.

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/
"Steve" <bahram@.iranmania.comwrote in message
news:1157613198.594826.148600@.b28g2000cwb.googlegr oups.com...

Quote:

Originally Posted by

>I have a databound dropdown in my page. I want to make one of the
values the default value. Any ideas?
>
Just to explain further, I have also appended one item to the dropdown,
using the AppendDataBoundItems="True" property of the dropdown.
Unfortunately the item I have appended to the dropdown has become the
default value of the dropdown list which is not what I want.
>
Kind regards,
>
Steve.
>


Thank you for this Karl.

Should I put this code in the page load event in page behind or can I
somehow put it as a parameter in between the dropdown tags in the page
itself.

Kind regads,

Steve

Karl Seguin [MVP] wrote:

Quote:

Originally Posted by

myDropDown.SelectedIndex =
myDropDown.Items.IndexOf(myDropDown.Items.FindByVa lue("yourDefaultValue"))
>
you can also use FindByText which uses the text, instead of the value.
>
Karl
>
--
http://www.openmymind.net/
http://www.codebetter.com/
>
>
"Steve" <bahram@.iranmania.comwrote in message
news:1157613198.594826.148600@.b28g2000cwb.googlegr oups.com...

Quote:

Originally Posted by

I have a databound dropdown in my page. I want to make one of the
values the default value. Any ideas?

Just to explain further, I have also appended one item to the dropdown,
using the AppendDataBoundItems="True" property of the dropdown.
Unfortunately the item I have appended to the dropdown has become the
default value of the dropdown list which is not what I want.

Kind regards,

Steve.


I'm pretty sure you're stuck doing it in codebehind.

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/
"Steve" <bahram@.iranmania.comwrote in message
news:1158133577.000959.188810@.b28g2000cwb.googlegr oups.com...

Quote:

Originally Posted by

Thank you for this Karl.
>
Should I put this code in the page load event in page behind or can I
somehow put it as a parameter in between the dropdown tags in the page
itself.
>
Kind regads,
>
Steve
>
>
Karl Seguin [MVP] wrote:

Quote:

Originally Posted by

>myDropDown.SelectedIndex =
>myDropDown.Items.IndexOf(myDropDown.Items.FindByVa lue("yourDefaultValue"))
>>
>you can also use FindByText which uses the text, instead of the value.
>>
>Karl
>>
>--
>http://www.openmymind.net/
>http://www.codebetter.com/
>>
>>
>"Steve" <bahram@.iranmania.comwrote in message
>news:1157613198.594826.148600@.b28g2000cwb.googlegr oups.com...

Quote:

Originally Posted by

>I have a databound dropdown in my page. I want to make one of the
values the default value. Any ideas?
>
Just to explain further, I have also appended one item to the dropdown,
using the AppendDataBoundItems="True" property of the dropdown.
Unfortunately the item I have appended to the dropdown has become the
default value of the dropdown list which is not what I want.
>
Kind regards,
>
Steve.
>


>

0 comments:

Post a Comment