Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Call Javascript from GridView ItemTemplate

Reply
Thread Tools

Call Javascript from GridView ItemTemplate

 
 
Mel
Guest
Posts: n/a
 
      01-07-2009
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.
 
Reply With Quote
 
 
 
 
Mel
Guest
Posts: n/a
 
      01-07-2009
On Jan 7, 11:10*am, Mel <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
format datetime in GridView ItemTemplate? =?Utf-8?B?RGFiYmxlcg==?= ASP .Net 2 04-12-2006 03:46 AM
SqlDataSource param in ItemTemplate can't find GridView bound cont =?Utf-8?B?RGFiYmxlcg==?= ASP .Net 2 04-12-2006 02:44 AM
use data from second sqldatasource in gridview itemtemplate? =?Utf-8?B?RGFiYmxlcg==?= ASP .Net 4 03-21-2006 06:36 AM
How to identify which row to be selected in itemtemplate column under gridview? ABC ASP .Net 1 10-07-2005 06:12 AM
can code inside a Repeater's ItemTemplate modify controls in the ItemTemplate? Bennett Haselton ASP .Net 1 09-24-2004 01:59 AM



Advertisments