0

I'm creating a system that basically allows a user to select criteria based on a database in order to formulate SQL queries and run them to output the data to excel. I'm currently trying to create functionality that will allow users to select columns from tables that they have selected in a previous step. I've tried using a repeater control for this but couldn't get it to work properly so what I've done is created a div with runat="server" as the container and in the code-behind I have a string list that stores all the tables that users have selected from two dropdownlists in the previous step. The code I currently have is as follows:

        SelectedTables.Add(PrimaryTableList.SelectedItem.Text);
        foreach (ListItem table in SecondaryTableList.Items)
        {
            if (table.Selected)
            {
                SelectedTables.Add(table.Text);
            }
        }

        string connStr = ConfigurationManager.ConnectionStrings["umbracoDbDSN"].ConnectionString;
        SqlConnection msSQLconnection = new SqlConnection(connStr);
        if (msSQLconnection.State == ConnectionState.Closed)
        {
            msSQLconnection.Open();
        }
        foreach (String tableName in SelectedTables)
        {
            ListBox ColumnsList = new ListBox();
            AvailableFieldsDiv.InnerHtml += "<p>" + tableName + "</p>";
            AvailableFieldsDiv.Controls.Add(ColumnsList);
            SqlCommand msSqlCommand = new SqlCommand("exec sp_columns '" + tableName + "'", msSQLconnection);
            SqlDataAdapter msSqlAdapter = new SqlDataAdapter(msSqlCommand);
            DataSet myDataSet = new DataSet();
            msSqlAdapter.Fill(myDataSet);
            ColumnsList.DataSource = myDataSet;
            ColumnsList.DataBind();
        }
        if (msSQLconnection.State == ConnectionState.Open)
        {
            msSQLconnection.Close();
        }

The problem I'm having with this code is that when I try to create the ListBox and add it to the container div I get an error stating "Cannot get inner content of AvailableFieldsDiv because the contents are not literal." Alternatively, I was also thinking about using a checkbox list instead of the listbox because this would allow the user to select multiple columns at once. Thanks in advance.

Tony Barsotti
  • 1,691
  • 2
  • 13
  • 17
  • check [this](http://stackoverflow.com/questions/2610249/cannot-get-inner-content-of-because-the-contents-are-not-literal) – jomsk1e Apr 04 '14 at 15:04
  • That's pulling values from an HTML table. I'm trying to get just the column names from the selected SQL tables and use that list of column names as the datasource of the listbox or checkbox list that I'm dynamically creating. – Tony Barsotti Apr 04 '14 at 15:08

0 Answers0