DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Fri, 17 Aug 2007 11:48:24 -0300,    posted on: microsoft.public.dotnet.framework.aspnet        back       

Thread Index
  1    Paulo
          2    Mark Fitzpatrick
          3    seigo


Looping Grid   
Hi, I have a grid with a template column wich is a TextBox, how can I 
retrieve the values typed by the user? I tried the code below but it always 
returns empty string:

for (int i = 0; i < grdDocs.Rows.Count; i++)
{
Response.Write(grdDocs.Rows[i].Cells[2].Text.ToString() + "<br>");
}

Thanks in advance!
Date:Fri, 17 Aug 2007 11:48:24 -0300   Author:  

Re: Looping Grid   
Well, the main problem here is you're not actually accessing the textbox, 
you're accessing the text property of the cell which won't get you anything 
unless you set the text of that cell. You need to find the control within 
the cell

TextBox tb = (TextBox)grdDocs.Rows[i].Cells[2].FindControl("name of your 
textbox");
if(text != null)
    Response.Write(tb.Text + "<br />");

I may be off a tad as I usually don't fetch data out of grid controls, but 
this is a fairly standard ASP.Net concept. Also, make sure you really have 
the right cell. It's easy to forget about a spacer cell and you end up 
trying to get values out of the wrong cell.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"Paulo"  wrote in message 
news:%234HiN3N4HHA.5360@TK2MSFTNGP03.phx.gbl...

> Hi, I have a grid with a template column wich is a TextBox, how can I 
> retrieve the values typed by the user? I tried the code below but it 
> always returns empty string:
>
> for (int i = 0; i < grdDocs.Rows.Count; i++)
> {
> Response.Write(grdDocs.Rows[i].Cells[2].Text.ToString() + "<br>");
> }
>
> Thanks in advance!
> 
Date:Fri, 17 Aug 2007 10:01:15 -0500   Author:  

Re: Looping Grid   
On Aug 17, 5:48 pm, "Paulo"  wrote:

> Hi, I have a grid with a template column wich is a TextBox, how can I
> retrieve the values typed by the user? I tried the code below but it always
> returns empty string:
>
> for (int i = 0; i < grdDocs.Rows.Count; i++)
> {
> Response.Write(grdDocs.Rows[i].Cells[2].Text.ToString() + "<br>");
>
> }
>
> Thanks in advance!


Hi Paulo,

You should use FindControl() method of GridViewRow object to find
TextBox:

foreach (GridViewRow row in GridView1.Rows)
{
    TextBox textbox = (TextBox)row.FindControl("TextBox1");
}

Instead of "TextBox1" as a parameter you should pass the name of
TextBox control that you placed in Grid template.
After this you can access Text property of textbox object.

Regards,
Alexander Kleshchevnikov
MCP
www.klalex.com
Date:Fri, 17 Aug 2007 08:08:58 -0700   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us