 |
|
Custom ASP.NET YetGridView DataSource ไม่จดจำค่าเมื่อ PostBack |
|
 |
|
|
 |
 |
|
ถ้ามันจดจำค่าได้ แบบนี้จบ
Code (VB.NET)
Protected Overrides Sub OnPageIndexChanging(e As System.Web.UI.WebControls.GridViewPageEventArgs)
Me.PageIndex = e.NewPageIndex
Me.DataBind()
MyBase.OnPageIndexChanging(e)
End Sub
คำถามก็คือไอ้ตรง comment '***** จะต้องแก้ไขหรือทำอย่างไร?
ขอบคุณครับ
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")>
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 :
1273 |
Reply :
20 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มัน 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 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองมั่วคลำไปเรื่อยฯ
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 :
ผ่านมา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มัน 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 :
ผ่านมา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
สนใจ grid อันเนี้ย http://w2ui.com/web/demo/grid
สร้างเป็น dll server control ให้หน่อยได้มะ ทำได้เปล่า

|
 |
 |
 |
 |
Date :
2013-03-19 11:56:35 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พอดีเห็นว่าชอบถามแบบลองภูมิ ก็เลยหาโจทย์หาให้
ไม่ต้องตอบก็ได้นะ แค่ถือว่า ผ่านมา ทำไม่เป็นก็แล้วกัน 
|
 |
 |
 |
 |
Date :
2013-03-19 12:01:43 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แต่ถ้าอยากได้คำแนะนำ ก็บอกนะ
จะช่วยแนะให้ 
|
 |
 |
 |
 |
Date :
2013-03-19 12:05:26 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
+55555 javascript:void(0);
ขอบคุณครับ
ปล. http://w2ui.com/web/demo/grid และที่นี่ http://www.flexigrid-asp.net/discontinued.aspx
-----หรือ devexpress หรือ telerix หรือ อื่นฯ มันตอบโจทย์ผมได้เกือบหมด
-----ยกเว้น และสำคัญมากฯ นั่นก็คือ คลิกขวา เลือกคำสั่ง View Source/View Page Source
-----มันจะต้องไม่เห็นข้อมูลอะไรเลย (ผมหมายถึง ทุกฯอย่างที่อยู่บน GridView หรือสิ่งที่ผมต้องการไม่ให้แสดงผลบน Client Browser)
|
 |
 |
 |
 |
Date :
2013-03-19 15:48:53 |
By :
ผ่านมา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มาอย่านอกเรื่อง
อ่ะ แนะให้นิด ให้เริ่มจาก embed resource ก่อนเลย
พวก js file ต่างๆ เอามารวมไว้ใน dll ให้ได้ก่อน
|
 |
 |
 |
 |
Date :
2013-03-19 15:57:03 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

และเมื่อ View Source/ View Page Source มันต้องเห็นเป็นอย่างนี้
Code (VB.NET)
<script src="/ScriptResource.axd?d=Yet_yr0iO2ixFsZ8bxj3PgxhBptll9Hofyxc-XfsqAZ2RxFDep2hJ1szm4Fdl7C30ZVALIyUVKX1Ak1pVdTBKMmENyoyD4NzjqQWygdO5snrr9oqGWxpnrMwfnq68K-MQxCl2Pat-n7YtrqHbW3nkRBcYg2&t=7c776dc1_Yet" type="text/javascript"></script>
|
 |
 |
 |
 |
Date :
2013-03-19 16:00:09 |
By :
ผ่านมา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
Imports System
Imports System.Reflection
Imports System.Runtime.InteropServices
Imports System.Web.UI
' General Information about an assembly is controlled through the following
' set of attributes. Change these attribute values to modify the information
' associated with an assembly.
' Review the values of the assembly attributes
<Assembly: AssemblyTitle("YetGridView")>
<Assembly: AssemblyDescription("")>
<Assembly: AssemblyCompany("")>
<Assembly: AssemblyProduct("YetGridView")>
<Assembly: AssemblyCopyright("Copyright © 1960-2013")>
<Assembly: AssemblyTrademark("")>
<Assembly: ComVisible(False)>
'The following GUID is for the ID of the typelib if this project is exposed to COM
<Assembly: Guid("d8075dab-b3a9-4083-ac8c-0c187d3f2b6f")>
' Version information for an assembly consists of the following four values:
'
' Major Version
' Minor Version
' Build Number
' Revision
'
' You can specify all the values or you can default the Build and Revision Numbers
' by using the '*' as shown below:
' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyFileVersion("1.0.0.0")>
<Assembly: WebResource("YetGridView.YetGridView.js", "text/javascript", PerformSubstitution:=True)>
|
 |
 |
 |
 |
Date :
2013-03-19 16:06:22 |
By :
ผ่านมา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

ผมรบกวนคุณ ห้ามตอบเกินวันละ 2 กระทู้/ท่านอื่นฯ ช่วยแปลงเป็น VB ให้หน่อย
ขอบคุณมากครับ
Code (C#)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Dynamic;
using System.Data;
namespace WebApplicationCS
{
public partial class DynamicObject_A : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
dynamic p = new ExpandoObject();
p.Title = "Using Dynamic";
p.Data = new Action(() =>
{
DataTable dt = new DataTable();
dt.Columns.Add("ProductCode", typeof(string));
dt.Columns.Add("ProductName", typeof(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();
});
Response.Write("<center><b>" + p.Title + "</center></b>");
p.Data();
}
}
}
|
 |
 |
 |
 |
Date :
2013-03-19 16:15:48 |
By :
ผ่านมา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แปลงไมอ่ะ เป็น c# ก็ดีอยู่แล้ว เขียน vb แล้วผื่นขึ้น ภาษาเด็กเล่นไว้เขียนเล่นๆ ก็พอ
แต่นอกเรื่องนะ บอกให้ทำสร้าง grid แบบ no.4 ทำไมไม่ทำซักที
|
 |
 |
 |
 |
Date :
2013-03-19 17:54:54 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
บอกให้ทำสร้าง grid แบบ no.4 ทำไมไม่ทำซักที
คำตอบอยู่ที่นี่ครับ ***** http://www.flexigrid-asp.net/discontinued.aspx *****
พอดีเห็นว่าชอบถามแบบลองภูมิ ก็เลยหาโจทย์หาให้
ไม่ต้องตอบก็ได้นะ แค่ถือว่า ผ่านมา ทำไม่เป็นก็แล้วกัน
ผมไม่ได้คิดแบบนั้นครับ ด้วยความสัตย์จริง รบกวนแปลงโค๊ดให้เป็น VB.NET ให้หน่อยครับ
ขอบคุณครับ
System.Dynamic C# <> VB
Code (C#)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Dynamic;
using System.Data;
namespace WebApplicationCS
{
public partial class DynamicObject_A : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
dynamic p = new ExpandoObject();
p.Title = "Using System.Dynamic";
p.Data = new Action(() =>
{
DataTable dt = new DataTable();
dt.Columns.Add("ProductCode", typeof(string));
dt.Columns.Add("ProductName", typeof(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();
});
Response.Write("<center><b>" + p.Title + "</center></b>");
p.Data();
}
}
}
|
 |
 |
 |
 |
Date :
2013-03-21 08:17:05 |
By :
ผ่านมา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จะอมภูมิ ไม่ทำ
|
 |
 |
 |
 |
Date :
2013-03-21 09:04:13 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เริ่มรู้สึกจะเกรียนเกินไปแระ ขอโทษด้วยล่ะกัน
งั้นบอกตามตรงก็ได้ vb.net เนี่ยพอเขียนได้ แต่ช้า
ส่วน syntax แปลกๆ พวก lamda, linq ของ vb.net เนี่ย ตายสนิท (dynamic ด้านบนด้วย)
งั้นจะลองดูล่ะกัน พักกลางวันก่อน
|
 |
 |
 |
 |
Date :
2013-03-21 09:11:35 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
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
|
 |
 |
 |
 |
Date :
2013-03-21 09:53:07 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันเป็นความสามารถของ ExpandoObject()
ที่สามารถประกาศ object ขึ้นมา
แล้วสามารถ add properties หรือ method ต่างๆ ได้ในขณะ runtime
แต่ของ vb.net จะ call mothod ตรงๆ ไม่ได้
ต้อง call ผ่าน invork
|
 |
 |
 |
 |
Date :
2013-03-21 09:58:08 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
p.Data.Invoke() เป็นคำตอบที่ไม่ใช่คำแนะนำ และเป็นคำตอบที่ทำให้ผมมีความสุข >55555
ขอบคุณมากครับคุณ ห้ามตอบเกินวันละ 2 กระทู้
|
 |
 |
 |
 |
Date :
2013-03-25 19:53:03 |
By :
ผ่านมา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมลืมบอกไปว่า ช่วงนี้ผมยุ่งมากฯ (บ้านโดนไฟไหม้ แม่ยาย ไม่สะบาย และอื่นฯ จิปาถะ) อย่างน้อยฯ อีก 2 เดือนที่ผมจะไม่ผ่านไป และผ่านมา (วันพรุ่งนี้ 26-03-2556) ผมต้องพาแม่ยายไปหาหมอ และธุระอื่นฯ ที่ผมจำเป็น ต้อง ทำ ต้องทำ
|
 |
 |
 |
 |
Date :
2013-03-25 19:59:43 |
By :
ผ่านมา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เป็นคำตอบที่ไม่ใช่คำแนะนำ แต่ เป็นคำตอบ     ที่ทำให้ผมมีความสุข >55555
|
 |
 |
 |
 |
Date :
2013-03-25 20:03:43 |
By :
ผ่านมา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|