Protected Overrides Sub OnPageIndexChanging(e As System.Web.UI.WebControls.GridViewPageEventArgs)
Me.PageIndex = e.NewPageIndex
Me.DataBind()
MyBase.OnPageIndexChanging(e)
End Sub
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Public Class YetGridView
Inherits GridView
<Bindable(False), Category("Appearance"), DefaultValue("Text"), Localizable(True), Description("Set GridView Pattern")>
Property _PatternCode As String
Get
If ViewState("_PatternCode") Is Nothing Then
Return String.Empty
Else
Return CType(ViewState("_PatternCode"), String)
End If
End Get
Set(ByVal Value As String)
ViewState("_PatternCode") = Value
End Set
End Property
Protected Overrides Sub OnPageIndexChanging(e As System.Web.UI.WebControls.GridViewPageEventArgs)
Me.PageIndex = e.NewPageIndex
Dim dynClass = Me.DataSource '*****
Me.DataSource = dynClass '*****
Me.DataBind()
MyBase.OnPageIndexChanging(e)
End Sub
''' <summary>
''' Get Active Column Index
''' </summary>
''' <param name="SortExp"></param>
''' <returns></returns>
''' <remarks></remarks>
Private Function GetColumnIndex(ByVal SortExp As String) As Integer
For s As Short = 0 To Me.Columns.Count - 1
Try
If Me.Columns(s).SortExpression.Equals(SortExp, StringComparison.CurrentCultureIgnoreCase) Then
Return s
End If
Catch ex As Exception
'Ignore Error
End Try
Next
Return -1
End Function
''' <summary>
''' Get Columns Alignment of GridView
''' </summary>
''' <param name="c">HL, IL, FL</param>
''' <returns>Enum</returns>
''' <remarks>HL = Header Alignment, IL = Item Alignment, FL = Footer Alignment</remarks>
Private Function GetColumnAlignment(ByVal c As String) As [Enum]
Try
Select Case c.Trim().Substring(1, 1).ToUpper()
Case "L"
Return HorizontalAlign.Left
Case "C"
Return HorizontalAlign.Center
Case "R"
Return HorizontalAlign.Right
Case Else
Return HorizontalAlign.Left 'Default Left
End Select
Catch ex As Exception
Return HorizontalAlign.Left
End Try
End Function
End Class
Tag : .NET, Web (ASP.NET), VB.NET, C#
Date :
2013-03-18 09:36:57
By :
ผ่านมา
View :
1240
Reply :
20
No. 1
Guest
มัน error ตั้งแต่ Protected Overrides Sub OnPageIndexChanging(e As System.Web.UI.WebControls.GridViewPageEventArgs) แล้ว
แนะนำให้เขียนเป็น method ใน web form ดีกว่าจะมาโมใน control
Date :
2013-03-19 10:27:02
By :
ห้ามตอบเกินวันละ 2 กระทู้
No. 2
Guest
ลองมั่วคลำไปเรื่อยฯ
Code (VB.NET)
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Public Class YetGridView
Inherits GridView
<Bindable(False), Category("Appearance"), DefaultValue("Text"), Localizable(True), Description("Set GridView Pattern")>
Public Property _PatternCode As String
Get
If ViewState("_PatternCode") Is Nothing Then
Return String.Empty
Else
Return CType(ViewState("_PatternCode"), String)
End If
End Get
Set(ByVal Value As String)
ViewState("_PatternCode") = Value
End Set
End Property
''' <summary>
''' Keep GridView DataSource After Postback
''' </summary>
''' <value>Example Me._Model = New List(Of Products)</value>
''' <remarks></remarks>
Public Property _DataModel As List(Of Object)
Get
If ViewState("_DataModel") Is Nothing Then
Return Nothing
Else
Return CType(ViewState("_DataModel"), List(Of Object))
End If
End Get
Set(ByVal Value As List(Of Object))
ViewState("_DataModel") = Value
End Set
End Property
Protected Overrides Sub OnPageIndexChanging(e As System.Web.UI.WebControls.GridViewPageEventArgs)
If ViewState("_DataModel") IsNot Nothing Then
Me.PageIndex = e.NewPageIndex
Me.DataSource = DirectCast(ViewState("_DataModel"), List(Of Object))
Me.DataBind()
MyBase.OnPageIndexChanging(e)
End If
End Sub
Protected Overrides Sub OnRowDataBound(e As System.Web.UI.WebControls.GridViewRowEventArgs)
For Each c As TableCell In e.Row.Cells
c.ToolTip = c.Text
Next
MyBase.OnRowDataBound(e)
End Sub
''' <summary>
''' Get current Active Column Index
''' </summary>
''' <param name="SortExp"></param>
''' <returns></returns>
''' <remarks></remarks>
Private Function GetColumnIndex(ByVal SortExp As String) As Integer
For s As Short = 0 To Me.Columns.Count - 1
Try
If Me.Columns(s).SortExpression.Equals(SortExp, StringComparison.CurrentCultureIgnoreCase) Then
Return s
End If
Catch ex As Exception
'Ignore Error
End Try
Next
Return -1
End Function
''' <summary>
'''
''' </summary>
''' <param name="c">HL, IL, FL</param>
''' <returns>Enum</returns>
''' <remarks>HL = Header Alignment, IL = Item Alignment, FL = Footer Alignment</remarks>
Private Function GetColumnAlignment(ByVal c As String) As [Enum]
Try
Select Case c.Trim().Substring(1, 1).ToUpper()
Case "C"
Return HorizontalAlign.Center
Case "R"
Return HorizontalAlign.Right
Case Else
Return HorizontalAlign.Left
End Select
Catch ex As Exception
Return HorizontalAlign.Left
End Try
End Function
End Class
Date :
2013-03-19 10:50:03
By :
ผ่านมา
No. 3
Guest
มัน error ตั้งแต่ Protected Overrides Sub OnPageIndexChanging(e As System.Web.UI.WebControls.GridViewPageEventArgs) แล้ว
----- แนะนำให้เขียนเป็น method ใน web form ดีกว่าจะมาโมใน control
We are Professional Reuseable & Valueable
Table GridViewPattern
PatternCode-----ColCount-----DisplayField-----------------------------------HeaderAlign-----ItemAlign-----FooterAlign---etc
1--------------------1----------------ProductCode----------------------------------HC
2--------------------2----------------ProductCode, ProductName--------------HC, HC
3--------------------3----------------ProductCode, Price, ProductName-----HC, HR, HC-----IL, IR, IL
...
...
...
Date :
2013-03-19 11:31:33
By :
ผ่านมา
No. 4
Guest
สนใจ grid อันเนี้ย http://w2ui.com/web/demo/grid
สร้างเป็น dll server control ให้หน่อยได้มะ ทำได้เปล่า
Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
Dim p As Object = New ExpandoObject()
p.Title = "Using System.Dynamic"
p.Data = Sub()
Dim dt As New DataTable
dt.Columns.Add("ProductCode", GetType(String))
dt.Columns.Add("ProductName", GetType(String))
dt.Rows.Add(New Object() {"001", "Car"})
dt.Rows.Add(New Object() {"002", "food"})
dt.Rows.Add(New Object() {"003", "bed"})
GridView1.DataSource = dt
GridView1.DataBind()
End Sub
Response.Write("<center><b>" + p.Title + "</b></center>")
p.Data.Invoke()
End Sub