hi all
i have a dropdownlist on my page.
in page load event, i get some data in a datatable.
how can i fill the dropdownlist with the data?
i tried;
Dim dt As DataTable = ......
ddl.DataSource = dt
ddl.DataBind()
but it fills the dropwownlist with "system.data.datatable....." etc..
aspci
Member
237 Points
48 Posts
filling dropdownlist with datatable
Sep 08, 2005 08:53 AM|LINK
hi all
i have a dropdownlist on my page.
in page load event, i get some data in a datatable.
how can i fill the dropdownlist with the data?
i tried;
Dim dt As DataTable = ......
ddl.DataSource = dt
ddl.DataBind()
but it fills the dropwownlist with "system.data.datatable....." etc..
how can i fill it, must i use a loop?
thanx..
l0n3i200n
Participant
1443 Points
337 Posts
Re: filling dropdownlist with datatable
Sep 08, 2005 09:21 AM|LINK
IF ( Page.IsPostBack = false) then
DropDownList1.DataSource = tablename
DropDownList1.DataTextField =
"A Descriptive Field from Table";DropDownList1.DataValueField=
"A key / Value Field from Table";DropDownList1.DataBind();
end if
aspci
Member
237 Points
48 Posts
Re: filling dropdownlist with datatable
Sep 08, 2005 09:24 AM|LINK
sorry. i missed 2 properties.
ddl.datasource=dt
ddl.datavalıefield="pp"
ddl.datatextfield="cc"
ddl.databind()
it runs good.
alvinz_c
Star
9972 Points
1981 Posts
Re: filling dropdownlist with datatable
Sep 08, 2005 10:02 AM|LINK
ddl.DataSource = dt
ddl.DataTextField = "FieldName";
ddl.DataBind()
The "FieldName" is the column name in your DataTable, which would be displayed as text in the DDL.
Microsoft ASP.NET™ Enthusiast v1.1 / v2.0, Malaysia
Blog : http://alvinzc.blogspot.com