2

我有一个文件集和图例,里面有“一些文本”,在这个字段集中我有一个 GRID

我有 2 个问题

  1. 如何展示?从后面的代码中隐藏 html 文件集,我尝试了以下方式来显示和隐藏字段集

    a) 设置 runat="server"--但它不起作用 b) 我将字段集粘贴到 asp.net 面板中并尝试显示/隐藏面板,它也不起作用

  2. 如何从代码后面为图例设置文本,即我想在 AS leged 文本后面设置“一些文本”+ Value_Form_Code

注意:我正在使用“Rad Ajax Manager”和 Rad Ajax LoadingPanel

4

4 回答 4

4
<asp:Panel ID="Panel1" runat="server" >                
<fieldlset>
<legend><asp:Label id="Label1" runat="server" /></legend>
</fieldset>
</asp:Panel>

如何从后面的代码中显示/隐藏 html 文件集?

Panel1.Visible = true; // or false

如何从代码后面设置图例文本,即我想在 AS 图例文本后面设置“一些文本”+ Value_Form_Code?

Label1.Text = String.Format("some text {0}",Value_Form_Code);
于 2013-11-07T05:42:02.990 回答
2

it should also be possible to add an ID and runat="server" to your fieldset and control visibility through code-behind. Just remember to write 'ID' in upper letters.

<fieldset ID="myFieldset" runat="server">

You won't be able to control the legend text, unless you give it an ID and runat itself. But visibility is absolutely possible.

The upside of this approach is: no needless html markup (Panel would be extra div). The downside: fieldsets are not really asp-controls, so some things might give you exceptions, so use carefully.

I use this approach only when I want to prevent controls from rendering at all in certain cases (visibility does that).

于 2016-02-12T09:43:57.527 回答
0

1:我认为你应该把你的字段集放在一个 asp:panel 中,然后从你的代码隐藏中隐藏/显示面板。这将自动隐藏/显示您的字段集。

2:就设置图例文本而言,只需使用 runat="server" 设置图例并从代码隐藏设置代码。

于 2013-11-07T05:42:21.597 回答
0

当您设置asp:panel控件的“GroupingText”属性时,它将呈现为HTML 中 的“fieldset”标签,而“GroupingText”属性值中的任何设置都将呈现为标签。<legend>

我认为以下代码将根据您的要求为您提供帮助。

对于设计方面,

<asp:Panel runat="server" ID="Panel1" GroupingText="This is legend">
       <h4>Your Content Goes Here</h4>
    </asp:Panel>
    <br />
    <asp:Button ID="btnHidePanel" runat="server" Text ="Hide FieldSet" onclick="btnHidePanel_Click" />
    <asp:Button ID="btnShowPanel" runat="server" Text ="Show FieldSet" onclick="btnShowPanel_Click" Visible="false" />

对于代码隐藏试试这个,

protected void btnHidePanel_Click(object sender, EventArgs e)
        {
            Panel1.Visible = false;
            btnHidePanel.Visible = false;
            btnShowPanel.Visible = true;
        }

        protected void btnShowPanel_Click(object sender, EventArgs e)
        {
            Panel1.Visible = true;
            Panel1.GroupingText = "This Legend Text Has been Changed";
            btnHidePanel.Visible = true;
            btnShowPanel.Visible = false;
        }
于 2013-11-07T14:48:47.193 回答