Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Read value from a Textbox in a grid view.

Reply
Thread Tools

Read value from a Textbox in a grid view.

 
 
Felix Wafytech
Guest
Posts: n/a
 
      05-23-2007
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


 
Reply With Quote
 
 
 
 
vMike
Guest
Posts: n/a
 
      05-23-2007

"Felix Wafytech" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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","idbasen amefortextbox")
tbox1 = ctype(Page.findcontrol(strTextBoxID),textbox)
yourtextintextbox1 = tbox1.text

End Sub




 
Reply With Quote
 
 
 
 
vMike
Guest
Posts: n/a
 
      05-23-2007
Niote


strSender1 should be strButton1ID sorry. I would snipping code

Mike


 
Reply With Quote
 
vMike
Guest
Posts: n/a
 
      05-23-2007
Having a bad day... button1 = DirectCast(sender,textbox)
should read button1 = DirectCast(sender,button)






 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      05-24-2007
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/subscripti...ult.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/subscripti...t/default.aspx.

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



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



 
Reply With Quote
 
vMike
Guest
Posts: n/a
 
      05-24-2007

"Steven Cheng[MSFT]" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pass value from activex textbox to webform textbox AGSHAR ASP .Net 1 05-31-2008 12:00 PM
Getting value of a asp:textbox from grid which is inside repeater tc02435 ASP .Net 0 06-12-2007 01:10 PM
get value from a grid textbox which is inside a repeater tc02435 ASP .Net 0 06-12-2007 12:34 PM
How to transfer a value from an Invisible Grid to an visible Grid =?Utf-8?B?QXNzYW5LaGFuIElzbWFpbA==?= ASP .Net 2 10-17-2005 03:56 AM
Displaying label or textbox in grid depending on value John Dalberg ASP .Net 0 08-12-2004 06:31 PM



Advertisments