Any possible to use SQL Query to load data from custom table for Data source of Drop-down list?

David Yu asked on April 6, 2018 03:06

We need get Drop-down list data source dynamically. Want to find a solution

Correct Answer

Peter Mogilnitski answered on April 6, 2018 04:54

If understand correctly, what you need is:

  1. Define new query for custom table
  2. Create your custom query according to guidelines. It should be something similar to:

    SELECT CustomTableIdFieldName, CustomTableValueFieldName FROM customtable_sampleTable WHERE ##WHERE## ORDER BY ##ORDERBY##

  3. Add New Query Data Source to your page template and point it to your query

  4. Add basic repeater to generate your drop down, point it your query data source.
  5. Define a transformation that your repeater that will use. <option value="<%# Eval("CustomTableIdFieldName") %>">Eval("CustomTableValueFieldName")</option>

  6. Add <select></select> tags to content before and after of your repeater

Your repeater now should render a drop down :)

P.S. There is also a shorter way without defining query, you can use custom table repeater. You can find the example under /Examples/Web-parts/Custom-tables/Custom-table-repeater.aspx on Corporate Site exmample. You just need to define transformation and add <select> to content before and after

2 votesVote for this answer Unmark Correct answer

   Please, sign in to be able to submit a new answer.