我有两个隐藏和显示radgrid的图像按钮,具体取决于客户想要看到的内容。单击按钮时,grid.visible属性设置为true或false。问题是当我第一次点击按钮时,页面回发并且不起作用。然后我再点击几次,它只显示一条水平线(我假设它是网格不是数据绑定)。我再点击几次,网格显示并完美隐藏。但是,当用户离开页面然后返回到此页面时,我会遇到同样的问题。
任何帮助都将不胜感激。
的.aspx
<div class="RegistrationHistoryGrid" >
<telerik:RadGrid ID="rgRegistrationHistory" Width="100%" ShowHeader="true" AutoGenerateColumns="false" OnSelectedIndexChanged="rgRegistrationHistory_SelectedIndexChanged" AllowCustomPaging="true" AllowSorting="True" AllowPaging="True" PageSize="10" runat="server" Gridlines="None" CellSpacing="0" onneeddatasource="rgRegistrationHistory_OnNeedDataSource" >
<ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True" EnableRowHoverStyle="true" EnablePostBackOnRowClick="true">
<Selecting AllowRowSelect="True" />
</ClientSettings>
<MasterTableView Width="100%" Summary="RadGrid table" DataKeyNames="ClientID, LastName, FirstName, Gender,DateOfBirth,Address">
<Columns>
<telerik:GridBoundColumn HeaderText="Period" Reorderable="false" UniqueName="Period" DataField="Period"/>
<telerik:GridBoundColumn HeaderText="Plate" Reorderable="false" UniqueName="Plate" DataField="Plate"/>
<telerik:GridBoundColumn HeaderText="Comment" Reorderable="false" UniqueName="Comment" DataField="Comment"/>
</Columns>
<SortExpressions>
<telerik:GridSortExpression FieldName="LastName" SortOrder="Ascending" />
</SortExpressions>
</MasterTableView>
<PagerStyle Mode="NextPrevAndNumeric" />
<FilterMenu EnableImageSprites="False"></FilterMenu>
<HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default"></HeaderContextMenu>
</telerik:RadGrid>
</div>
的.cs
protected void rgRegistrationHistory_OnNeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
List<int> fakeList = new List<int>();
rgRegistrationHistory.DataSource = fakeList;
}
protected void imgChevronClosed_Click(object sender, ImageClickEventArgs e)
{
imgChevronOpen.Visible = true;
imgChevronClosed.Visible = false;
rgRegistrationHistory.Visible = false;
}
protected void imgChevronOpen_Click(object sender, ImageClickEventArgs e)
{
imgChevronOpen.Visible = false;
imgChevronClosed.Visible = true;
rgRegistrationHistory.Visible = true;
}
答案 0 :(得分:3)
切换其可见性时,必须重新绑定网格。有关此事,请参阅this article。
答案 1 :(得分:0)
您可以尝试合并逻辑,然后执行类似的操作:
标记:
<asp:ImageButton ID="imgToggleGrid" runat="server" ImageUrl="~/images/hide.png" OnClick="imgToggleGrid_Click" />
<asp:PlaceHolder ID="plcGrid" runat="server">
<!-- GRID -->
</asp:PlaceHolder>
代码隐藏:
protected void imgToggleGrid_Click(object sender, EventArgs e)
{
plcGrid.Visible = !plcGrid.Visible;
imgToggleGrid.ImageUrl = String.Format("~/images/{0}", plcGrid.Visible ? "hide.png" : "show.png");
}