Home All Groups Group Topic Archive Search About

Change/read value from control in EditItemTemplate

Author
22 Apr 2005 2:30 PM
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

Author
23 Apr 2005 7:53 PM
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



posti***@alexshirley.com wrote:
Show quoteHide quote
> 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
>
Author
28 Apr 2005 3:40 PM
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
Author
8 May 2005 7:53 PM
Scott Mitchell [MVP]
posti***@alexshirley.com wrote:
Show quoteHide quote
> 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?

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
Author
28 Apr 2005 3:41 PM
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