locked
DynamicData Dropdown list RRS feed

  • Question

  • User1922250498 posted

    Ok, easy question to answer I hope. 

     

    I have a database table that has a "Active" field.  I want my drop downs to only show "Active = true" items. 

     

    Also when looking at the list page for the items, I would like the dropdown filter to sort on the "Active"  field, alternately showing true or false or all items.

     

    i am using vs 2010 and c# 

     

    Any ideas would be very approciated, thanks!

     

     

    Thursday, January 20, 2011 1:25 PM

Answers

  • User-1412735316 posted

    you can use sqldatasource binded with dropdownlist to populate it.


                 <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1"
                    DataTextField="location" DataValueField="location" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged1">
                </asp:DropDownList>
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:trailsdbConnectionString %>"
                    SelectCommand="SELECT ColumnName FROM TableName Where Active='true'"></asp:SqlDataSource>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 20, 2011 2:17 PM
  • User-330204900 posted

     Hi Jason, Just make a copy of the default ForeignKey_Edit field template and replace the PopulateListControl with you own method. Then use UIHint in your metadata to select you own custom field template (note: you will need to make a copy of the ForeignKey read only field template and name the same)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 20, 2011 7:14 PM

All replies

  • User-1412735316 posted

    you can use sqldatasource binded with dropdownlist to populate it.


                 <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1"
                    DataTextField="location" DataValueField="location" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged1">
                </asp:DropDownList>
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:trailsdbConnectionString %>"
                    SelectCommand="SELECT ColumnName FROM TableName Where Active='true'"></asp:SqlDataSource>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 20, 2011 2:17 PM
  • User1922250498 posted

    I was using a DynamicControl  

     

    <asp:DynamicControl runat="server" DataField="Office" ID="DynamicControl_Office"
                OnInit="DynamicControl_Init"/>

     

    but i just switched to the regular drop down instead, any ideas on how to do that with a dynamiccontrol?

    Thursday, January 20, 2011 5:53 PM
  • User-330204900 posted

     Hi Jason, Just make a copy of the default ForeignKey_Edit field template and replace the PopulateListControl with you own method. Then use UIHint in your metadata to select you own custom field template (note: you will need to make a copy of the ForeignKey read only field template and name the same)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 20, 2011 7:14 PM
  • User1922250498 posted

    Oh yes, I completely forgot about the copy and custom field option.  Ok, thank you! 

    Friday, January 21, 2011 11:27 AM
  • User1014298547 posted

    Where in the metadata does this UIHint go?

    Wednesday, March 13, 2013 11:40 AM