How to reference cells once converted to Template Column

Discussion in 'ASP .Net Datagrid Control' started by Keith-Earl, Jun 11, 2004.

  1. Keith-Earl

    Keith-Earl Guest

    Life is easy when I use a simple bound column. I refer to it as:
    MyString = e.Item.Cells(2).Text

    As soon as I convert this column to a Template Column I loose this ability.
    How do a refer to the Text in that cell AFTER I have displayed the grid? I
    know I can refer to it with a DataRow going in, but no luck after the grid
    has been displayed.

    I simply want to grab the contents of a cell the the use selects. I use the
    correct event -

    datagrid_ItemCommand

    but the code blows, say I do not have an object.

    Thanks...
     
    Keith-Earl, Jun 11, 2004
    #1
    1. Advertising

  2. Keith-Earl

    Keith-Earl Guest

    Re: How to reference cells once converted to Template Column *UPDATE*

    I need to rephrase my question. I actually have no problem *referencing*
    the columns, it's just that the data is no longer available and returns an
    empty string.

    The real issue is that the data is not accessible (as far as I can tell)
    once I convert a bound column to a templated problem. I have tried all
    kinds of silly things like persisting the DataTable to a Session variable,
    etc. I even converted the column BACK to a databound column and it works
    like a change.

    Quesiton: How do I get to the value contained (right there in front of me
    in my browser) in that cell?

    Thanks


    "Keith-Earl" <css@NO_SPAMConsultWithUs.com> wrote in message
    news:...
    > Life is easy when I use a simple bound column. I refer to it as:
    > MyString = e.Item.Cells(2).Text
    >
    > As soon as I convert this column to a Template Column I loose this

    ability.
    > How do a refer to the Text in that cell AFTER I have displayed the grid?

    I
    > know I can refer to it with a DataRow going in, but no luck after the grid
    > has been displayed.
    >
    > I simply want to grab the contents of a cell the the use selects. I use

    the
    > correct event -
    >
    > datagrid_ItemCommand
    >
    > but the code blows, say I do not have an object.
    >
    > Thanks...
    >
    >
     
    Keith-Earl, Jun 11, 2004
    #2
    1. Advertising

  3. Keith-Earl

    Jos Guest

    Re: How to reference cells once converted to Template Column *UPDATE*

    Keith-Earl wrote:
    > I need to rephrase my question. I actually have no problem
    > *referencing* the columns, it's just that the data is no longer
    > available and returns an empty string.
    >
    > The real issue is that the data is not accessible (as far as I can
    > tell) once I convert a bound column to a templated problem. I have
    > tried all kinds of silly things like persisting the DataTable to a
    > Session variable, etc. I even converted the column BACK to a
    > databound column and it works like a change.
    >
    > Quesiton: How do I get to the value contained (right there in front
    > of me in my browser) in that cell?


    The idea of a TemplateColumn is that you can add to it the controls
    you like. So it depends on which controls you put into the template,
    and which information you want to get out of them.

    Say, you added a textbox:
    <TemplateColumn>
    <EditItemTemplate>
    <asp:Textbox id="myTextbox" runat="server"></asp:TextBox>
    </EditItemTemplate>
    </TemplateColumn>

    To get the contents of the textbox (for VB.NET):
    MyString = CType(e.Item.Cells(2).FindControl("myTextbox"),Textbox).Text

    You can even do it without bothering about the column index:

    MyString = CType(e.Item.FindControl("myTextbox"),Textbox).Text

    --

    Jos
     
    Jos, Jun 12, 2004
    #3
  4. Keith-Earl

    Keith-Earl Guest

    Re: How to reference cells once converted to Template Column *UPDATE*

    Aha, will try. Thank you for your response.
    Keith
     
    Keith-Earl, Jun 14, 2004
    #4
  5. Keith-Earl

    Rick Spiewak Guest

    If you have placed a control in the templated column, just use
    ..findcontrol("id") on it to find the control, and get at the text.

    "Keith-Earl" <css@NO_SPAMConsultWithUs.com> wrote in message
    news:...
    > Life is easy when I use a simple bound column. I refer to it as:
    > MyString = e.Item.Cells(2).Text
    >
    > As soon as I convert this column to a Template Column I loose this

    ability.
    > How do a refer to the Text in that cell AFTER I have displayed the grid?

    I
    > know I can refer to it with a DataRow going in, but no luck after the grid
    > has been displayed.
    >
    > I simply want to grab the contents of a cell the the use selects. I use

    the
    > correct event -
    >
    > datagrid_ItemCommand
    >
    > but the code blows, say I do not have an object.
    >
    > Thanks...
    >
    >
     
    Rick Spiewak, Jun 22, 2004
    #5
    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. Dexter
    Replies:
    1
    Views:
    440
    Eliyahu Goldin
    Jan 18, 2005
  2. Ken Varn
    Replies:
    1
    Views:
    994
    Ken Varn
    Aug 19, 2005
  3. Replies:
    0
    Views:
    564
  4. Joel Finkel

    Cells[].Text or Cells[].Controls[0]

    Joel Finkel, Sep 1, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    347
    Joel Finkel
    Sep 1, 2003
  5. Gancy
    Replies:
    4
    Views:
    243
    Rasto Levrinc
    Feb 3, 2005
Loading...

Share This Page