加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

VB.NET版的GridView经典使用…

发布时间:2020-12-17 07:49:25 所属栏目:百科 来源:网络整理
导读:常用控件 原文地址: VB.NET版的GridView经典使用(编辑,删除,分页,鼠标行颜色变化、链接列) 作者: 吴培洪 Protected Sub Page_Load( ByVal sender As Object , ByVal e As System.EventArgs) Handles Me .Load If Not IsPostBack Then binddata() End
常用控件
原文地址:VB.NET版的GridView经典使用(编辑,删除,分页,鼠标行颜色变化、链接列) 作者:吴培洪
Protected Sub Page_Load( ByVal sender As Object , ByVal e As System.EventArgs) Handles Me .Load
If Not IsPostBack Then
binddata()
End If

EndSub

Public Sub binddata()
'
EndSub

' 编辑中
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()

EndSub

' 分页
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数据的函数
EndSub

' 更新
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
= " selecthbdwnofrometsshbdwherehbdcnm=' " & 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
= " updateetsdlsetokscore1=' " & _
CType (GridView1.Rows(e.RowIndex).FindControl( " TextBox6 " ),TextBox).Text.ToString().Trim() & " ',okscore2=' " & _
CType (GridView1.Rows(e.RowIndex).FindControl( " TextBox7 " ),okscore=' " & _
CType (GridView1.Rows(e.RowIndex).FindControl( " TextBox8 " ),okreport=' " & _
CType (GridView1.Rows(e.RowIndex).FindControl( " TextBox9 " ),okgrad=' " & _
CType (GridView1.Rows(e.RowIndex).FindControl( " TextBox10 " ),memo=' " & _
CType (GridView1.Rows(e.RowIndex).FindControl( " TextBox12 " ),TextBox).Text.ToString().Trim() & " 'wheretrano=' " & _
GridView1.DataKeys(e.RowIndex).Value.ToString()
& " 'andwno=' " & wno & " ' "
clsB.ExeSqlCmd(sqlstr)
GridView1.EditIndex
= - 1
binddata()
EndSub

' 取消
Protected Sub GridView1_RowCancelingEdit( ByVal sender As Object , ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GridView1.RowCancelingEdit
GridView1.EditIndex
= - 1
binddata()
EndSub

' 删除
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
= " selecthbdwnofrometsshbdwherehbdcnm=' " & 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
= " deleteetsdlwheretrano= " & GridView1.DataKeys(e.RowIndex).Value.ToString().Trim() & " andwno=' " & wno & " ' "
clsB.ExeSqlCmd(sqlstr)
binddata()
EndSub

' 绑定行,特效及链接列属性分配等
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:voidwindow.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
EndSub


前台:
< asp:GridView ID ="GridView1" runat ="server" AutoGenerateColumns ="False" Width =100% BackColor ="White" BorderColor ="White" BorderStyle ="Ridge" BorderWidth ="2px" CellPadding ="3" CellSpacing ="1" GridLines ="None" AllowPaging ="True" AllowSorting ="True" >
<!-- -->
</ asp:GridView >

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读