buttoncolumn问题,在各大论坛问了好几天了,还是解决不了,只有50分了

kwklover 2003-10-15 06:16:51
我在datagrid控件里有一个buttoncolumn,在它的OnItemCommand事件中
Sub DataGrid_ItemCommand(Sender As object,E as DataGridCommandEventArgs)
dim strNum as string=e.item.cells(1).text
lblShowText.Textt=strNum
End Sub
在没有按datagrid控件的上一页,下一页时候,它是运行正常的(即可以准确获得预定的值),但当我按“下一页”时就出现以下错误了:
指定的参数已超出有效值的范围。参数名:index
出错行:dim strNum as string=e.item.cells(1).text
不知道为什么会这样,请各位高手赐教了!万分感谢
...全文
106 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
kwklover 2003-10-15
  • 打赏
  • 举报
回复
问题解决了,谢谢各位了!!
saucer 2003-10-15
  • 打赏
  • 举报
回复
because when you click on "下一页", ItemComamnd is also triggered and e.Item is refers to the Pager(?), so you should give the button a command name and check for its value in your ItemCommand

<asp:ButtonColumn CommandName="MyButton" ...


Sub DataGrid_ItemCommand(Sender As object,E as DataGridCommandEventArgs)
If CType(e.CommandSource, Button).CommandName = "MyButton" Then 'or
'If CType(e.CommandSource, LinkButton).CommandName = "MyButton" Then
dim strNum as string=e.item.cells(1).text
lblShowText.Textt=strNum
end if
End Sub
kwklover 2003-10-15
  • 打赏
  • 举报
回复
这个的分页应该没有问题
因为我把这个OnItemCommand事件的代码去掉,分页就一点问题都没有
webdiyer 2003-10-15
  • 打赏
  • 举报
回复
你没有判断DataGridItem的类型,不会写vb.net的代码,把你的改成C#的:

void DataGrid_ItemCommand(object Sender,DataGridCommandEventArgs e){
if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem){
string strNum=e.Item.Cells[1].Text;
}
}
ahui_net 2003-10-15
  • 打赏
  • 举报
回复
datagrid的页是从0开始的
返回给你的页数是从1 开始的

62,039

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧