Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Datagrid Control (http://www.velocityreviews.com/forums/f60-asp-net-datagrid-control.html)
-   -   How to reference cells once converted to Template Column (http://www.velocityreviews.com/forums/t760722-how-to-reference-cells-once-converted-to-template-column.html)

Keith-Earl 06-11-2004 04:28 PM

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 06-11-2004 06:08 PM

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




Jos 06-12-2004 07:27 AM

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



Keith-Earl 06-14-2004 07:51 PM

Re: How to reference cells once converted to Template Column *UPDATE*
 
Aha, will try. Thank you for your response.
Keith



Rick Spiewak 06-22-2004 11:10 AM

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





All times are GMT. The time now is 09:26 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.