How to reference cells once converted to Template Column

Ask a Question related to ASP.NET Data Grid Control, Design and Development.

  1. #1

    Default How to reference cells once converted to Template Column

    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 Guest

  2. Similar Questions and Discussions

    1. Reference Column Name by string...
      If you read half way through my question and think to yourself, "Huh?" you will know exactly how I feel right now. I am dynamically creating a...
    2. Template column base on another column value
      Hello .net expert, I would like to change the color a a column "Name" base on the value of another column "tel" . Is it possible ??? Thanks in...
    3. Qualify/Reference datagrid cells by name
      Now I am referencing datagrid cells by index, eq. '...Cells.Text'. I always find this a little bit tricky to use. With DataSets it is pssible to...
    4. Bound Column or Template Column (w dAdapater?) in DataGrid
      I am able to get the data using DataAdapter and the DataReader. I am more inclined to use DataAdapter because I want to update the data on the SQL...
    5. Template & layout tables/cells -- Need help
      I have a slight problem... After using dreamweaver for a little while, I realized that it would be so much simpler to use a universal template so...
  3. #2

    Default 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:eNwCkE9TEHA.2844@TK2MSFTNGP12.phx.gbl...
    > 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 Guest

  4. #3

    Default 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"),Tex tbox).Text

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

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

    --

    Jos


    Jos Guest

  5. #4

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

    Aha, will try. Thank you for your response.
    Keith


    Keith-Earl Guest

  6. #5

    Default Re: How to reference cells once converted to Template Column

    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:eNwCkE9TEHA.2844@TK2MSFTNGP12.phx.gbl...
    > 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 Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139