Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Reading data from Template Column

Reply
Thread Tools

Reading data from Template Column

 
 
jcriv
Guest
Posts: n/a
 
      08-16-2004
Hi,
I have a datagrid on a webform and I also have an OK Button. I designed the
datagrid in Visual Studio. The dg has 3 'databound' coulmns and 3 template
columns. I used the drop down tool 'Edit Template' to 'Item Template' to a
TextBox with an initial text value.

When I run the program I bind the grid to a dataset which has 3 columns.
The grid displays just fine. My first three columns have the data from my
dataset and the last three columns have my initial text value in the text
boxes.

What I want to do is to let a user tab thru the template textboxes and make
entries and when done press the OK button on the form. I then want to
retieve the values the user entered in the template textboxes.

In my 'code behind' I have code the looks like

For i = 0 to dsMyDataSet.Tables(0).Rows.Count - 1

strText = dgMyGrid.Items(i).Cells(3).Text

Next

But, the text values I get in all cases is "" (blank). I don't get whet
the user types in nor do I get my initial default value. Note: For Cells
(0,1,2) I do get back the databound values. Cells(3) would be the first
'Template' cell.

Any idea what I might be doing wrong here?

Thanks
--
John
 
Reply With Quote
 
 
 
 
Jos
Guest
Posts: n/a
 
      08-16-2004
jcriv wrote:
> Hi,
> I have a datagrid on a webform and I also have an OK Button. I
> designed the datagrid in Visual Studio. The dg has 3 'databound'
> coulmns and 3 template columns. I used the drop down tool 'Edit
> Template' to 'Item Template' to a TextBox with an initial text value.
>
> When I run the program I bind the grid to a dataset which has 3
> columns. The grid displays just fine. My first three columns have
> the data from my dataset and the last three columns have my initial
> text value in the text boxes.
>
> What I want to do is to let a user tab thru the template textboxes
> and make entries and when done press the OK button on the form. I
> then want to retieve the values the user entered in the template
> textboxes.
>
> In my 'code behind' I have code the looks like
>
> For i = 0 to dsMyDataSet.Tables(0).Rows.Count - 1
>
> strText = dgMyGrid.Items(i).Cells(3).Text
>
> Next
>
> But, the text values I get in all cases is "" (blank). I don't get
> whet the user types in nor do I get my initial default value. Note:
> For Cells (0,1,2) I do get back the databound values. Cells(3)
> would be the first 'Template' cell.
>
> Any idea what I might be doing wrong here?
>
> Thanks


Cells(3).Text would be the Text value of the table cell, not
the Text value of the TextBox.

Use:
strText = CType(dgMyGrid.Items(i).FindControl("IDOfTextBox") ,TextBox).Text

where IDOfTextBox is the ID that you assigned to the TextBox.

--

Jos


 
Reply With Quote
 
 
 
 
jcriv
Guest
Posts: n/a
 
      08-16-2004
Thanks, that works. In the mean time I also discovered that the following
works
dim tb as System.Web.UI.WebControls.TextBox

tb = dgMyGrid.Items(i).Cells(3).Controls(1)

myStr = tb.Text

I'm not sure how all of this is related. I looked around the VS Help and
found a lot of info about constructing you own templates, etc but not much
about simply using what's already there. If you know a good link I'd
appreciate it. Preferably a VS designer example and not one heavy on html.

Thanks




"Jos" wrote:

> jcriv wrote:
> > Hi,
> > I have a datagrid on a webform and I also have an OK Button. I
> > designed the datagrid in Visual Studio. The dg has 3 'databound'
> > coulmns and 3 template columns. I used the drop down tool 'Edit
> > Template' to 'Item Template' to a TextBox with an initial text value.
> >
> > When I run the program I bind the grid to a dataset which has 3
> > columns. The grid displays just fine. My first three columns have
> > the data from my dataset and the last three columns have my initial
> > text value in the text boxes.
> >
> > What I want to do is to let a user tab thru the template textboxes
> > and make entries and when done press the OK button on the form. I
> > then want to retieve the values the user entered in the template
> > textboxes.
> >
> > In my 'code behind' I have code the looks like
> >
> > For i = 0 to dsMyDataSet.Tables(0).Rows.Count - 1
> >
> > strText = dgMyGrid.Items(i).Cells(3).Text
> >
> > Next
> >
> > But, the text values I get in all cases is "" (blank). I don't get
> > whet the user types in nor do I get my initial default value. Note:
> > For Cells (0,1,2) I do get back the databound values. Cells(3)
> > would be the first 'Template' cell.
> >
> > Any idea what I might be doing wrong here?
> >
> > Thanks

>
> Cells(3).Text would be the Text value of the table cell, not
> the Text value of the TextBox.
>
> Use:
> strText = CType(dgMyGrid.Items(i).FindControl("IDOfTextBox") ,TextBox).Text
>
> where IDOfTextBox is the ID that you assigned to the TextBox.
>
> --
>
> Jos
>
>
>

 
Reply With Quote
 
Jos
Guest
Posts: n/a
 
      08-17-2004
jcriv wrote:
> Thanks, that works. In the mean time I also discovered that the
> following works
> dim tb as System.Web.UI.WebControls.TextBox
>
> tb = dgMyGrid.Items(i).Cells(3).Controls(1)
>
> myStr = tb.Text
>
> I'm not sure how all of this is related. I looked around the VS Help
> and found a lot of info about constructing you own templates, etc but
> not much about simply using what's already there. If you know a good
> link I'd appreciate it. Preferably a VS designer example and not one
> heavy on html.


The textbox is the second control in the cell.
The first control is a Literal control, created by ASP.NET to
represent any white space between the
<EditItemTemplate> tag and the <asp:TextBox> tag.

I prefer FindControl because it keeps working, even
if you add other controls to the template later.

--

Jos


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
setting Column width of Template Column in Datagrid.. Charleees ASP .Net 2 06-20-2006 12:52 PM
DataGrid loses view state if first column is a template column. Ken Varn ASP .Net 1 08-19-2005 02:54 PM
how to know if a datagrid column is a template column? Dexter ASP .Net 1 01-18-2005 01:45 PM
Template Column data depending on form data John Mackerras ASP .Net Datagrid Control 0 11-15-2004 01:05 PM
Activa or not activate a button column depending if another data column has data or not carlos perez ASP .Net 0 06-08-2004 02:16 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57