datagrid数据绑定并格式化的一个例子

Public Class mymanage
    Inherits System.Web.UI.Page

#Region " Web 窗体设计器生成的代码 "

    '该调用是 Web 窗体设计器所必需的。
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
    Protected WithEvents Form1 As System.Web.UI.HtmlControls.HtmlForm

    '注意: 以下占位符声明是 Web 窗体设计器所必需的。
    '不要删除或移动它。
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
        '不要使用代码编辑器修改它。
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not Page.IsPostBack Then
            bindgrid()
        End If
    End Sub
    Sub bindgrid()
        'DataGrid1.DataSource = mydb.gettable("select * from articles where art_col_sub=" & Request.QueryString("art_col_sub"))
        DataGrid1.DataSource = mydb.gettable(CType(Request.QueryString("art_col_sub"), Integer))
        DataGrid1.DataKeyField = "id"
        DataGrid1.DataBind()
    End Sub
    Private Sub DataGrid1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGrid1.SelectedIndexChanged

    End Sub

    Private Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.ItemCommand
        Select Case e.CommandName
            Case "Delete"
                ' Response.Write(DataGrid1.DataKeys(e.Item.ItemIndex))
                mydb.delrecord(DataGrid1.DataKeys(e.Item.ItemIndex))
            Case "disp"
                Response.Redirect(String.Format("disp.aspx?art_col_sub={0}", DataGrid1.DataKeys(e.Item.ItemIndex)))
                bindgrid()

        End Select
    End Sub

    Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
        If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
            If Len(e.Item.Cells(5).Text) > 12 Then
                e.Item.Cells(5).Text = Mid(e.Item.Cells(5).Text, 1, 12) + "......"
            End If
            ' Dim btnDelete As ImageButton
            'btnDelete = CType(e.Item.FindControl("btnDelete"), ImageButton)
            'btnDelete.Attributes.Add("onclick", "return confirm('Warning: This will delete ALL records, including all content pages and users, associated with this community.')")
        End If
    End Sub
End Class

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值