两个网格问题。点击第二个网格删除行第一个网格数据后我输了 [英] Two grids problem. After clicking second grid delete row first grid data i am losing

查看:73
本文介绍了两个网格问题。点击第二个网格删除行第一个网格数据后我输了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

If ViewState("CurrentTable") IsNot Nothing Then
           Dim dt As DataTable = DirectCast(ViewState("CurrentTable"), DataTable)
           Dim dtCurrentTable As DataTable = New DataTable()
           dtCurrentTable = CType(ViewState("CurrentTable"), DataTable)
           If (dt.Rows.Count > 0) Then
               If (dt.Rows.Count = 1) Then

                   Dim Cnt, Rowcnt As Integer
                   Rowcnt = GridView4.Rows.Count
                   Dim introwindex As Integer
                   For Cnt = 0 To Rowcnt
                       If (Cnt = introwindex) Then
                           Dim box1 As TextBox = DirectCast(GridView4.Rows(Cnt).Cells(1).FindControl("TextBox1"), TextBox)
                           Dim box2 As TextBox = DirectCast(GridView4.Rows(Cnt).Cells(2).FindControl("TextBox2"), TextBox)
                           Dim box3 As TextBox = DirectCast(GridView4.Rows(Cnt).Cells(3).FindControl("TextBox3"), TextBox)
                           Dim ddl3 As DropDownList = DirectCast(GridView4.Rows(Cnt).Cells(3).FindControl("DropDownList2"), DropDownList)

                           FillDropDownList(ddl3)
                           ddl3.ClearSelection()

                           box1.Text = String.Empty
                           box2.Text = String.Empty
                           box3.Text = String.Empty

                           ddl3.Items.FindByText("Select").Selected = True

                       End If
                   Next
                   Exit Sub
                 Exit Sub
               End If
               Dim d As Integer = dtCurrentTable.Rows.Count
               Dim RowIndex111 As Integer = e.RowIndex
               dtCurrentTable.Rows(RowIndex111).Delete()
               dtCurrentTable.AcceptChanges()
               dtCurrentTable = CType(ViewState("CurrentTable"), DataTable)
           End If
           GridView4.DataSource = dtCurrentTable
           GridView4.DataBind()


           For i As Integer = 0 To dt.Rows.Count - 1
               If (dt.Rows(i)("Sno").ToString <> "") Then
                   dt.Rows(i)("Sno") = i + 1

                   dt.AcceptChanges()
                   dtCurrentTable = CType(ViewState("CurrentTable"), DataTable)
                   Dim s As Integer = 1
               End If

           Next
           GridView4.DataSource = dtCurrentTable
           GridView4.DataBind()
           SetPreviousData()
       End If



首先是网格删除编码。下面是第二个网格编码的删除行。


Above first grid delete coding. Below one delete row of second grid coding.

If ViewState("Grid4") IsNot Nothing Then
           Dim dt1 As DataTable = DirectCast(ViewState("Grid4"), DataTable)
           Dim dtCurrentTable1 As DataTable = New DataTable()
           dtCurrentTable1 = CType(ViewState("Grid4"), DataTable)
           If (dt1.Rows.Count > 0) Then
               If (dt1.Rows.Count = 1) Then

                   Dim Cnt, Rowcnt As Integer
                   Rowcnt = GridView4.Rows.Count
                   Dim introwindex As Integer
                   For Cnt = 0 To Rowcnt
                       If (Cnt = introwindex) Then
                           Dim ddl3 As DropDownList = DirectCast(GridView5.Rows(Cnt).Cells(1).FindControl("DropDownList3"), DropDownList)
                           Dim box6 As TextBox = DirectCast(GridView5.Rows(Cnt).Cells(1).FindControl("TextBox6"), TextBox)

                           FillDropDownList1(ddl3)
                           ddl3.ClearSelection()

                           box6.Text = String.Empty
                           ddl3.Items.FindByText("Select").Selected = True

                       End If
                   Next
                   Exit Sub
                   'Exit Sub
               End If
               Dim d As Integer = dtCurrentTable1.Rows.Count
               Dim RowIndex111 As Integer = e.RowIndex
               dtCurrentTable1.Rows(RowIndex111).Delete()
               dtCurrentTable1.AcceptChanges()
               dtCurrentTable1 = CType(ViewState("Grid4"), DataTable)
           End If
           GridView5.DataSource = dtCurrentTable1
           GridView5.DataBind()


           For i As Integer = 0 To dt.Rows.Count - 1
               If (dt1.Rows(i)("Sno").ToString <> "") Then
                   dt1.Rows(i)("Sno") = i + 1

                   dt1.AcceptChanges()
                   dtCurrentTable1 = CType(ViewState("Grid4"), DataTable)
                   Dim s As Integer = 1
               End If

           Next
           GridView5.DataSource = dtCurrentTable1
           GridView5.DataBind()
           ' SetPreviousData1()
       End If

任何信息我犯了什么错误。

Any information plz what i had done the mistake.

推荐答案

这里实际发生的事情是删除点击你的页面正在刷新,因此网格视图中的数据1迷路了。 />


解决方案1 ​​

您可以在更新面板中放置第二个网格视图



解决方案2

尝试在删除操作完成后再次绑定第一个gridview。



解决方案3

尝试在页面加载事件上绑定网格视图。
what actually happening here is on delete click your page is getting refreshed and hence Data in Grid view 1 get lost .

solution 1
you can put second grid view in update panel

solution 2
try to bind your first gridview again as soon as your delete operation gets completed.

solution 3
try to bind your grid view on page load event.


这篇关于两个网格问题。点击第二个网格删除行第一个网格数据后我输了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆