Reading data from Template Column

Discussion in 'ASP .Net Datagrid Control' started by jcriv, Aug 16, 2004.

  1. jcriv

    jcriv Guest

    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
     
    jcriv, Aug 16, 2004
    #1
    1. Advertising

  2. jcriv

    Jos Guest

    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
     
    Jos, Aug 16, 2004
    #2
    1. Advertising

  3. jcriv

    jcriv Guest

    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
    >
    >
    >
     
    jcriv, Aug 16, 2004
    #3
  4. jcriv

    Jos Guest

    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
     
    Jos, Aug 17, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. carlos perez
    Replies:
    0
    Views:
    438
    carlos perez
    Jun 8, 2004
  2. Dexter
    Replies:
    1
    Views:
    440
    Eliyahu Goldin
    Jan 18, 2005
  3. Ken Varn
    Replies:
    1
    Views:
    995
    Ken Varn
    Aug 19, 2005
  4. Charleees
    Replies:
    2
    Views:
    8,281
    Eliyahu Goldin
    Jun 20, 2006
  5. John Mackerras

    Template Column data depending on form data

    John Mackerras, Nov 15, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    149
    John Mackerras
    Nov 15, 2004
Loading...

Share This Page