Change/read value from control in EditItemTemplate

Discussion in 'ASP .Net Datagrid Control' started by postings@alexshirley.com, Apr 22, 2005.

  1. Guest

    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
     
    , Apr 22, 2005
    #1
    1. Advertising

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



    wrote:
    > 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
    >
     
    Scott Mitchell [MVP], Apr 23, 2005
    #2
    1. Advertising

  3. Guest

    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
     
    , Apr 28, 2005
    #3
  4. Guest

    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
     
    , Apr 28, 2005
    #4
  5. wrote:
    > 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
     
    Scott Mitchell [MVP], May 8, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?cGhpbGxpcA==?=
    Replies:
    2
    Views:
    446
    =?Utf-8?B?cGhpbGxpcA==?=
    Mar 11, 2005
  2. Replies:
    1
    Views:
    1,788
    Grant Merwitz
    Sep 27, 2005
  3. xazos79
    Replies:
    0
    Views:
    420
    xazos79
    Dec 19, 2005
  4. =?Utf-8?B?Tkg=?=
    Replies:
    2
    Views:
    29,324
    =?Utf-8?B?Tkg=?=
    Mar 27, 2006
  5. Christian Perthen

    FormView, change default to EditItemTemplate

    Christian Perthen, Dec 27, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    357
    Christian Perthen
    Dec 27, 2006
Loading...

Share This Page