joerdie
joerdie

Reputation: 379

Placing DataBound Drop Down List into TableCell

I have a bound drop down list that I would like to place into a Table Cell. I am used to Labels and Text Boxes but I cannot seem to get the syntax working on this one. This code is inside of a Webmethod and my output has to be just the html. Thank you.

[System.Web.Services.WebMethod]
public static string gatherSurchargeData(string PriceListItemID, string ProdID, string ColorCode)
{
DataTable GetProductSizes = new DataTable();

GetProductSizes = DataLayer.PricingToolDL.getProductSizes(ProdID, ColorCode);

DataTable dt = new DataTable();

dt = DataLayer.PricingToolDL.getScharge(PriceListItemID);

Table tblScharges = new Table();
tblScharges.ID = "tblScharges";

TableHeaderRow th = new TableHeaderRow();

TableHeaderCell thSizeScharge = new TableHeaderCell();

thSizeScharge.Text = "Size";

th.Cells.Add(thSizeScharge);

tblScharges.Rows.Add(th);

int i = 0;

    while (i <= dt.Rows.Count - 1)
    {
        TableRow tr = new TableRow();
        tr.ID = "tableTr" + i;
        TableCell tcSizeScharge = new TableCell();

        DropDownList ddl = new DropDownList();

        ddl.DataSource = GetProductSizes;
        ddl.DataTextField = "FitSize";
        ddl.DataValueField = "FitSize";
        ddl.DataBind();

        //string dtMovexSKU = dt.Rows[i]["MovexSKU"].ToString();
        //DataRow[] GetProductSizesMovexSKU = GetProductSizes.Select("MovexSKU Like'" + dtMovexSKU + "'");

        //tcSizeScharge.ID = "tcSizeScharge" + i;

        //tcSizeScharge.Text = GetProductSizesMovexSKU[0][1].ToString();

        tr.Cells.Add(tcSizeScharge);

        tblScharges.Rows.Add(tr);
        i++;
    }

string html = "";
using (StringWriter sw = new StringWriter())
{
    tblScharges.RenderControl(new HtmlTextWriter(sw));
    html = sw.ToString();
}

return html;
}

The commented lines would be the code I would use if I were only wanting text to appear if that helps.

Upvotes: 0

Views: 88

Answers (1)

Mairaj Ahmad
Mairaj Ahmad

Reputation: 14604

You need to add control in tablecell like this

tcSizeScharge.Controls.Add(ddl);

Upvotes: 1

Related Questions