摘要:GRIDVIEW 顯示無資料
| Sub insertBlankMsg(ByRef gvx As GridView, ByVal msg As String) |
| If gvx.Rows.Count = 0 Then |
| Dim cellx As New TableCell |
| Dim rowHeader As New GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal) |
| For Each colx As DataControlField In gvx.Columns |
| If colx.Visible Then |
| cellx = New TableCell |
| cellx.HorizontalAlign = HorizontalAlign.Center |
| cellx.Text = colx.HeaderText |
| rowHeader.Cells.Add(cellx) |
| End If |
| Next |
| cellx = New TableCell |
| cellx.Text = msg |
| cellx.ForeColor = Drawing.Color.Navy |
| cellx.ColumnSpan = 99 |
| cellx.HorizontalAlign = HorizontalAlign.Center |
| Dim rowx As New GridViewRow(0, 0, DataControlRowType.DataRow, DataControlRowState.Normal) |
| rowx.Cells.Add(cellx) |
| Dim tablex As New Table |
| tablex.Rows.Add(rowHeader) |
| tablex.Rows.Add(rowx) |
| gvx.Controls.Add(tablex) |
| End If |
| End Sub |
| Protected Sub GridView1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.PreRender |
| sender.Attributes.Add("bordercolor", "black") |
| insertBlankMsg(sender, "查無任何記錄") |
| End Sub |