当asp.net可折叠面板展开或折叠时更改按钮文本

时间:2015-04-20 20:46:26

标签: asp.net ajax ajaxcontroltoolkit

我正在使用按钮来显示/隐藏asp可折叠面板。折叠面板时如何将按钮的文本更改为show,展开面板时如何更改hide

我尝试使用TextLabelID="btnShowHideRequestComment" CollapsedText="Show" ExpandedText="Hide",但没有效果。

    <asp:Panel ID="pnlRequestCommentHistory" runat="server">
    <asp:GridView ID="gvwRequestCommentHistory" runat="server" 
        AutoGenerateColumns="False" CssClass="GridStyle" 
        DataSourceID="odsRequestCommentHistory">
        <Columns>
            <asp:BoundField DataField="Name" HeaderText="User" SortExpression="Name" />
            <asp:BoundField DataField="CommentDate" HeaderText="Date" 
                SortExpression="CommentDate" />
            <asp:BoundField DataField="Comment" HeaderText="Comment" 
                SortExpression="Comment" />
        </Columns>
        <AlternatingRowStyle CssClass="GridAlternateRowStyle" />
        <RowStyle CssClass="GridRowStyle" />
    </asp:GridView>
</asp:Panel>
<asp:CollapsiblePanelExtender ID="cpeRequestCommentHistory" runat="server"
TargetControlID="pnlRequestCommentHistory" CollapseControlID="btnShowHideRequestComment" ExpandControlID="btnShowHideRequestComment"
Collapsed="true" CollapsedSize="0" TextLabelID="btnShowHideRequestComment" CollapsedText="Show" ExpandedText="Hide">
</asp:CollapsiblePanelExtender>

1 个答案:

答案 0 :(得分:0)

我在here找到了以下解决方案:

protected void btnShowHideRequestComment_Click(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            if (btnShowHideRequestComment.Text == "Show")
                btnShowHideRequestComment.Text = "Hide";
            else
                btnShowHideRequestComment.Text = "Show";
        }
    }