473,394 Members | 1,770 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Gridview w/ custom Template Field and embedded Text Box

I have a Gridview that I am dynamically adding template columns to which contain text boxes in their "Item Data" field. After adding the columns to the gridview in my Page_Load event, the page binds a SQL Data Source to the Gridview and all is good.

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

Jun 12 '07 #1
0 4260

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: washoetech | last post by:
I have a gridview control. In this grid view there is a column for the price of an item. Some of the prices have a dollar sign in front of it and some dont. How do I get rid of the dollar sign...
3
by: | last post by:
Hello, I am trying to get add a product to a cart from a gridview control when a button in the gridview is clicked. I have a book on how to do this in asp.net 2.0 but it is done by specifying...
8
by: Mike Kelly | last post by:
I've chosen to implement the "optimistic concurrency" model in my application. To assist in that, I've added a ROWVERSION (TIMESTAMP) column to my main tables. I read the value of the column in my...
3
by: NateDawg | last post by:
I'm reposting this. I'm kinda in a bind untill i get this figured out, so if anyone has some input it would sure help me out. Ok, I’ve noticed a few gridview problems floating around the forum....
1
by: Miguel Dias Moura | last post by:
Hello, I have a GridView in my page which is created in runtime. It works fine. My page has 2 Asp Buttons: - The HIDE button makes GridView.Visible = False; - The SHOW button makes...
6
by: CSharpguy | last post by:
In my gridview I have 2 -3 template fields which are hyperlinks. I allow the user to print this grid. When the grid prints it also prints the links, how can I take the user to a print preview page...
5
by: Andrew Robinson | last post by:
I am attempting to better automate a Pager Template within a GridView. I am succesfully skinning a Drop Down List withing my control (the DDL is added to my control). I correctly populate the item...
1
by: neobonzi | last post by:
Hello! I'm dynamically creating a GridView bound to a datatable using custom template columns using the following method: protected void ShowGrid(DataTable dt) { ...
7
by: =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= | last post by:
I'm adding subheadings to a gridview. Each sub head has a few link buttons. I'm adding the controls in the rowdatabound event code follows: sorry about the length here. I have to be missing...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.