For i = 0 To GridView1.Rows.Count - 1
Dim DDL3 As LinkButton = DirectCast(GridView1.Rows(i).Cells(3).FindControl("LinkButton2"), LinkButton)
If i = ??????? Then
Label4.Text = DDL3.Text
End If
Next
Private Sub YetGridView(ByVal grd As GridView, ByVal grdPattern As String)
grd.Columns.Clear()
If Not (grdPattern.Equals(Nothing) OrElse grdPattern.Equals(String.Empty)) Then
Dim gp = WL_Session.GlobalSession.Current.sysGridPatternExt.Find(Function(x) x.PatternCode = grdPattern)
If gp IsNot Nothing Then
Dim ht = WL_Common.PageManager.GetGridPatternTextExt(gp).Split(","), bf = gp.BoundFieldName.Split(","), cw = gp.ColumnWidth.Split(",")
Dim ha = gp.H_Align.Split(","), ia = gp.I_Align.Split(","), fa = gp.F_Align.Split(",")
Dim tmpCW As Short = 0
For i As Short = 0 To gp.ColumnCount - 1
Dim b As New BoundField()
Try
b.HeaderText = ht(i).TrimStart(" "c) 'removed all left spaces
b.DataField = bf(i).Trim()
b.SortExpression = bf(i).Trim()
b.HeaderStyle.HorizontalAlign = GetColumnAlignment(ha(i))
b.ItemStyle.HorizontalAlign = GetColumnAlignment(ia(i))
b.FooterStyle.HorizontalAlign = GetColumnAlignment(fa(i))
tmpCW = CShort(cw(i).Trim())
b.HeaderStyle.Width = tmpCW
b.ItemStyle.Width = tmpCW
b.FooterStyle.Width = tmpCW
'DataFormatString = xxx 'Not Implement yet.
'xxx...
'xxx...
Catch ex As Exception
'Write Log.
End Try
grd.Columns.Add(b)
Next
End If
End If
End Sub
Imports System.Data
Partial Class MyGridView
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
GridView1.DataSource = GetData()
GridView1.DataBind()
End Sub
Protected Sub GridView1_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(DirectCast(sender, GridView), String.Format("Select${0}", e.Row.RowIndex.ToString())))
e.Row.Attributes.Add("onmouseover", "javascript:this.style.backgroundColor='#EFF3FB'; this.style.cursor='pointer'")
e.Row.Attributes.Add("onmouseout", "javascript:this.style.backgroundColor='#FFFFFF';")
End If
End Sub
Protected Sub GridView1_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles GridView1.SelectedIndexChanged
Dim Gv As GridView = DirectCast(sender, GridView)
Gv.SelectedRow.Attributes.Clear()
If Gv.SelectedIndex >= 0 Then
Label1.Text = String.Format("Row Index: {0}", Gv.SelectedIndex.ToString())
End If
End Sub
Protected Function GetData() As DataTable
Dim data As New DataTable()
data.Columns.Add(New DataColumn("ID", GetType(String)))
data.Columns.Add(New DataColumn("Name", GetType(String)))
For i As Integer = 1 To 5
Dim dr As DataRow = data.NewRow()
dr("ID") = String.Format("{0}.", i.ToString())
dr("Name") = String.Format("ผ่านมา_{0}", i.ToString())
data.Rows.Add(dr)
Next
Return data
End Function
End Class