I'm left with a gridview with 5 columns 3 of which have text boxes in their item cells. (The other two come directly from the SQL DS)
What I want is to be able to change a value in one of the text boxes and trap the "Text Changed" event, but unfortunately I can't seem to do that.
Below is the code in which I am attempting to use:
Public Class clsCustomGridViewTemplate
Implements ITemplate
Private m_colType As ListItemType
Private m_sColumnName As String
Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn
Try
Select Case m_colType
Case ListItemType.AlternatingItem
Case ListItemType.EditItem
Case ListItemType.Footer
Case ListItemType.Header
Dim objLabel As New Label
With objLabel
.Text = m_sColumnName
End With
container.Controls.Add(objLabel)
Case ListItemType.Item
Dim objTextBox As New TextBox
With objTextBox
.AutoPostBack = True
End With
AddHandler objTextBox.TextChanged, AddressOf Me.objTextBox_TextChanged
AddHandler objTextBox.DataBinding, AddressOf Me.objTextBox_DataBinding
container.Controls.Add(objTextBox)
Case ListItemType.Pager
Case ListItemType.SelectedItem
Case ListItemType.Separator
End Select
Catch ex As Exception
End Try
End Sub
Public Sub objTextBox_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs)
Try
Catch ex As Exception
End Try
End Sub
Public Sub objTextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Try
Catch ex As Exception
End Try
End Sub
Public Sub New(ByVal objType As ListItemType, ByVal sColumnName As String)
m_colType = objType
m_sColumnName = sColumnName
End Sub
End Class
----------------------------------------------------------------------------------------------------
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
Dim objController As New clsController
Dim objConfig As System.Web.Configuration.WebConfigurationManager
Dim sConnString As String = objConfig.ConnectionStrings("JWTimeMockupConnectio nString").ConnectionString
Dim objSQLConn As New SSGCommonLibrary.SSGCommonObjects.Connections.clsS QLConnection(sConnString)
Dim sSQL As String
Dim objRS As System.Data.SqlClient.SqlDataReader
sSQL = "SELECT DISTINCT EarnCode FROM TimeEntry, TimeRegister WHERE TimeEntry.TimeRegisterID = TimeRegister.TimeRegisterID AND TimeRegister.PeriodID = 1 AND TimeRegister.PersonID = 1 AND TimeRegister.DeptID = 762"
objRS = objSQLConn.GetDataReader(sSQL)
While objRS.Read
Dim objTemplateField As New TemplateField
With objTemplateField
.HeaderTemplate = New clsCustomGridViewTemplate(ListItemType.Header, objController.GetEarnCodeData(objRS("EarnCode")).E arnCodeDescription)
.ItemTemplate = New clsCustomGridViewTemplate(ListItemType.Item, objController.GetEarnCodeData(objRS("EarnCode")).E arnCodeDescription)
End With
Me.GridView1.Columns.Add(objTemplateField)
End While
objRS.Close()
Catch ex As Exception
End Try
End Sub
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
Try
If e.Row.RowType = DataControlRowType.DataRow Then
Dim objGV As GridView = CType(sender, GridView)
For I As Int16 = 2 To objGV.Columns.Count
'e.Row.DataItem.Row(0) = Date
Dim objTextBox As TextBox = CType(e.Row.Controls(I).Controls(0), TextBox)
objTextBox.Text = e.Row.DataItem(I - 1)
Next
End If
Catch ex As Exception
End Try
End Sub