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

  • Thread starter Thread starter Paul
  • Start date Start date
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";
 
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?
 
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";
 
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";
 
Back
Top