设置Gridview,Repter...中的linkbutton按钮不可用
2012-12-03 14:35
288 查看
假设在Gridview中的分页控件中有linkbutton:
设置了当在首页的时候:“首页”,“第一页”不可点击,虽然按钮已经禁用了!
但事实上:他还是可以点击的,不信你试试!!!
经过调试:发现LinkButton首页 lnkFirstPage的OnClientClick居然还有值!
解决办法:在Gridview的_gvGuest_RowDataBound让OnClientClick为空就行了!
LinkButton lnkFirstPage = e.Row.FindControl("lnkFirstPage") as LinkButton;
if (lnkFirstPage.Enabled == false)
lnkFirstPage.OnClientClick = "";
if (e.Row.RowType == DataControlRowType.Pager)
{
LinkButton lnkFirstPage = e.Row.FindControl("lnkFirstPage") as LinkButton;
if (lnkFirstPage.Enabled == false)
lnkFirstPage.OnClientClick = "";
LinkButton lnkUpPage = e.Row.FindControl("lnkUpPage") as LinkButton;
if (lnkUpPage.Enabled == false)
lnkUpPage.OnClientClick = "";
LinkButton lnkDownPage = e.Row.FindControl("lnkDownPage") as LinkButton;
if (lnkDownPage.Enabled == false)
lnkDownPage.OnClientClick = "";
LinkButton lnkLastPage = e.Row.FindControl("lnkLastPage") as LinkButton;
if (lnkLastPage.Enabled == false)
lnkLastPage.OnClientClick = "";
}
<PagerTemplate> 当前第:<asp:Label ID="lblCurrentPage" runat="server" Text="<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>"> </asp:Label>页 | 一共: <asp:Label ID="lblAllPage" runat="server" Text="<%#((GridView)Container.Parent.Parent).PageCount %>"></asp:Label>页 <asp:LinkButton ID="lnkFirstPage" runat="server" OnClientClick="return clearData();" CommandName="Page" CommandArgument="First" Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex != 0 %>">第一页</asp:LinkButton> <asp:LinkButton ID="lnkUpPage" runat="server" OnClientClick="return clearData();" CommandName="Page" CommandArgument="Prev" Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex != 0 %>">上一页</asp:LinkButton> <asp:LinkButton ID="lnkDownPage" runat="server" OnClientClick="return clearData();" CommandName="Page" CommandArgument="Next" Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex != ((GridView)Container.Parent.Parent).PageCount - 1 %>">下一页</asp:LinkButton> <asp:LinkButton ID="lnkLastPage" runat="server" OnClientClick="return clearData();" CommandName="Page" CommandArgument="Last" Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex != ((GridView)Container.Parent.Parent).PageCount - 1 %>">最后一页</asp:LinkButton> 跳转到: <asp:TextBox ID="txtNeedPage" Width="20px" runat="server" onkeyup='value=value.replace(/[^\d]/g,"") ' onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" Text="<%#((GridView)Container.Parent.Parent).PageIndex + 1 %>"></asp:TextBox> <asp:LinkButton ID="lnkGoto" runat="server" CommandName="Page" OnClientClick="return clearData();" CommandArgument="-2">Go</asp:LinkButton> 跳转到: <asp:DropDownList ID="ddlNeedPage" runat="server" onchange="javascript:selectChange();" AutoPostBack="true" OnSelectedIndexChanged="ddlNeedPage_SelectedIndexChanged"> </asp:DropDownList> </PagerTemplate>
设置了当在首页的时候:“首页”,“第一页”不可点击,虽然按钮已经禁用了!
但事实上:他还是可以点击的,不信你试试!!!
经过调试:发现LinkButton首页 lnkFirstPage的OnClientClick居然还有值!
解决办法:在Gridview的_gvGuest_RowDataBound让OnClientClick为空就行了!
LinkButton lnkFirstPage = e.Row.FindControl("lnkFirstPage") as LinkButton;
if (lnkFirstPage.Enabled == false)
lnkFirstPage.OnClientClick = "";
if (e.Row.RowType == DataControlRowType.Pager)
{
LinkButton lnkFirstPage = e.Row.FindControl("lnkFirstPage") as LinkButton;
if (lnkFirstPage.Enabled == false)
lnkFirstPage.OnClientClick = "";
LinkButton lnkUpPage = e.Row.FindControl("lnkUpPage") as LinkButton;
if (lnkUpPage.Enabled == false)
lnkUpPage.OnClientClick = "";
LinkButton lnkDownPage = e.Row.FindControl("lnkDownPage") as LinkButton;
if (lnkDownPage.Enabled == false)
lnkDownPage.OnClientClick = "";
LinkButton lnkLastPage = e.Row.FindControl("lnkLastPage") as LinkButton;
if (lnkLastPage.Enabled == false)
lnkLastPage.OnClientClick = "";
}
相关文章推荐
- easyui按钮linkbutton 设置可用/不可用
- 给 GridView 的 LinkButton 删除按钮添加弹出层的确认删除对话框
- mfc关于CButtonST按钮设置不可用时,按钮变灰
- 关于CButtonST按钮设置不可用时设置按钮图标
- WebForm GridView设置分页,编辑,更新,取消,删除,按钮,以及排序。
- 给 GridView 的 LinkButton 删除按钮添加弹出层的确认删除对话框
- jQuery设置单选按钮radio选中/不可用的实例代码
- Mfc中设置按钮不可用
- jquery设置按钮停顿3秒不可用
- ASPxGridView-根据记录值来控制命令按钮(CommandButton)或子表命令列(CommandColumn)的显示与可用
- cocos2d 设置按钮不可用
- 设置倒计时10秒可用的按钮JS函数(转)
- [Android] 设置AlertDialog中按钮的可用(Enable)状态
- easyui按钮linkbutton 不可用(置灰)与 可用(取消置灰)
- (界面笔记之二十七)设置按钮图标可用不可用的图标显示(CBitmapButton的使用)
- 扩展GridView控件(3) - 根据按钮的CommandName设置其客户端属性
- JS设置 按钮为可用和不可用两种状态
- 扩展GridView控件(3) - 根据按钮的CommandName设置其客户端属性
- matlab寻找另一个界面的句柄、设置初始左上角的logo、按钮不可用
- jquery easyui-linkButton获取和设置按钮text并且解决火狐不支持innerText的方法