Read value from a Textbox in a grid view.

F

Felix Wafytech

Hello,

I have a grid view with a template column and a button column. This template
field contains a textbox in the Item Template tab. Entering a value in the
text box and clicking on the button in that row should retrieve the value
entered and insert it into another gridview. The problem here is, I'm unable
to retrieve the value entered in the text box on the button click event. Can
someone help me on how I could retrieve the value in the text box?

Note that the grid is not in edit mode. There are other columns in the grid
that display the data in read-only mode. BTW, I do not want to use a command
button to edit and update data because I do not want to update the database
here. I just need to retrieve the value entered by the user in text box when
the button in that row is clicked.

Thanks in advance for all the help. Your help is very much appreciated.

Thanks,
Felix.J
 
V

vMike

Felix Wafytech said:
Hello,

I have a grid view with a template column and a button column. This template
field contains a textbox in the Item Template tab. Entering a value in the
text box and clicking on the button in that row should retrieve the value
entered and insert it into another gridview. The problem here is, I'm unable
to retrieve the value entered in the text box on the button click event. Can
someone help me on how I could retrieve the value in the text box?

Note that the grid is not in edit mode. There are other columns in the grid
that display the data in read-only mode. BTW, I do not want to use a command
button to edit and update data because I do not want to update the database
here. I just need to retrieve the value entered by the user in text box when
the button in that row is clicked.

Thanks in advance for all the help. Your help is very much appreciated.

Thanks,
Felix.J
You would do something along the following lines. Each "submit" button will
have an ID which is the id you specify plus what .net adds to the name.
Your text boxes will do the same. So the id of the button and the id of the
text box will have the same "stuff" added to them except for the base name.
With that in mind you would do something like the following

Sub ButtonSubmit_Click(sender as object, e as eventargs)
dim strTextBoxID as string
dim tbox1 as textbox
dim buttton1 as button
dim strButton1ID as string
button1 = DirectCast(sender,textbox)
strButton1ID = button1.uniqueid
strTextBoxID =
strSender1.replace("idbasenamebforbutton","idbasenamefortextbox")
tbox1 = ctype(Page.findcontrol(strTextBoxID),textbox)
yourtextintextbox1 = tbox1.text

End Sub
 
V

vMike

Having a bad day... button1 = DirectCast(sender,textbox)
should read button1 = DirectCast(sender,button)
 
S

Steven Cheng[MSFT]

Hi Felix,

I think you can use databinding to bind the rowIndex of each row to the
Button's CommandArgument(or Command) property so that you can read it
later. Then, in button's click event, you can get the current Row(where the
button in) through the CommandArgument(or Command ) propety you set early
and use FindControl to locate the certain controls you want in Gridview Row
or Column. How do you think?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 
V

vMike

Steven Cheng said:
Hi Felix,

I think you can use databinding to bind the rowIndex of each row to the
Button's CommandArgument(or Command) property so that you can read it
later. Then, in button's click event, you can get the current Row(where
the
button in) through the CommandArgument(or Command ) propety you set early
and use FindControl to locate the certain controls you want in Gridview
Row
or Column. How do you think?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Agreed, something like this would work too. This is an imagebutton snip
using an earlier set command argument.

Sub Unlock_Click(sender as object, e as ImageClickEventArgs)
dim ctl as imagebutton = ctype(Sender, imagebutton)
dim intID as int32 = ctype(ctl.commandargument, int32)
dim intOffset as int32 = (BlogGrid1.PageIndex) * BlogGrid1.PageSize
Dim row As GridViewRow = BlogGrid1.Rows(intID-intOffset)
dim ctl2 as textbox = ctype(row.findcontrol("Title1"),textbox)

Mike
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top