HighTechTalks DotNet Forums  

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

ASP.net ASP.net discussions (microsoft.public.dotnet.framework.aspnet)


Discuss How to pass a parameter to an event from a textbox in a gridview in the ASP.net forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
 
Posts: n/a

Default How to pass a parameter to an event from a textbox in a gridview - 12-11-2007 , 09:00 PM






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





Reply With Quote
  #2  
Old   
Eliyahu Goldin
 
Posts: n/a

Default Re: How to pass a parameter to an event from a textbox in a gridview - 12-12-2007 , 04:17 AM






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


<tester> wrote

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







Reply With Quote
  #3  
Old   
 
Posts: n/a

Default Re: How to pass a parameter to an event from a textbox in a gridview - 12-12-2007 , 03:16 PM



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" <REMOVEALLCAPITALSeEgGoldDinN (AT) mMvVpPsS (DOT) org> wrote in
message news:O3N5l$JPIHA.4684 (AT) TK2MSFTNGP02 (DOT) phx.gbl...
Quote:
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


tester> wrote

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









Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.