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"),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() & "' 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 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使用所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)