Call Javascript from GridView ItemTemplate

Discussion in 'ASP .Net' started by Mel, Jan 7, 2009.

  1. Mel

    Mel Guest

    When the GridView link button is clicked I want to first set a textbox
    to a value and then call a Javascript function. How do I do this?

    I have a GridView with one column that contains a link button (called
    lbutFabNum) in the ItemTemplate. When the user clicks lbutFabNum I
    want to set a text box value to the lbutFabNum text and then call the
    Done() javascript function.
     
    Mel, Jan 7, 2009
    #1
    1. Advertising

  2. Mel

    Mel Guest

    On Jan 7, 11:10 am, Mel <> wrote:
    > When the GridView link button is clicked I want to first set a textbox
    > to a value and then call a Javascript function.  How do I do this?
    >
    > I have a GridView with one column that contains a link button (called
    > lbutFabNum) in the ItemTemplate.  When the user clicks lbutFabNum I
    > want to set a text box value to the lbutFabNum text and then call the
    > Done() javascript function.


    Nevermind, I figured it out. Here is the code if anyone else is
    interested.

    JAVASCRIPT CODE (IN ASPX FILE)
    function userSelected(fabnum)
    {
    document.getElementById('txtEntry').value=fabnum; //set
    the text box to the value from the GridView link button
    Done(); //call the Done Javascript function to pass the
    fab number back to the parent window
    }

    VB.NET CODE (IN ASPX.VB FILE)
    Protected Sub gvJobMaster_RowDataBound(ByVal sender As Object,
    ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles
    gvJobMaster.RowDataBound 'this is my GridView Control
    If (e.Row.RowType = DataControlRowType.DataRow) Then
    Dim seldata As String = e.Row.DataItem(0).ToString 'get
    column zero data (link button value)
    e.Row.Attributes.Add("onclick", "userSelected('" + seldata
    + "')") 'call javascript function
    End If
    End Sub
     
    Mel, Jan 7, 2009
    #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. Bennett Haselton
    Replies:
    1
    Views:
    5,344
    Joe Fallon
    Sep 24, 2004
  2. ABC
    Replies:
    1
    Views:
    955
    Patirck Ige
    Oct 7, 2005
  3. =?Utf-8?B?RGFiYmxlcg==?=

    use data from second sqldatasource in gridview itemtemplate?

    =?Utf-8?B?RGFiYmxlcg==?=, Mar 20, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    4,065
    =?Utf-8?B?RGFiYmxlcg==?=
    Mar 21, 2006
  4. =?Utf-8?B?RGFiYmxlcg==?=
    Replies:
    2
    Views:
    3,500
    =?Utf-8?B?RGFiYmxlcg==?=
    Apr 12, 2006
  5. Didg
    Replies:
    1
    Views:
    116
Loading...

Share This Page