Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
|
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 25th, 2010, 08:33 AM
Authorized User
 
Join Date: Nov 2008
Posts: 21
Thanks: 3
Thanked 0 Times in 0 Posts
Send a message via MSN to MonkeyMan666
Unhappy Can't get value from TextBox in GridView

Hiya
I have a GridView on an ASP.NET page with a TemplateField column that has a TextBox in the ItemTemplate. I then have a command field which is supposed to pull the text from this TextBox and use it in a SqlCommand running a stored procedure. The code is being from the OnRowCommand event from the gridview.

Here is my C# code:

Code:
int index = Convert.ToInt32(e.CommandArgument);    
GridViewRow selectedRow = this.gvwSNConfirm.Rows[index];    
TableCell intID = selectedRow.Cells[1];    
int reqID = int.Parse(intID.Text);    </SPAN>
// Get the SN from the text box on the selected row    </SPAN>
TableCell snCell = selectedRow.Cells[0];    
TextBox tbox = (TextBox)snCell.FindControl("txtSN");    
string stSN = tbox.Text.ToString(); <--the bit that doesnt work
I have no idea why this wont work. It is the same as another web form with the exception of the control names.

Can anyone point me in the right direction?

Thanks

MonkeyMan
 
Old February 26th, 2010, 04:35 AM
Authorized User
 
Join Date: Nov 2008
Posts: 21
Thanks: 3
Thanked 0 Times in 0 Posts
Send a message via MSN to MonkeyMan666
Default

I deleted and re-created the form but changing the code slightly and it seemed to do the trick.
The code was changed to:
Code:
 
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = gvwSecond.Rows[index];
int secondID = int.Parse(row.Cells[1].Text);
TextBox txtsn = ((TextBox)row.FindControl("txtSecSN")); 
string sn = txtsn.Text;
I'm not sure if tehre was anything lingering in the design classes which I didnt see which was stopping the value being picked up but it is working now





Similar Threads
Thread Thread Starter Forum Replies Last Post
Retrieving value from textbox in a Gridview julius C# 2005 1 March 12th, 2009 08:12 AM
GridView Textbox Limno .NET Framework 1.x 0 May 28th, 2008 02:35 PM
Dynamic textbox generation into gridview dharmeshtandel ASP.NET 2.0 Basics 3 December 24th, 2007 02:14 AM
TextBox inside GridView michurin ASP.NET 2.0 Basics 2 January 13th, 2007 12:51 PM
Masked TextBox & formatting TextBox melvik C# 1 September 22nd, 2003 11:01 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.