DataGrid怎么在删除的时候不会自己刷新页面???DataGrid重新fill了一次,为什么会增加一倍了???
DataGrid怎么在删除的时候不会自己刷新页面???DataGrid重新fill了一次,为什么会增加一倍了??? 问题点数:20、回复次数:11Top
1 楼hackate(兰花开香入梦境,独思佳人亦飘然!!)回复于 2005-04-04 21:06:13 得分 10
Public Class index
Inherits System.Web.UI.Page
#Region " Web 窗体设计器生成的代码 "
'该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
'注意: 以下占位符声明是 Web 窗体设计器所必需的。
'不要删除或移动它。
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub
#End Region
Dim conn As SqlClient.SqlConnection
Dim cmd As SqlClient.SqlCommand
Dim ds As DataSet = New DataSet
Dim mycmd As SqlClient.SqlDataAdapter
Dim strsql As String
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
conn = New SqlClient.SqlConnection(ConfigurationSettings.AppSettings("shujuku"))
If Not IsPostBack Then
binddatagrid()
End If
'在此处放置初始化页的用户代码
End Sub
Private Sub DataGrid1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGrid1.SelectedIndexChanged
Dim StrN As Integer
StrN = DataGrid1.SelectedIndex + 1
Response.Write("<script>alert('是你选择了第 " & StrN & " 列!');</script>")
'Page.RegisterStartupScript("selChan", "<script>alert(""" & DataGrid1.Items(DataGrid1.SelectedIndex).Cells(3).Text & """)</script>")
End Sub
Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
DataGrid1.CurrentPageIndex = e.NewPageIndex
DataGrid1.DataBind()
binddatagrid()
End Sub
Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.EditCommand
DataGrid1.EditItemIndex = e.Item.ItemIndex
binddatagrid()
End Sub
Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.UpdateCommand
Dim intid As Integer
Dim txtbt As TextBox
'Dim txtpstime As TextBox
Dim strbt As String
'Dim dtpstime As DateTime
intid = DataGrid1.DataKeys(e.Item.ItemIndex)
txtbt = e.Item.Cells(1).Controls(0)
strbt = txtbt.Text
'Response.Write("<script>alert('是" & strbt & "');</script>")
strsql = "update wenzhang set bt=@bt where id=@id"
cmd = New SqlClient.SqlCommand(strsql, conn)
cmd.Parameters.Add("@bt", strbt)
cmd.Parameters.Add("@id", intid)
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
DataGrid1.EditItemIndex = -1
binddatagrid()
End Sub
Private Sub binddatagrid()
'cmd = New SqlClient.SqlCommand("select * from wenzhang", conn)
'mycmd = New SqlClient.SqlDataAdapter("select id,bt,pstime from wenzhang order by id desc", conn)
mycmd = New SqlClient.SqlDataAdapter("aspx_adminlist", conn)
mycmd.SelectCommand.CommandType = CommandType.StoredProcedure
conn.Open()
mycmd.Fill(ds)
DataGrid1.DataSource = New DataView(ds.Tables(0))
'DataGrid1.DataSource = cmd.ExecuteReader()
DataGrid1.DataBind()
conn.Close()
Dim item As DataGridItem
For Each item In DataGrid1.Items
item.Attributes.Add("onmousemove", "javascript:this.bgColor='#f2f7f9'")
item.Attributes.Add("onmouseout", "javascript:this.bgColor='#ffffff'")
Next
End Sub
Private Sub DataGrid1_CancelCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.CancelCommand
DataGrid1.EditItemIndex = -1
binddatagrid()
End Sub
Private Sub DataGrid1_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.DeleteCommand
If DataGrid1.DeleteCommandName = "Delete" Then
Dim delid As Integer
delid = DataGrid1.DataKeys(e.Item.ItemIndex)
cmd = New SqlClient.SqlCommand("delete from wenzhang where id=@id", conn)
cmd.Parameters.Add("@id", delid)
conn.Open()
cmd.ExecuteNonQuery()
cmd.Dispose()
conn.Close()
Response.Write("<script>alert('删除第" & e.Item.ItemIndex & "行成功!');</script>")
binddatagrid()
End If
'If (MyDataGrid.CurrentPageIndex >= Me.MyDataGrid.PageCount - 1 And MyDataGrid.CurrentPageIndex <> 0) Then '判断
'MyDataGrid.CurrentPageIndex = MyDataGrid.CurrentPageIndex - 1
'End If
'OpenDataBase_BindToDataGrid()
'此些乃至分页删除遇到问题解决方式!
End Sub
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
Select Case e.Item.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem
e.Item.Attributes.Add("OnClick", Page.GetPostBackClientEvent(e.Item.Cells(3).Controls(0), String.Empty))
End Select
'Response.Write("<script>alert('谁快捏');</script>")
'Dim links As LinkButton
'links = e.Item.FindControl("shanchu")
'links.Attributes.Add("onclick", "javascript:{if(confirm('确定删除用户吗?')==false) return false;}")
'btn.Attributes("onclick") = "javascript:{if(confirm('确定删除用户吗?')==false) return false;}"
End Sub
Private Sub DataGrid1_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemCreated
Select Case e.Item.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem
Dim links As LinkButton
links = e.Item.FindControl("shanchu")
links.Attributes.Add("onclick", "javascript:{if(confirm('确定删除用户吗?')==false) return false;}")
End Select
End Sub
End Class
Top
2 楼hackate(兰花开香入梦境,独思佳人亦飘然!!)回复于 2005-04-04 21:06:26 得分 0
你可以参考一下我的代码Top
3 楼mmwban2005(fa)回复于 2005-04-04 21:19:57 得分 0
好的,谢Top
4 楼lau_marco(青苹果)回复于 2005-04-04 21:28:52 得分 0
删除时,请重新绑定数据源的
Top
5 楼softchao(小款※人生就像大便, 往往努力了半天却只迸出几个屁 )回复于 2005-04-04 21:34:12 得分 5
回复人: hackate(~兰心*-*寒~ | 网站: http://www.7to.net) ( ) 信誉:100 2005-04-04 21:06:00 得分: 0
================================
姐姐,那么长,别人怎么看啊!晕~~ 被你BS一下也不怕!呵呵~~~
================
回答问题:
1.删除后重新调用绑定!
2.楼主:不懂你的DG是怎么FILL的!DG只是个UI的表示!你具体的数据源到底是来至什么??DataSet??datatable??Top
6 楼mmwban2005(fa)回复于 2005-04-04 21:41:39 得分 0
我重新fill了一次,为什么记录会增多??
不是说会覆盖原来的记录的嘛???Top
7 楼sword222()回复于 2005-04-04 21:52:39 得分 3
删除后,再重新绑定,很简单的Top
8 楼king4th0(壮壮)回复于 2005-04-04 22:17:25 得分 2
删除->绑定Top
9 楼softchao(小款※人生就像大便, 往往努力了半天却只迸出几个屁 )回复于 2005-04-04 22:20:39 得分 0
不应该出现你说的这种情况!(说的不对的请指正:)
个人看法:
1.首先你是NEW的一个新的对象!那么填充到一个新的对象是不可能出现你这种情况的!
解决办法:
2.实在是没办法你可以在每次填充前都清空一次容器!Top
10 楼softchao(小款※人生就像大便, 往往努力了半天却只迸出几个屁 )回复于 2005-04-04 22:21:58 得分 0
我重新fill了一次,为什么记录会增多??
不是说会覆盖原来的记录的嘛???
=================>
你重新FILL到什么里面!>???Top
11 楼poseidonliu(波塞冬)回复于 2005-04-05 16:56:21 得分 0
markTop




