views:

21

answers:

1

In .Net 3.5 and VB.NET VS2008 How to set the DataTextField property in this link:

http://www.brainbell.com/tutorials/ASP/Simple_Databinding.html

It says:

Now update the page to build a list of TechnologyDescriptors and to attach the collection of TechnologyDescriptors for each control. For each control, set the DataTextField property to "TechnologyName" (to map it to the TechnologyDescriptor's TechnologyName property). This will ensure that the technology name will appear in the control. Then set the DataValueField for each control to "Description" to map the Description property to be the associated value.

How to do this ?

A: 

Assuming you're data binding to a ListBox, you can set the value of DataTextField in either the asp code:

<asp:ListBox id="Listbox1" 
     DataSource="<% databindingexpression %>"
     DataTextField="DataSourceField"
     DataValueField="DataSourceField"
     AutoPostBack="True|False"
     Rows="rowcount"
     SelectionMode="Single|Multiple"
     OnSelectedIndexChanged="OnSelectedIndexChangedMethod"
     runat="server">

   <asp:ListItem value="value" selected="True|False">
      Text
   </asp:ListItem>

</asp:ListBox>

or using code behind:

ListBox1.DataTextField = "DataSourceField";
Dexter