locked
Using DropdownList within Repeater RRS feed

  • Question

  • User-1876300537 posted

     I'm creating a form with a drop down list box inside a repeater control. I'm having trouble setting the "SelectedValue" of the listbox. I've found numerous examples on line where it's being set declaritively but I am unable to do this. It is not available through intellisense and of course I get an error when I try to use it.

    Here is my code:

    <ItemTemplate>
                <tr>
                    <td align="center"><asp:DropDownList ID="lstMonths" DataSourceID="SqlDataSourceMonths" DataTextField="MonthName"
                            DataValueField="MonthID" runat="server"></asp:DropDownList></td>
                    <td align="right"><%#Eval("YearCollected")%></td>
                    <td  align="right"><%#Eval("ADAPercentage")%>%</td>
                    <td  align="right"><%#Eval("AvgDailyAttendance")%></td>
                    <td align="center"><asp:LinkButton ID="LinkButton1" Commandname="edit" CausesValidation="false" CommandArgument='<%#Eval("ProgramAvgDailyAttendanceID")%>'                                                 runat="server">Edit</asp:LinkButton></td>
                    <td align="center"><asp:LinkButton ID="lnkDeleteADA" Commandname="delete" CausesValidation="false" CommandArgument='<%#Eval("ProgramAvgDailyAttendanceID")%>'                                             runat="server">Delete</asp:LinkButton></td>
                </tr>

    </ItemTemplate>

    Any help would be much appreciated.

    Wednesday, July 2, 2008 9:50 AM

Answers

  • User-1995538749 posted

    Try first changing the double-quotes around your SelectedValue property to single-quotes: 

    <itemtemplate>
    	<tr>
    		<td align="center">
    			<asp:dropdownlist id="lstMonths" datasourceid="SqlDataSourceMonths" datatextfield="MonthName"
    				datavaluefield="MonthID" selectedvalue='<%# Bind("MonthID") %>' runat="server">
    			</asp:dropdownlist>
    		</td>
    		<td align="right">
    			<%#Eval("YearCollected")%>
    		</td>
    		<td align="right">
    			<%#Eval("ADAPercentage")%>%
    		</td>
    		<td align="right">
    			<%#Eval("AvgDailyAttendance")%>
    		</td>
    		<td align="center">
    			<asp:linkbutton id="LinkButton1" commandname="edit" causesvalidation="false" commandargument='<%#Eval("ProgramAvgDailyAttendanceID")%>'
    				runat="server">Edit</asp:linkbutton>
    		</td>
    		<td align="center">
    			<asp:linkbutton id="lnkDeleteADA" commandname="delete" causesvalidation="false" commandargument='<%#Eval("ProgramAvgDailyAttendanceID")%>'
    				runat="server">Delete</asp:linkbutton>
    		</td>
    	</tr>
    </itemtemplate>
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 2, 2008 11:16 AM

All replies

  • User-1995538749 posted

    Even though the SelectedValue property doesn't appear as an available property of the DropDownList within intellisense, it can still be used. What is the error you are receiving?

    Wednesday, July 2, 2008 9:53 AM
  • User-1876300537 posted

     Code I'm using now:

    <ItemTemplate>
                <tr>
                    <td align="center"><asp:DropDownList ID="lstMonths" DataSourceID="SqlDataSourceMonths" DataTextField="MonthName"
                            DataValueField="MonthID" SelectedValue="<%#Eval("MonthID")%>" runat="server"></asp:DropDownList></td>
                    <td align="right"><%#Eval("YearCollected")%></td>
                    <td  align="right"><%#Eval("ADAPercentage")%>%</td>
                    <td  align="right"><%#Eval("AvgDailyAttendance")%></td>
                    <td align="center"><asp:LinkButton ID="LinkButton1" Commandname="edit" CausesValidation="false" CommandArgument='<%#Eval("ProgramAvgDailyAttendanceID")%>'                                                 runat="server">Edit</asp:LinkButton></td>
                    <td align="center"><asp:LinkButton ID="lnkDeleteADA" Commandname="delete" CausesValidation="false" CommandArgument='<%#Eval("ProgramAvgDailyAttendanceID")%>'                                             runat="server">Delete</asp:LinkButton></td>
                </tr>
            </ItemTemplate>

    I'm not getting an error msg, but the DropDownList control is not rendering html. When I "view source" in the browser I see the <asp: DropDownList> tag rather than html. When I remove the declarative SelectedValue from the DDL, the html for the list box renders as normal in the browser.

    Thoughts?

    Thanks.


     

    Wednesday, July 2, 2008 10:31 AM
  • User-1995538749 posted

    Try first changing the double-quotes around your SelectedValue property to single-quotes: 

    <itemtemplate>
    	<tr>
    		<td align="center">
    			<asp:dropdownlist id="lstMonths" datasourceid="SqlDataSourceMonths" datatextfield="MonthName"
    				datavaluefield="MonthID" selectedvalue='<%# Bind("MonthID") %>' runat="server">
    			</asp:dropdownlist>
    		</td>
    		<td align="right">
    			<%#Eval("YearCollected")%>
    		</td>
    		<td align="right">
    			<%#Eval("ADAPercentage")%>%
    		</td>
    		<td align="right">
    			<%#Eval("AvgDailyAttendance")%>
    		</td>
    		<td align="center">
    			<asp:linkbutton id="LinkButton1" commandname="edit" causesvalidation="false" commandargument='<%#Eval("ProgramAvgDailyAttendanceID")%>'
    				runat="server">Edit</asp:linkbutton>
    		</td>
    		<td align="center">
    			<asp:linkbutton id="lnkDeleteADA" commandname="delete" causesvalidation="false" commandargument='<%#Eval("ProgramAvgDailyAttendanceID")%>'
    				runat="server">Delete</asp:linkbutton>
    		</td>
    	</tr>
    </itemtemplate>
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 2, 2008 11:16 AM
  • User-1876300537 posted

     Thanks! The single quotes fixed the issue.

    Wednesday, July 2, 2008 11:45 AM