Call Javascript from GridView ItemTemplate

M

Mel

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

Mel

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top