0

这里有一个用户控件问题,我在运行时动态填充一些 html 输入标签。请参阅下面的 html 控件。

在用户控件中创建动态字段:

foreach (InputItem inputItem in searchFunctions)
    {             
%>
    <tr> 
        <th><label id="Label2"><%inputItem.Text.AsString();%></label></th>
            <td>
            <%
                inputItem.Html.ToString();
                %>
            </td>
    </tr>
<%  
    }                      
%>

问题出在使用控件的页面的 page_load 上。我正在获取引用的控件并对其进行初始化(请参见下面的代码)。但它似乎没有采取。该页面正在加载控件空白,就像它在填充任何数据之前加载它一样。

我确实知道代码肯定会进入动态人口部分,并且 html 是合理的。即使它不是标签上的 inputItem.Text 也会通过,但它也是空白的。

public void Page_Load(object sender, System.EventArgs e)
{
    BindData();
}

protected void BindData()
{
    Common.PopulateListFromDataTable(UnitOfMeasure.GetUnitOfMeasureByGroupName("weight"), unitOfMeasure, "UnitOfMeasure", "UnitOfMeasureLong");
    unitOfMeasure.SelectedIndex = unitOfMeasure.Items.IndexOf(unitOfMeasure.Items.FindByText("pounds"));
    InitializeOrderSearch();

}

protected void InitializeOrderSearch()
{
    List<InputItem> searchFunctions = new List<InputItem> 
    {
        new InputItem("text","BillingCompany","BillingCompany","Company Name","100px"),
        new InputItem("text","PurchaseOrderNumber","PurchaseOrderNumber","PO#","100px"),
        new InputItem("dropdown","OrderStatus","OrderStatus","Status","100px"),
    };

    List<string> columns = new List<string>()
    {
        "PurchaseOrderNumber",
        "ProcessDate",
        "Status"
    };

    //OrderSearch1 is name of control from aspx
    OrderSearch1.searchFunctions = searchFunctions;
    OrderSearch1.columns = columns;
}

我也尝试过下面这样的事情,但没有运气,抛出一个错误,说它不能从类型控制转换为 ASP.control 类型。任何想法,在这里有点不知所措。

protected void BindData()
{
    Common.PopulateListFromDataTable(UnitOfMeasure.GetUnitOfMeasureByGroupName("weight"), unitOfMeasure, "UnitOfMeasure", "UnitOfMeasureLong");
    unitOfMeasure.SelectedIndex = unitOfMeasure.Items.IndexOf(unitOfMeasure.Items.FindByText("pounds"));
    this.OrderSearch1 = InitializeOrderSearch();

}

protected admin_controls_OrderSearch InitializeOrderSearch()
{
    admin_controls_OrderSearch blah = new admin_controls_OrderSearch();
    List<InputItem> searchFunctions = new List<InputItem> 
    {
        new InputItem("text","BillingCompany","BillingCompany","Company Name","100px"),
        new InputItem("text","PurchaseOrderNumber","PurchaseOrderNumber","PO#","100px"),
        new InputItem("dropdown","OrderStatus","OrderStatus","Status","100px"),
    };

    List<string> columns = new List<string>()
    {
        "PurchaseOrderNumber",
        "ProcessDate",
        "Status"
    };

    //OrderSearch1 is name of control from aspx
    blah.searchFunctions = searchFunctions;
    blah.columns = columns;
    return blah;
}
4

1 回答 1

1

使用此语法将文本从服务器端脚本输出到页面的 html:

<tr> 
    <th><label id="Label2"><%= inputItem.Text.AsString() %></label></th>
    <td><%= inputItem.Html.ToString() %></td>
</tr>
于 2013-09-18T03:00:09.203 回答