VB.NET版的GridView经典使用(编辑,删除,分页,链接列)
来源:互联网 发布:网上淘宝店铺转让 编辑:程序博客网 时间:2024/04/30 10:08
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
binddata()
End If
End Sub
Public Sub binddata()
'
End Sub
'编辑中
Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing
GridView1.EditIndex = e.NewEditIndex
'当前编辑行背景色高亮
GridView1.EditRowStyle.BackColor = Color.FromName("#F7CE90")
binddata()
End Sub
'分页
Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
GridView1.PageIndex = e.NewPageIndex
binddata() '重新绑定GridView数据的函数
End Sub
'更新
Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
Dim clsB As New sqlDLTP.business
Dim sqlstr As String
Dim ds As New DataSet
sqlstr = "select hbdwno from etsshbd where hbdcnm='" & CType(GridView1.Rows(e.RowIndex).FindControl("TextBox1"), TextBox).Text.ToString().Trim() & "'"
ds = clsB.queryitems(sqlstr)
Dim wno As String = ds.Tables(0).Rows(0)(0).ToString().Trim()
sqlstr = "update etsdl set okscore1='" & _
CType(GridView1.Rows(e.RowIndex).FindControl("TextBox6"), TextBox).Text.ToString().Trim() & "',okscore2='" & _
CType(GridView1.Rows(e.RowIndex).FindControl("TextBox7"), TextBox).Text.ToString().Trim() & "',okscore='" & _
CType(GridView1.Rows(e.RowIndex).FindControl("TextBox8"), TextBox).Text.ToString().Trim() & "',okreport='" & _
CType(GridView1.Rows(e.RowIndex).FindControl("TextBox9"), TextBox).Text.ToString().Trim() & "',okgrad='" & _
CType(GridView1.Rows(e.RowIndex).FindControl("TextBox10"), TextBox).Text.ToString().Trim() & "',memo='" & _
CType(GridView1.Rows(e.RowIndex).FindControl("TextBox12"), TextBox).Text.ToString().Trim() & "' where trano='" & _
GridView1.DataKeys(e.RowIndex).Value.ToString() & "' and wno='" & wno & "'"
clsB.ExeSqlCmd(sqlstr)
GridView1.EditIndex = -1
binddata()
End Sub
'取消
Protected Sub GridView1_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GridView1.RowCancelingEdit
GridView1.EditIndex = -1
binddata()
End Sub
'删除
Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting
Dim clsB As New sqlDLTP.business
Dim sqlstr As String
Dim ds As New DataSet
sqlstr = "select hbdwno from etsshbd where hbdcnm='" & CType(GridView1.Rows(e.RowIndex).FindControl("Label1"), Label).Text.ToString().Trim() & "'"
ds = clsB.queryitems(sqlstr)
Dim wno As String = ds.Tables(0).Rows(0)(0).ToString().Trim()
sqlstr = "delete etsdl where trano=" & GridView1.DataKeys(e.RowIndex).Value.ToString().Trim() & "and wno='" & wno & "'"
clsB.ExeSqlCmd(sqlstr)
binddata()
End Sub
'绑定行,特效及链接列属性分配等
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
'鼠标经过时,行背景色变
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'")
'鼠标移出时,行背景色变
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'")
' HyperLink列给链接值
CType(e.Row.Cells(1).FindControl("HyperLink1"), HyperLink).NavigateUrl = "javascript:void window.open('trashow.aspx?tno=" + CType(e.Row.Cells(1).FindControl("HyperLink1"), HyperLink).Text + "','', 'left='+(window.top.screen.width-454)/2+',top='+(window.top.screen.height-454)/2+',width=625,height=500,scrollbars=yes,resizeable=yes');"
'当有编辑列时,避免出错,要加的RowState判断
If e.Row.RowState = DataControlRowState.Normal Or e.Row.RowState = DataControlRowState.Alternate Then
If CType(e.Row.Cells(12).FindControl("Label11"), Label).Text = "1" Then
CType(e.Row.Cells(12).FindControl("Label11"), Label).Text = "在职"
End If
End If
End If
End Sub
前台:
<!-- -->
</asp:GridView>
- VB.NET版的GridView经典使用(编辑,删除,分页,链接列)
- VB.NET版的GridView经典使用…
- Asp.Net[C#] 使用GridView 分页,编辑,删除,导出XML完整页面
- ASP.NET GridView用法(二) 模板,脚注,排序,编辑,删除,多选,分页,添加
- 自定义GRIDVIEW编辑列 删除列
- GridView控件的排序、删除、编辑、分页等问题
- GridView 的编辑删除
- GridView动态添加模板列(VB.NET版)
- GridView实现编辑,选择删除,分页功能
- 使用GridView的模板列实现在线编辑的功能
- GridView的编辑、新增、删除
- GridView的编辑删除代码
- 【轉】VB.NET gridview使用
- .net GridView数据行 删除,编辑
- Asp.net:GridView中的编辑 删除
- GridView那点事之【内置的删除、编辑使用】
- asp.net之DataList的使用方法,及分页(存储过程创建),编辑,更新,删除
- asp.net之DataList的使用方法,及分页(存储过程创建),编辑,更新,删除
- 在C#中操作XML I
- 常用的javascript小技巧
- 程序员创业失败主要原因
- Happiness Is A Journey
- 在C#中操作XM II
- VB.NET版的GridView经典使用(编辑,删除,分页,链接列)
- 解决smarty的 invalid attribute name 问题
- 定义可延迟(deferrable)的约束
- C++好网站及其他网站收录(转载)
- 在VC++下对文件属性的获取与更改
- Java 读取 JPEG 文件的 exif 信息
- spring 控制jsf managedBean
- xml 增 删 改 查
- Ogre的UML图(一)