这里有一个用户控件的问题,我在运行时动态填充一些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;
}
答案 0 :(得分:1)
使用此语法从服务器端脚本输出文本到页面的html:
<tr>
<th><label id="Label2"><%= inputItem.Text.AsString() %></label></th>
<td><%= inputItem.Html.ToString() %></td>
</tr>