Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / December 2007

Tip: Looking for answers? Try searching our database.

How to pass a parameter to an event from a textbox in a gridview

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tester - 12 Dec 2007 02:00 GMT
I have a gridview with a textbox in an ItemTemplate, as below.  The
OnTextChanged event fires okay but how do I pass a parameter to it, I get an
error when I try "OnTextChanged(""SomeData"")".  I would also like to pass
in the value of column 1.   I would also like to be able to get the row the
user is on when this event fires.  Thank you for your help.

<asp:GridView ID="gv" />
      <Columns>
           <asp:BoundField DataField="Col1" HeaderText="Column 1"/>
          <asp:TemplateField HeaderText="Column2">
              <ItemTemplate>
                  <asp:TextBox ID="txt" OnTextChanged="OnTextChanged"
Autopostback=true Columns=15 runat="server" Text='<%# Bind("Column2Data")
%>'></asp:TextBox>
              </ItemTemplate>
          </asp:TemplateField>

Protected Sub OnTextChanged(ByVal sender as Object, ByVal e as EventArgs)
   'some procedures here
End Sub
Eliyahu Goldin - 12 Dec 2007 09:17 GMT
You don't need to pass, you can figure it out in the event handler. The
sender parameter points on the textbox. The textbox is inside a TableCell.
The TableCell is inside a row. With this understanding you can navigate up
from the sender to the containing row using Parent property.

Signature

Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net

>I have a gridview with a textbox in an ItemTemplate, as below.  The
>OnTextChanged event fires okay but how do I pass a parameter to it, I get
[quoted text clipped - 16 lines]
>    'some procedures here
> End Sub
tester - 12 Dec 2007 20:16 GMT
Thanks!  that works great! This is my code if it helps anyone, quite simple!
Dim txt as TextBox

'get the cell the control that triggered this event is in

Dim parent1 as DataControlFieldCell = sender.parent

'get the row the cell is in that the control is in that triggered this
event - got that?

Dim parent2 as Gridviewrow = parent1.parent

txt = cType(Parent2.FindControl("myControl"), textbox)

'do whatever

> You don't need to pass, you can figure it out in the event handler. The
> sender parameter points on the textbox. The textbox is inside a TableCell.
[quoted text clipped - 21 lines]
>>    'some procedures here
>> End Sub

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.