473,568 Members | 2,935 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get values of a textbox in a datagrid?

I have a datagrid and I created a textbox and a button in a column of every
row. How do I make it such that when the user click the button, i can get the
value entered in the textbox, and how do I know which row are the textbox and
the button that is clicked located? And how do I include the button_Click
event in my code?

Does anyone has any idea? Thank you.
Nov 19 '05 #1
2 2087
Hi wrytat

Answer to the question : how do I include the button_Click event in my code?

First assign some value to commandName property to your button. When you
click the button the datagrid's ItemCommand event will trigger. There you
can handle that event by checking the commandname as like

Suppose i assigned "Add" as commandName for button
then in ItemCommand you can check which button is clicked

if(e.CommandNam e == "Add" )
{

//Add the code
}

To identify which button clicked, you can use CommandArgument property of
button.

To get the textbox value, first you get a reference to the textbox.

Textbox text1 = (TextBox)e.Item .FindControl("t xtTest"); // txtTest is
textbox name
String someValue = text1.Text;

regards
charmis
Nov 19 '05 #2
> Suppose i assigned "Add" as commandName for button
then in ItemCommand you can check which button is clicked
What is an command argument? Where can I find it?
To identify which button clicked, you can use CommandArgument property of
button.

To get the textbox value, first you get a reference to the textbox.

Textbox text1 = (TextBox)e.Item .FindControl("t xtTest"); // txtTest is
textbox name
String someValue = text1.Text;


What is ItemCommand? But I'll have so many text1 because I've a textbox in
every row.

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3186
by: Morné | last post by:
Hi how do I validate a text value in a datagrid e.g. the user is only allowed to type in a Y or a N. I specifically have a problem with using the PropertyDescriptorCollection. I get the following error: "Additional information: Cannot create a child list for field Query." Below my existing code:
0
1470
by: Paolo Tardivel via DotNetMonster.com | last post by:
I have a databound datagrid containing template columns which allow editing of the values contained in the datagrid through the use of text boxes. One of the fields in the datagrid displays the time and date. When a row has been selected for editing I want to be able to click a button in the datagrid and update one of the text boxes with the...
3
4923
by: Kevin Pedersen | last post by:
Hello, I am using an editable datagrid. After I save the changes the datagrid shows the old values. I've read the posts about the Page_Load and not binding the datagrid each time. The SQL that is being sent to the database is correct and the changes are eventually being made. If I refresh the page after the update then the new values...
0
1050
by: Mike | last post by:
I've got an app with a DataTable that gets passed around and modified by datagrids on 3 different asp.net pages. Not all columns need to be displayed, but I need them all in the datagrid so I can call the LoadDataRow method to update the DataTable "in place". I've been using boundcolumns for the invisible fields, which worked fine, but now...
0
1802
by: Newasps | last post by:
Hi guys, I have a problem with UpdateCommand Event. In tihs event Ä°'m creating required controls to get that controls' values and also get them. But when I try to get updated values I'm getting the first values for each control. Please help me. Thanks for any help. Bye Ozer And here's my code: Imports System Imports System.Data...
0
1526
by: Ozer | last post by:
Hi guys, I need some help. In my datagrid's updatecommand event i'm trying to get textboxes values and also do it. But when i update the values in textboxes and fire the event, I can't get the updated values. Please help me. Thanks for any help. Bye. Ozer And here's my code: Imports System Imports System.Data Imports System.Data.OleDb
3
1327
by: MaryA | last post by:
I have an asp.net application in which i have a form containing a datagrid when using the update command event i have: tb = CType(e.Item.Cells(3).Controls(0), TextBox) subject = tb.Text this code is supposed to get the new data entered in the text box but i am getting the old data why?
1
1382
by: Arjen Hoekstra | last post by:
Hello, I've got a datagrid with a textbox in each cell. I've also two buttons, one to add a row to the datagrid and one to delete a row. A user can type data into textboxes and then submit it to a database (by clicking on a submit button). The problem is that every time, the "add row" or "delete row" button is clicked, the textbox values...
2
1686
by: Kiran Kumar Pinjala | last post by:
Hi, May be this is silly, or I just need a second pair eyes to look at this. I am trying to get values that I have edited in a datagrid and update the values with those values. Here is the code that I am using in my update command. TextBox txtProdName = (TextBox)e.Item.Cells.Controls; TextBox txtSuppID = (TextBox)e.Item.Cells.Controls;...
7
2183
by: Aaron | last post by:
Complete code follows. I am new to .NET programming (and programming in general) and I am having a difficult time understanding how to fill a variable in one sub, and then access it from another. I have tried declaring them as shared, public, friend, etc and I always get an error stating that something is not valid on a local variable...
0
7693
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7917
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8118
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7665
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2105
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
933
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.