473,657 Members | 2,401 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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:BoundFie ld DataField="Col1 " HeaderText="Col umn 1"/>
<asp:TemplateFi eld HeaderText="Col umn2">
<ItemTemplate >
<asp:TextBox ID="txt" OnTextChanged=" OnTextChanged"
Autopostback=tr ue Columns=15 runat="server" Text='<%# Bind("Column2Da ta")
%>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateFie ld>
Protected Sub OnTextChanged(B yVal sender as Object, ByVal e as EventArgs)
'some procedures here
End Sub


Dec 12 '07 #1
2 8505
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.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
<testerwrote in message news:O2******** ******@TK2MSFTN GP05.phx.gbl...
>I have a gridview with a textbox in an ItemTemplate, as below. The
OnTextChange d 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:BoundFie ld DataField="Col1 " HeaderText="Col umn 1"/>
<asp:TemplateFi eld HeaderText="Col umn2">
<ItemTemplate >
<asp:TextBox ID="txt" OnTextChanged=" OnTextChanged"
Autopostback=tr ue Columns=15 runat="server" Text='<%# Bind("Column2Da ta")
%>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateFie ld>
Protected Sub OnTextChanged(B yVal sender as Object, ByVal e as EventArgs)
'some procedures here
End Sub


Dec 12 '07 #2
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 DataControlFiel dCell = 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.F indControl("myC ontrol"), textbox)

'do whatever

"Eliyahu Goldin" <RE************ **************@ mMvVpPsS.orgwro te in
message news:O3******** ******@TK2MSFTN GP02.phx.gbl...
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.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
<testerwrote in message news:O2******** ******@TK2MSFTN GP05.phx.gbl...
>>I have a gridview with a textbox in an ItemTemplate, as below. The
OnTextChang ed 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:GridVie w ID="gv" />
<Columns>
<asp:BoundFie ld DataField="Col1 " HeaderText="Col umn 1"/>
<asp:TemplateFi eld HeaderText="Col umn2">
<ItemTemplate >
<asp:TextBox ID="txt" OnTextChanged=" OnTextChanged"
Autopostback=t rue Columns=15 runat="server" Text='<%# Bind("Column2Da ta")
%>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateFie ld>
Protected Sub OnTextChanged(B yVal sender as Object, ByVal e as EventArgs)
'some procedures here
End Sub



Dec 12 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3817
by: Damon | last post by:
Help! Need this fixed ASAP. I have a GridView/DetailsView master/details form set up, with both bound to separate ObjectDataSource objects. Both the GridView and the DetailsView have a DataKeyNames parameter of "UserCompany, BillableCompany". The DetailsView has control parameters for its select method pointing to these two keys on the GridView. But the select method function receives two copies of the UserCompany field! The...
0
1822
by: David Hubbard | last post by:
I am using a GridView to display a set of objects that have a parent-child relationship. Each object, MyBO, has an ID property that is used to get the children of that object. class MyBO { int _id; String _name;
3
2155
by: rodchar | last post by:
hey all, i have a gridView with editing available. when a user clicks the update link for a row, how do i pass the entire data table as a parameter to my business layer? thanks, rodchar
5
2732
by: pbearne | last post by:
Hi guys I am trying to this function below I have a web form with a load of inputs text boxs etc and i need to disable them So I have tried to write a function I can call and get the function to work the type of the input so can disaable as needed
2
5093
by: darren.murray2 | last post by:
Hello all, I'm fairly new at this so I may be doing this the wrong way but I've got a FormView within a multiview that when it is updated in edit mode, will call on the update method associated with the objectdatasource that fills the formview. Problem: One of the fields is a textbox that when clicked has to open up a popup window with a listbox and when that popup closes, it sends the
2
5589
by: dotnetdev01 | last post by:
hello, i want to increment/decrement the value in textbox on the click event of image button placed on the gridview. i m using item template. both textbox and imagebuttons are in item template. can u help!!!
2
3602
by: rajkm42 | last post by:
Hi friends, I have a gridview which loads an XML file to display a textbox and other dropdownlists. Which is used for data entry. The user will enter an empid in the textbox. Once leaving the textbox(for example after pressing tab), I need to fire Blur event of that textbox and retrieve the empname and display in the next column of the textbox in the gridview. How can I fire the blur event of textbox?
1
2319
by: adepvivek | last post by:
Hi everybody, I am using textbox in gridview as template. And I want to stored the value of textbox. For that I want to pass the textbox value to stored procedure. So please give me solution.
4
2941
by: ismailc | last post by:
Hi, I need help please. I need to create a textbox with a report url in an iframe below. Onclick of button create IFrame and pass textbox value into parameter of iframe src. I'm not to sure how to do this, i think some javascript is needed as I want the button to check the textbox is not blank value first and then create iframe and pass textbox value as parameter. Does anyone have another method where there are 2 iframes: Having the...
0
8402
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8315
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8508
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8608
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7341
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4164
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4323
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1962
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1627
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.