How to reference cells once converted to Template Column

K

Keith-Earl

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...
 
K

Keith-Earl

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
 
J

Jos

Keith-Earl said:
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
 
R

Rick Spiewak

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top