How to get values of a textbox in a datagrid?

G

Guest

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

charmis p varghese

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.CommandName == "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("txtTest"); // txtTest is
textbox name
String someValue = text1.Text;

regards
charmis
 
G

Guest

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("txtTest"); // 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.
 

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

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,151
Latest member
JaclynMarl
Top