我在C#.net网站后面的代码中创建标签。标签包含一些我从服务器返回的标准数据。
我遇到的问题是我想在这些创建的控件(标签内)中添加一个按钮,但附加控件将覆盖标签中定义的Text。
我有什么办法可以阻止这种情况?
for (var i = 0; i < (QuoteArray.Length)-1; i++)
{
Button[] btnArr = new Button[QuoteArray.Length]; //not used
var button = new Button
{
ID = "Quote_0" + i,
CommandArgument = "i",
Text = "!!",
CssClass = "CountButton"
};
Label addL1 = new Label
{
ID = "new_labeieeu" + i,
Text = string.Format("Tariff: {1}</br>Reference: {0}</br>Price: £{3}</br>excl. VAT.</br>Max Passenger: {4}</br>Max Luggage: {5}</br>{2}</br>", QuoteArray[i][0], QuoteArray[i][1], QuoteArray[i][2], QuoteArray[i][3], QuoteArray[i][4], QuoteArray[i][5], QuoteArray[i][6]),
CssClass ="QuoteButton"
};
panelQuote.Controls.Add(addL1);
addL1.Controls.Add(button);
}
答案 0 :(得分:1)
您正在添加标签按钮,您可以这样做
panelQuote.Controls.Add(addL1);
panelQuote.Controls.Add(button);
这将在标签旁边添加按钮。
答案 1 :(得分:1)
它不漂亮,但我最后添加了另一个面板,所以标签和Button都进入这个面板,然后我可以根据需要设置样式。它确实意味着一个内部有40多个面板,但现在还可以。
for (var i = 0; i < (QuoteArray.Length)-1; i++)
{
Button[] btnArr = new Button[QuoteArray.Length];
Panel panel_Inside_Quote = new Panel
{
ID = "InnerQuote_" +i,
CssClass = "QuoteButton"
//string bob = Convert.ToString(stop);
};
panelQuote.Controls.Add(panel_Inside_Quote);
Button button = new Button
{
ID = "Quote_0" + i,
CommandArgument = "i",
Text = "!!",
CssClass = "CountButton"
};
Label addL1 = new Label
{
ID = "new_labeieeu" + i,
Text = string.Format("Tariff: {1}</br>Reference: {0}</br>Price: £{3}</br>excl. VAT.</br>Max Passenger: {4}</br>Max Luggage: {5}</br>{2}</br>", QuoteArray[i][0], QuoteArray[i][1], QuoteArray[i][2], QuoteArray[i][3], QuoteArray[i][4], QuoteArray[i][5], QuoteArray[i][6]),
CssClass ="QuoteButton"
};
panel_Inside_Quote.Controls.Add(addL1);
panel_Inside_Quote.Controls.Add(button);
//Make_Booking_Page(this, new EventArgs());*/
}