Change/read value from control in EditItemTemplate

P

postings

Hi

In my datagrid I have a textbox in an EditItemTemplate like so

--------------------
<asp:TextBox id=txtPrice ontextchanged="txtPrice_TextChanged"
runat="server" AutoPostBack="True">
--------------------

I also have back end code like this:


--------------------
Sub txtPrice_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Response.Write("BOING!")

'This won't get the textbox controls I need, what should I do?
'Dim txtPrice As TextBox
=MyDataGrid.Items(e.Item.ItemIndex).FindControl("txtPrice")
'Dim txtDiscount As TextBox =
MyDataGrid.Items(e.Item.ItemIndex).FindControl("txtDiscount")
'Dim txtTotal As TextBox =
MyDataGrid.Items(e.Item.ItemIndex).FindControl("txtTotal")

End Sub
--------------------

This code works fine (Note I've remmed out the last three lines).

I basically need to get control of the textbox controls in the edititem
template so I can get their values and update them.

If I take out the rems it won't work (e points to system.eventargs,
not WebControls.DataGridCommandEventArgs). So I need something else.

What code do I need to get control of the textboxes in
edititemtemplate?

Many thanks!

Alex
 
S

Scott Mitchell [MVP]

In the TextChanged event handler sender is the TextBox control that
caused the event. So, you can get a reference to the TextBox using:

Dim myTB as TextBox = CType(sender, TextBox)

hth
 
P

postings

Thanks Scott (sorry I've been away fixing another datagrid problem
before I could get back to this one!)...

This works great (doh I should have realised this! - thanks)...
I now get the value of the textbox now, from my subroutine triggered
via autopostback:
Dim myTB as TextBox = CType(sender, TextBox)

I now need to get the values of other textboxes inside the datagrid,
and update the value of another textbox inside the datagrid - from this
same subroutine which is triggered by autopostback.

How can I get the values of these controls form the datagrid?

Cheers!

Alex
 
P

postings

Thanks Scott (sorry I've been away fixing another datagrid problem
before I could get back to this one!)...

This works great (doh I should have realised this! - thanks)...
I now get the value of the textbox now, from my subroutine triggered
via autopostback:
Dim myTB as TextBox = CType(sender, TextBox)

I now need to get the values of other textboxes inside the datagrid,
and update the value of another textbox inside the datagrid - from this
same subroutine which is triggered by autopostback.

How can I get the values of these controls from the datagrid?

Cheers!

Alex
 
S

Scott Mitchell [MVP]

Thanks Scott (sorry I've been away fixing another datagrid problem
before I could get back to this one!)...

This works great (doh I should have realised this! - thanks)...
I now get the value of the textbox now, from my subroutine triggered
via autopostback:




I now need to get the values of other textboxes inside the datagrid,
and update the value of another textbox inside the datagrid - from this
same subroutine which is triggered by autopostback.

How can I get the values of these controls form the datagrid?

I trust you know how to get the controls when you have a reference to
the DataGridItem? If so, you can get the DataGridItem that contains the
TextBox using the following code:

Dim dgi as DataGridItem = CType(myTB.Parent.Parent, DataGridItem)

hth
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top