How to read input from a textfield in a datagrid !?!

Discussion in 'ASP .Net Web Controls' started by Remco Groot Beumer, Nov 6, 2003.

  1. Hello,

    I'm working with a datagrid control in ASP.NET. The datagrid shows a list of
    products. One column shows the productnumber, one column shows the
    productname, one column shows a picture of the product and the last column
    shows an empty textbox with an 'OK' button.

    People can enter a quantity in the empty textbox. After clicking on the 'OK'
    button, the product and quantity should be added to another datagrid. The
    problem is that I don't know how to read the quantity. I now do this as
    follows (cells(5) is the template-column with the textbox, the 'OK' button
    triggers the SelectedIndexChanged event):

    Private Sub grdArtikelen_SelectedIndexChanged(ByVal sender As System.Object,
    ByVal e As System.EventArgs) Handles grdArtikelen.SelectedIndexChanged

    Dim txb As TextBox
    =CType(Me.grdProducts.SelectedItem.Cells(5).Controls(1), TextBox)

    Dim dblQuantity As Double

    dblQuantity = CType(txb.Text, Double)

    End Sub



    This code gets the right textbox, but the TEXT property is always empty. How
    can I get the text that has been entered in the textbox?

    Any help would be appreciated.

    Greetings,

    Remco
    Remco Groot Beumer, Nov 6, 2003
    #1
    1. Advertising

  2. Remco Groot Beumer

    SSW Guest

    Hi,

    To trap the even form BtnOk in Datagid, U need to trap Datagid Event Name "ItemCommand".
    Follow the step as below.

    1) Give BtnOk CommandName let's say grdArtikelen_ BtnOk
    2) Attach a Event ItemCommand to Datagrid(Event name will be grdArtikelen_ItemCommand)
    3) Check e.CommandName if it is grdArtikelen_ BtnOk then procide with ur Process.

    Below is the same code in C#.
    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Sample Code Event tape for Datagrid grdArtikelen ItemCommand
    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    private void grdArtikelen_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
    if(e.CommandName=="grdArtikelen_ BtnOk")
    {
    Response.Write("Yes U Got It :)");
    Response.Write(((TextBox)(grdArtikelen.Items[e.Item.ItemIndex].Cells[0].FindControl("txtQty"))).Text); // To Read TextBox Value.
    // Place ur code here to Process on BtnOk Click
    }
    }

    Hope this helps.

    Thanks,

    sswalia
    MCSD, MCAD, OCA

    "Remco Groot Beumer" <> wrote in message news:bodr3p$75f$1.nb.home.nl...
    > Hello,
    >
    > I'm working with a datagrid control in ASP.NET. The datagrid shows a list of
    > products. One column shows the productnumber, one column shows the
    > productname, one column shows a picture of the product and the last column
    > shows an empty textbox with an 'OK' button.
    >
    > People can enter a quantity in the empty textbox. After clicking on the 'OK'
    > button, the product and quantity should be added to another datagrid. The
    > problem is that I don't know how to read the quantity. I now do this as
    > follows (cells(5) is the template-column with the textbox, the 'OK' button
    > triggers the SelectedIndexChanged event):
    >
    > Private Sub grdArtikelen_SelectedIndexChanged(ByVal sender As System.Object,
    > ByVal e As System.EventArgs) Handles grdArtikelen.SelectedIndexChanged
    >
    > Dim txb As TextBox
    > =CType(Me.grdProducts.SelectedItem.Cells(5).Controls(1), TextBox)
    >
    > Dim dblQuantity As Double
    >
    > dblQuantity = CType(txb.Text, Double)
    >
    > End Sub
    >
    >
    >
    > This code gets the right textbox, but the TEXT property is always empty. How
    > can I get the text that has been entered in the textbox?
    >
    > Any help would be appreciated.
    >
    > Greetings,
    >
    > Remco
    >
    >
    SSW, Nov 10, 2003
    #2
    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. Remco Groot Beumer

    How to read input from a textfield in a datagrid !?!

    Remco Groot Beumer, Nov 6, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    301
    Remco Groot Beumer
    Nov 6, 2003
  2. Remco Groot Beumer

    How to read input from a textfield in a datagrid !?!

    Remco Groot Beumer, Nov 6, 2003, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    124
  3. Remco Groot Beumer

    How to read input from a textfield in a datagrid !?!

    Remco Groot Beumer, Nov 6, 2003, in forum: ASP .Net Web Services
    Replies:
    2
    Views:
    111
  4. Stumped and Confused

    Output VALUE of INPUT textfield using document.write

    Stumped and Confused, Sep 17, 2004, in forum: Javascript
    Replies:
    13
    Views:
    263
    Richard Cornford
    Sep 23, 2004
  5. Replies:
    3
    Views:
    217
    Amer Neely
    Nov 22, 2006
Loading...

Share This Page