【Vegas原创】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

    
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  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操作DataGridView控件的用法的集合,包括: 1. DataGridView当前的单元格属性取得、变更 2. DataGridView编辑属性 3. DataGridView最下面一新追加行非表示 4. DataGridView判断当前选中行是否为新追加的行 5. DataGridView删除行可否设定 6. DataGridView不表示和删除 DataGridView控件用法合集(二) 7. DataGridView宽度高度设置为不能编辑 8. DataGridView行高幅自动调整 9. DataGridView指定行冻结 10. DataGridView顺序变更可否设定 11. DataGridView行复数选择 12. DataGridView选择的行、、单元格取得 DataGridView控件用法合集(三) 13. DataGridView指定单元格是否表示 14. DataGridView表头部单元格取得 15. DataGridView表头部单元格文字设定 16. DataGridView选择的部分拷贝至剪贴板 17.DataGridView粘贴 18. DataGridView单元格上ToolTip表示设定(鼠标移动到相应单元格上时,弹出说明信息) DataGridView控件用法合集(四) 19. DataGridView中的ContextMenuStrip属性 20. DataGridView指定滚动框位置 21. DataGridView手动追加 22. DataGridView全体分界线样式设置 23. DataGridView根据单元格属性更改显示内容 24. DataGridView新追加行的行高样式设置る 25. DataGridView新追加行单元格默认值设置 DataGridView中输入错误数据的处理(五) 26. DataGridView单元格数据错误标签表示 27. DataGridView单元格内输入值正确性判断 28. DataGridView单元格输入错误值事件的捕获 DataGridView控件用法合集(六) 29. DataGridView行排序(点击表头自动排序的设置) 30. DataGridView自动行排序(新追加值也会自动排序) 31. DataGridView自动行排序禁止情况下的排序 32. DataGridView指定指定排序 DataGridView控件用法合集(七) 33. DataGridView单元格样式设置 34. DataGridView文字表示位置的设定 35. DataGridView单元格内文字换行 36. DataGridView单元格DBNull值表示的设定 37. DataGridView单元格样式格式化 38. DataGridView指定单元格颜色设定 39. DataGridView单元格文字字体设置 40. DataGridView根据单元格值设定单元格样式 DataGridView控件用法合集(八) 41. DataGridView设置单元格背景颜色 42. DataGridView行样式描画 43. DataGridView显示行号 44. DataGridView焦点所在单元格焦点框不显示的设定 DataGridView控件用法合集(九) 45. DataGridView中显示选择框CheckBox 46. DataGridView中显示下拉框ComboBox 47. DataGridView单击打开下拉框 48. DataGridView中显示按钮 49. DataGridView中显示链接 50. DataGridView中显示图像 DataGridView控件用法合集(十) 51. DataGridView编辑中单元格控件取得 52. DataGridView输入自动完成 53. DataGridView单元格编辑时键盘KEY事件取得 54. DataGridView下拉框(ComboBox)单元格编辑时事件取得 55. DataGridView下拉框(ComboBox)单元格允许文字输入设定 DataGridView控件用法合集(十一) 56. DataGridView根据值不同在另一中显示相应图片 57. DataGridView中显示进度条(ProgressBar) 58. DataGridView中添加MaskedTextBox DataGridView控件用法合集(十二) 59. DataGridView中Enter键按下焦点移至旁边的单元格 60. DataGridView行集合化(Group)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值