Link to home
Start Free TrialLog in
Avatar of Dovberman
DovbermanFlag for United States of America

asked on

How to set the label.text property to the data displayed in a dropdownlist. visual studio 2005

I need to set the label.text property to the data displayed in a dropdownlist.

Me.lblResource.Text = ddlResourceType.DataTextField returns the field name instead of the field value.

Source code for the aspx file

    <asp:Label ID="lblResourceType" runat="server" Text="Resource Type">
    </asp:Label>&nbsp;<br />
   
    <asp:DropDownList ID="ddlResourceType" runat="server" AutoPostBack="True"
      DataSourceID="dscResourceType"
      DataTextField="RT_Name" DataValueField="RT_ID">
    </asp:DropDownList>
   
    <asp:SqlDataSource ID="dscResourceType" runat="server"
      ConnectionString="<%$ ConnectionStrings:ResFinderSQLConnectionString %>"
        SelectCommand="SELECT [RT_ID], [RT_Name] FROM [Resource_Types]
      ORDER BY [RT_Name]" DataSourceMode="DataReader">
    </asp:SqlDataSource>

Source code for the aspx.vb file

    Protected Sub ddlResourceType_SelectedIndexChanged(ByVal sender As Object,
      ByVal e As System.EventArgs)
      Handles ddlResourceType.SelectedIndexChanged

        Me.lblResource.Text = ddlResourceType.DataTextField

Thanks,

Dovberman
ASKER CERTIFIED SOLUTION
Avatar of JackOfPH
JackOfPH
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dovberman

ASKER

I tried that. It returns the index value. Yet the dropdown list displays the text of the RT_Name field.