473,326 Members | 2,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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: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


Dec 12 '07 #1
2 8477
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**************@TK2MSFTNGP05.phx.gbl...
>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


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 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

"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:O3**************@TK2MSFTNGP02.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**************@TK2MSFTNGP05.phx.gbl...
>>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



Dec 12 '07 #3

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

Similar topics

2
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...
0
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 { ...
3
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
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...
2
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...
2
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...
2
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...
1
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
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.