views:

77

answers:

1

I have a table called ProjectRegion. It has two columns, an id and a title. I successfully use ActiveRecord to get all the rows. I want to create a drop down list where I assign the id column to the value and the title to the text. I suspect I'll be able to do something like-

ProjectRegion[] projRegion = ProjectRegion.FindAll();
DropDownList1.DataTextField = ???;
DropDownList1.DataValueField = ???;
DropDownList1.DataBind();

But I don't know the syntax?

+1  A: 

Maybe what you need is:

DropDownList1.DataSource = ProjectRegion.FindAll();
DropDownList1.DataTextField = "title";
DropDownList1.DataValueField = "id";
DropDownList1.DataBind();

The values for DataTextField and DataValueField are just strings referencing the properties of your ProjectRegion class.

Nelson Reis
Sorry, I think I described it incorrectly. I create the drop down menu with-<SELECT id="DropDownList1" name="DropDownList1" runat="server"></SELECT>
Tom
Sure, is the same thing.
Nelson Reis
I don't think those properties exist for my DropDownList1 object.I get two build errors like:Error 41 'System.Web.UI.HtmlControls.HtmlSelect' does not contain a definition for 'DisplayMember' and no extension method 'DisplayMember' accepting a first argument of type 'System.Web.UI.HtmlControls.HtmlSelect' could be found (are you missing a using directive or an assembly reference?)
Tom
That code works now. Awesome. Thanks.
Tom
Glad I could help ;-)
Nelson Reis