VB.NET版的GridView经典使用(编辑,删除,分页,链接列)

前端之家收集整理的这篇文章主要介绍了VB.NET版的GridView经典使用(编辑,删除,分页,链接列)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

ProtectedSubPage_Load(ByValsenderAsObject,ByValeAsSystem.EventArgs)HandlesMe.Load
IfNotIsPostBackThen
binddata()
EndIf

EndSub

PublicSubbinddata()
'
EndSub

'编辑中
ProtectedSubGridView1_RowEditing(ByValsenderAsObject,ByValeAsSystem.Web.UI.WebControls.GridViewEditEventArgs)HandlesGridView1.RowEditing
GridView1.EditIndex
=e.NewEditIndex
'当前编辑行背景色高亮
GridView1.EditRowStyle.BackColor=Color.FromName("#F7CE90")
binddata()

EndSub

'分页
ProtectedSubGridView1_PageIndexChanging(ByValsenderAsObject,ByValeAsSystem.Web.UI.WebControls.GridViewPageEventArgs)HandlesGridView1.PageIndexChanging
GridView1.PageIndex
=e.NewPageIndex
binddata()
'重新绑定GridView数据的函数
EndSub

'更新
ProtectedSubGridView1_RowUpdating(ByValsenderAsObject,ByValeAsSystem.Web.UI.WebControls.GridViewUpdateEventArgs)HandlesGridView1.RowUpdating
DimclsBAsNewsqlDLTP.business
DimsqlstrAsString
DimdsAsNewDataSet
sqlstr
="selecthbdwnofrometsshbdwherehbdcnm='"&CType(GridView1.Rows(e.RowIndex).FindControl("TextBox1"),TextBox).Text.ToString().Trim()&"'"
ds
=clsB.queryitems(sqlstr)
DimwnoAsString=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

'取消
ProtectedSubGridView1_RowCancelingEdit(ByValsenderAsObject,ByValeAsSystem.Web.UI.WebControls.GridViewCancelEditEventArgs)HandlesGridView1.RowCancelingEdit
GridView1.EditIndex
=-1
binddata()
EndSub

'删除
ProtectedSubGridView1_RowDeleting(ByValsenderAsObject,ByValeAsSystem.Web.UI.WebControls.GridViewDeleteEventArgs)HandlesGridView1.RowDeleting
DimclsBAsNewsqlDLTP.business
DimsqlstrAsString
DimdsAsNewDataSet
sqlstr
="selecthbdwnofrometsshbdwherehbdcnm='"&CType(GridView1.Rows(e.RowIndex).FindControl("Label1"),Label).Text.ToString().Trim()&"'"
ds
=clsB.queryitems(sqlstr)
DimwnoAsString=ds.Tables(0).Rows(0)(0).ToString().Trim()

sqlstr
="deleteetsdlwheretrano="&GridView1.DataKeys(e.RowIndex).Value.ToString().Trim()&"andwno='"&wno&"'"
clsB.ExesqlCmd(sqlstr)
binddata()
EndSub

'绑定行,特效及链接属性分配等
ProtectedSubGridView1_RowDataBound(ByValsenderAsObject,ByValeAsSystem.Web.UI.WebControls.GridViewRowEventArgs)HandlesGridView1.RowDataBound
Ife.Row.RowType=DataControlRowType.DataRowThen

'鼠标经过时,行背景色变
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判断
Ife.Row.RowState=DataControlRowState.NormalOre.Row.RowState=DataControlRowState.AlternateThen

IfCType(e.Row.Cells(12).FindControl("Label11"),Label).Text="1"Then
CType(e.Row.Cells(12).FindControl("Label11"),Label).Text="在职"
EndIf
EndIf
EndIf
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 >
原文链接:https://www.f2er.com/vb/262713.html

猜你在找的VB相关文章