我在第2页删除第2行,可是第1页的第2行被删除
i=e.item.ItemIndex
Dim DRow as DataRow
DRow=myDS.Tables(0).Rows(i)
Dim a1 as string=DRow("num").Trim()
Dim a2 as string=DRow("name").Trim()
我知道是i的问题,大家告诉我如何能解决啊,只要成功立刻给分,先来先给

解决方案 »

  1.   

    不要用ItemIndex去删除,用DataKey
      

  2.   

    datakey怎么用啊,能给举个例子吗
      

  3.   

    前台设定DataGrid
    DataKeyField="ID"
    后台
    DataGrid1.DataKeys[e.Item.ItemIndex]
      

  4.   

    datagrid1.DataKeyField="ID"
    i=datagrid1.DataKeys[e.Item.Itemindex]
    Dim DRow as DataRow
    DRow=myDS.Tables(0).Rows(i)
    Dim a1 as string=DRow("yourname").Trim()
    Dim a2 as string=DRow("yourkey").Trim()
    我这么写出现错误
    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: BC30203: Identifier expected
      

  5.   

    i=datagrid1.DataKeys[e.Item.Itemindex]改成i=datagrid1.DataKeys(e.Item.Itemindex)后
    出现错误
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: indexSource
      

  6.   

    datagrid1.DataKeyField="ID"
    i=datagrid1.DataKeys[e.Item.Itemindex]
    Dim DRow as DataRow
    DRow=myDS.Tables(0).Rows(i)
    Dim a1 as string=DRow("yourname").Trim()
    Dim a2 as string=DRow("yourkey").Trim()
    我这么写出现错误你这么写有问题的,看你的这行代码:i=datagrid1.DataKeys[e.Item.Itemindex]
    不能使用[]这个的!
      

  7.   

    我换成小括号就是这个错误
    出现错误
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

    这句放到DataKeyField="ID"前台中设定错误也是一样的
      

  8.   

    说你的索引出错了
    你使用断点看看
    e.Item.ItemIndex
    i=datagrid1.DataKeys(e.Item.ItemIndex)
    这两个值是多少
      

  9.   

    使用的前提是你在DATAGRID绑定事件中,要设定关键字段
    DataGrid.DataSource = 求取到的数据集
    DataGrid.DataKeyField = "xxx_id"
    DataGrid.DataBind()
    然后求取的时候才能使用DataKeys
    dim i as string = DataGrid.DataKeys[e.Item.Itemindex].toString()