gridview control, trying to set selected value in a dropdown list

P

Paul

I have a gridview control with a template column that has a dropdown list.
I am trying to set the selected value with the code below but it does not
seem to work. It runs ok, no error but the value "minor" is not showing up
as selected, any ideas, thanks.

(e.Row.Cells[3].FindControl("drdnSeveritygv") as DropDownList).SelectedValue
= "minor";
 
T

Teemu Keiski

Hi,

at which point in code (Page_Load, Prerender, Button's click,RowDataBound
etc) are you trying to do this? Is it sure that databinding doesn't clear it
e.g that you set it first and call DataBind() immediately after?
 
P

Paul

Hi it is in the rowdatabound event. The actual code is

(e.Row.Cells[2].FindControl("ddrlist") as DropDownList).SelectedValue =
Convert.ToString(discSubCatnew.ID);
discSubCatnew.ID = an integer and this integer corresponds to the data value
field in the dropdown. Would you have to set it after you call databind?

--
Paul G
Software engineer.


Teemu Keiski said:
Hi,

at which point in code (Page_Load, Prerender, Button's click,RowDataBound
etc) are you trying to do this? Is it sure that databinding doesn't clear it
e.g that you set it first and call DataBind() immediately after?

--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net

Paul said:
I have a gridview control with a template column that has a dropdown list.
I am trying to set the selected value with the code below but it does not
seem to work. It runs ok, no error but the value "minor" is not showing
up
as selected, any ideas, thanks.

(e.Row.Cells[3].FindControl("drdnSeveritygv") as
DropDownList).SelectedValue
= "minor";
 
P

Paul

I got it working, had a typo in the dropdown list data value field, thanks!
--
Paul G
Software engineer.


Teemu Keiski said:
Hi,

at which point in code (Page_Load, Prerender, Button's click,RowDataBound
etc) are you trying to do this? Is it sure that databinding doesn't clear it
e.g that you set it first and call DataBind() immediately after?

--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net

Paul said:
I have a gridview control with a template column that has a dropdown list.
I am trying to set the selected value with the code below but it does not
seem to work. It runs ok, no error but the value "minor" is not showing
up
as selected, any ideas, thanks.

(e.Row.Cells[3].FindControl("drdnSeveritygv") as
DropDownList).SelectedValue
= "minor";
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top