Dropdowns and matching Data

andycharger

Centurion
Joined
Apr 2, 2003
Messages
152
Hi

I have entries stored in my Database that are originally stored from <select> drop downs on a form.
e.g. <select>
<option>rice</option><option>peas</option> </select>
Now when I return to the form and retrieve the information from the database and put it back on my form I use the following:
Code:
<asp:TextBox  Font-Bold=True  CssClass="boxtext" id="txtName"  Text='<%# DataBinder.Eval(Container.DataItem, "first_name") %>' runat="server"></asp:TextBox>

So what I want to know is, if I have a drop down with RICE and PEAS in it, and I want to make the database recorded version the selected one when I edit the information, How do I get the option to be the Selected one?
 
Nearly!

Nice try but......

When I do the code above, it says the following:

Object reference not set to an instance of an object.

Yes, I have changed your code to reflect my names!

It seems that it does not like this during the page load. At what point can I call this in my code?
 
This will work too..

lstVegetables.Items.FindByValue("Peas")).Selected = True

The first one will not give youa NULL reference error if the value you supplied is not in the drop down, this one will, but its more to the point. In your other post, seems like your controls are not being initialized or something.
 
kahlua001 said:
What happens in your Page_load when you just do a mycheckbox.checked = true? Leave out all the rest for now.

When I do any reference in my Page_load event to any of my page items, it says the Object reference not set to an instance of an object.
The error occurs on the line you stated and I have changed the "mycheckbox.checked" to "chkOMB.checked" as that is a checkbox on my page. This is despite the fact that it is listed at the top of the VB page in "protected WithEvents"

Any ideas where I initialise it?
 
Back
Top