Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > gridview control, trying to set selected value in a dropdown list

Reply
Thread Tools

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

 
 
Paul
Guest
Posts: n/a
 
      06-26-2008
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";
--
Paul G
Software engineer.
 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      06-26-2008
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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";
> --
> Paul G
> Software engineer.



 
Reply With Quote
 
 
 
 
Paul
Guest
Posts: n/a
 
      06-26-2008
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" wrote:

> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> >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";
> > --
> > Paul G
> > Software engineer.

>
>
>

 
Reply With Quote
 
Paul
Guest
Posts: n/a
 
      06-26-2008
I got it working, had a typo in the dropdown list data value field, thanks!
--
Paul G
Software engineer.


"Teemu Keiski" wrote:

> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> >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";
> > --
> > Paul G
> > Software engineer.

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to get selected value from dropdown list Andy Sutorius ASP .Net 6 10-29-2012 08:14 PM
bind a dropdown in a column in a datagrid based on the dropdown value selected in another column of the datagrid. vishnu ASP .Net 1 03-25-2006 01:24 PM
Q: dropdown list, no selected value =?Utf-8?B?SklNLkgu?= ASP .Net 2 04-12-2005 03:38 PM
ASP.NET Set selected value of Dropdown within Datagrid Jenna Alten ASP .Net 6 02-26-2005 04:12 AM
Re: need selected value from dropdown list box Scott Allen ASP .Net 1 08-25-2004 07:09 PM



Advertisments