Question ComboBox Issues

martin.s.ransome

Active member
Joined
May 29, 2011
Messages
25
Programming Experience
5-10
I have two comboboxes. The first one has a list of classes and the second one's datasource is based on a stored procedure that takes as a parameter the text from the fisrt. The Problem. The second cbo is displaying the key vaules and not the display values.

Code:
    <form id="form1" runat="server">    <div>
    
        
        <asp:Label ID="Label2" runat="server" 
            style="z-index: 1; left: 21px; top: 39px; position: absolute; width: 112px; margin-bottom: 7px" 
            Text="Select a Class"></asp:Label>  
        
        <br />
    
        <asp:Chart ID="Chart1" runat="server" Height="371px" Width="375px" 
            style="z-index: 1; left: 133px; top: 273px; position: absolute">
            <series>
                <asp:Series Name="Series1">
                </asp:Series>
            </series>
            <chartareas>
                <asp:ChartArea Name="ChartArea1">
                </asp:ChartArea>
            </chartareas>
        </asp:Chart>
    
    </div>
    <asp:Label ID="Label1" runat="server" 
        style="z-index: 1; left: 19px; top: 106px; position: absolute; width: 258px" 
        Text="Select a Student"></asp:Label><br /> <br />
    <asp:DropDownList ID="DropDownList1" runat="server" 
        
        style="z-index: 1; left: 23px; top: 69px; position: absolute; height: 32px; width: 146px;" 
        DataSourceID="SqlDataSourceClasses" DataTextField="ClassName" 
        DataValueField="ClassName" Height="14px">
    </asp:DropDownList>


    <asp:DropDownList ID="DropDownList2" runat="server" 
        DataSourceID="SqlDataSourceStudents" DataTextField="StudentID" 
        DataValueField="StudentID" 
        
        style="z-index: 1; left: 27px; top: 140px; position: absolute; height: 27px; width: 242px" 
        AutoPostBack="True">
    </asp:DropDownList>


    <asp:SqlDataSource ID="SqlDataSourceStudents" runat="server" 
        ConnectionString="<%$ ConnectionStrings:SIMSConnectionString %>" 
        
        SelectCommand="SELECT s.StudentID, s.FirstName + ' ' + s.LastName AS Student FROM Students AS s INNER JOIN ClassofStudents AS cs ON s.StudentID = cs.StudentID INNER JOIN Classes AS c ON cs.ClassID = c.ID WHERE (c.ClassName = @ClassName)">
        <SelectParameters>
            <asp:ControlParameter ControlID="DropDownList1" DefaultValue="Form 1" 
                Name="ClassName" PropertyName="SelectedValue" />
        </SelectParameters>
    </asp:SqlDataSource>


    <asp:SqlDataSource ID="SqlDataSourceClasses" runat="server" 
        ConnectionString="<%$ ConnectionStrings:SIMSConnectionString %>" 
        SelectCommand="SELECT [ClassName] FROM [Classes]"></asp:SqlDataSource>
    </form>
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,295
Location
Sydney, Australia
Programming Experience
10+
You don't have any ComboBoxes. A ComboBox is a Windows control. As your code says, you have DropDownLists. I opened this thread based on the title without noticing what forum it was in and it turns out to be a waste of time. Please use the correct names for everything to avoid such confusion.
 

martin.s.ransome

Active member
Joined
May 29, 2011
Messages
25
Programming Experience
5-10
Forgive my error please. It is not a combobox issue but rather a dropdownlist issue.

I accept correction with thanks, for I'd rather remain a fool for a day than remain a fool for a lifetime.
 

niceastham

Member
Joined
Mar 18, 2011
Messages
11
Programming Experience
1-3
Check the DataTextField property for the second drop down list. It currently reads StudentID which is the same as the DataValueField. Surely you would want this to show something else.
 
Top Bottom