VB.NET版的GridView经典使用…

VB.NET版的GridView经典使用…,第1张

概述常用控件 原文地址:VB.NET版的GridView经典使用(编辑,删除,分页,鼠标行颜色变化、链接列) 作者:吴培洪 Protected   Sub  Page_Load( ByVal  sender  As   Object ,  ByVal  e  As  System.EventArgs)  Handles   Me .Load          If   Not  IsPostBack  常用控件 原文地址: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 > 总结

以上是内存溢出为你收集整理的VB.NET版的GridView经典使用…全部内容,希望文章能够帮你解决VB.NET版的GridView经典使用…所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1271297.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-08
下一篇 2022-06-08

发表评论

登录后才能评论

评论列表(0条)

保存