How to get values of a textbox in a datagrid?

  • Thread starter Thread starter Guest
  • Start date Start date
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.
 
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
 
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.
 
Back
Top