473,549 Members | 2,948 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Gridview w/ custom Template Field and embedded Text Box

1 New Member
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 clsCustomGridVi ewTemplate
Implements ITemplate

Private m_colType As ListItemType
Private m_sColumnName As String

Public Sub InstantiateIn(B yVal container As System.Web.UI.C ontrol) Implements System.Web.UI.I Template.Instan tiateIn
Try
Select Case m_colType
Case ListItemType.Al ternatingItem
Case ListItemType.Ed itItem
Case ListItemType.Fo oter
Case ListItemType.He ader
Dim objLabel As New Label
With objLabel
.Text = m_sColumnName
End With
container.Contr ols.Add(objLabe l)

Case ListItemType.It em
Dim objTextBox As New TextBox
With objTextBox
.AutoPostBack = True
End With

AddHandler objTextBox.Text Changed, AddressOf Me.objTextBox_T extChanged
AddHandler objTextBox.Data Binding, AddressOf Me.objTextBox_D ataBinding

container.Contr ols.Add(objText Box)

Case ListItemType.Pa ger
Case ListItemType.Se lectedItem
Case ListItemType.Se parator
End Select

Catch ex As Exception

End Try
End Sub
Public Sub objTextBox_Data Binding(ByVal sender As Object, ByVal e As System.EventArg s)
Try

Catch ex As Exception

End Try
End Sub
Public Sub objTextBox_Text Changed(ByVal sender As Object, ByVal e As System.EventArg s)
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.EventArg s) Handles Me.Load
Try

Dim objController As New clsController

Dim objConfig As System.Web.Conf iguration.WebCo nfigurationMana ger
Dim sConnString As String = objConfig.Conne ctionStrings("J WTimeMockupConn ectionString"). ConnectionStrin g
Dim objSQLConn As New SSGCommonLibrar y.SSGCommonObje cts.Connections .clsSQLConnecti on(sConnString)
Dim sSQL As String

Dim objRS As System.Data.Sql Client.SqlDataR eader

sSQL = "SELECT DISTINCT EarnCode FROM TimeEntry, TimeRegister WHERE TimeEntry.TimeR egisterID = TimeRegister.Ti meRegisterID AND TimeRegister.Pe riodID = 1 AND TimeRegister.Pe rsonID = 1 AND TimeRegister.De ptID = 762"
objRS = objSQLConn.GetD ataReader(sSQL)

While objRS.Read
Dim objTemplateFiel d As New TemplateField
With objTemplateFiel d
.HeaderTemplate = New clsCustomGridVi ewTemplate(List ItemType.Header , objController.G etEarnCodeData( objRS("EarnCode ")).EarnCodeDes cription)
.ItemTemplate = New clsCustomGridVi ewTemplate(List ItemType.Item, objController.G etEarnCodeData( objRS("EarnCode ")).EarnCodeDes cription)
End With
Me.GridView1.Co lumns.Add(objTe mplateField)
End While

objRS.Close()

Catch ex As Exception

End Try
End Sub



Protected Sub GridView1_RowDa taBound(ByVal sender As Object, ByVal e As System.Web.UI.W ebControls.Grid ViewRowEventArg s) Handles GridView1.RowDa taBound
Try

If e.Row.RowType = DataControlRowT ype.DataRow Then
Dim objGV As GridView = CType(sender, GridView)

For I As Int16 = 2 To objGV.Columns.C ount
'e.Row.DataItem .Row(0) = Date
Dim objTextBox As TextBox = CType(e.Row.Con trols(I).Contro ls(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 4267

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

Similar topics

3
6213
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 if it is in front of the value? My guess would be to use a template column but I dont know how to go about this. Any ideas? Below is an example...
3
5579
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 the "DataTextField" as the productID of the product that I want to add. This works but the button displays the productID as the text instead of "Add...
8
5021
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 select, remember it, and then use it in the update. It works just fine when I have full control of the whole process. I want to do the same for...
3
13728
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. Everyone wants to do a java confirmation box when a user clicks the delete button. Fair enough, basic user design rules state that you should...
1
9338
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 GridView.Visible = True. I press HIDE and the GridView disappears as expected. After it I press SHOW and the GridView doesn't show.
6
3455
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 and not show the templated fields, (hyperlinks) and also not print those fields?
5
2974
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 list that corresponds with the number of pages, but I am unable to wire up the Selected Index Changed event. Auto PostBack is set to true and the...
1
1938
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) { int i; int j; for( i = 0; i < dt.Columns.Count; i++) {
7
6183
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 something. The buttons show up and post back, but the events do not fire. any help would be appreciated!!! Thank you. protected void...
0
7520
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7446
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7718
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7809
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6041
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5088
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3498
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3480
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.