用LinkButton控制GridView数据分页显示问题
aspx中设置GridView的AllowPaging="true",PagerSetting-Visible="false",然后再添加四个LinkButton按钮,设...
aspx中设置GridView的AllowPaging="true",PagerSetting-Visible="false",然后再添加四个LinkButton按钮,设置CommandName=Page,CommandAugement分别设置为First,Perv,Next,Last.然后给CommandAugement=Last的LinkButton添加Command事件,事件代码如下.
protected void LinkButtonLast_Command(object sender, CommandEventArgs e)
{
//switch(((LinkButton)sender).CommandArgument.ToString().ToLower())
switch (e.CommandArgument.ToString().ToLower())
{
case "first":
GridView1.PageIndex = 0;
LinkButtonFirst.Visible = false;
LinkButtonPrevious.Visible = false;
LinkButtonNext.Visible = true;
LinkButtonLast.Visible = true;
break;
case "prev":
GridView1.PageIndex = GridView1.PageIndex - 1;
if (GridView1.PageIndex == 0)
{
LinkButtonFirst.Visible = false;
LinkButtonPrevious.Visible = false;
LinkButtonNext.Visible = true;
LinkButtonLast.Visible = true;
}
else
{
LinkButtonFirst.Visible = true;
LinkButtonPrevious.Visible = true;
LinkButtonNext.Visible = true;
LinkButtonLast.Visible = true;
}
break;
case "next":
GridView1.PageIndex = GridView1.PageIndex + 1;
if (GridView1.PageIndex == GridView1.PageCount - 1)
{
LinkButtonFirst.Visible = true;
LinkButtonPrevious.Visible = true;
LinkButtonNext.Visible = false;
LinkButtonLast.Visible = false;
}
else
{
LinkButtonFirst.Visible = true;
LinkButtonPrevious.Visible = true;
LinkButtonNext.Visible = true;
LinkButtonLast.Visible = true;
}
break;
case "last":
GridView1.PageIndex = GridView1.PageCount - 1;
LinkButtonFirst.Visible = true;
LinkButtonPrevious.Visible = true;
LinkButtonNext.Visible = false;
LinkButtonLast.Visible = false;
break;
}
}
此代码除点击CommandAugement=Last的LinkButton有响应外,其它一概无效.给各按钮添加Clik事件,并把相应的方法添加进去完全好用.以上代码哪里写的不妥呢?请高人指点,小猫儿先在此谢过! 展开
protected void LinkButtonLast_Command(object sender, CommandEventArgs e)
{
//switch(((LinkButton)sender).CommandArgument.ToString().ToLower())
switch (e.CommandArgument.ToString().ToLower())
{
case "first":
GridView1.PageIndex = 0;
LinkButtonFirst.Visible = false;
LinkButtonPrevious.Visible = false;
LinkButtonNext.Visible = true;
LinkButtonLast.Visible = true;
break;
case "prev":
GridView1.PageIndex = GridView1.PageIndex - 1;
if (GridView1.PageIndex == 0)
{
LinkButtonFirst.Visible = false;
LinkButtonPrevious.Visible = false;
LinkButtonNext.Visible = true;
LinkButtonLast.Visible = true;
}
else
{
LinkButtonFirst.Visible = true;
LinkButtonPrevious.Visible = true;
LinkButtonNext.Visible = true;
LinkButtonLast.Visible = true;
}
break;
case "next":
GridView1.PageIndex = GridView1.PageIndex + 1;
if (GridView1.PageIndex == GridView1.PageCount - 1)
{
LinkButtonFirst.Visible = true;
LinkButtonPrevious.Visible = true;
LinkButtonNext.Visible = false;
LinkButtonLast.Visible = false;
}
else
{
LinkButtonFirst.Visible = true;
LinkButtonPrevious.Visible = true;
LinkButtonNext.Visible = true;
LinkButtonLast.Visible = true;
}
break;
case "last":
GridView1.PageIndex = GridView1.PageCount - 1;
LinkButtonFirst.Visible = true;
LinkButtonPrevious.Visible = true;
LinkButtonNext.Visible = false;
LinkButtonLast.Visible = false;
break;
}
}
此代码除点击CommandAugement=Last的LinkButton有响应外,其它一概无效.给各按钮添加Clik事件,并把相应的方法添加进去完全好用.以上代码哪里写的不妥呢?请高人指点,小猫儿先在此谢过! 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询