.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

how to call a javascript function on rowcommand event of gridview

Posted By: radhika     Posted Date: November 01, 2010    Points:2   Category :ASP.Net
My requirement is when I select any record from gridview then I set the textbox value 1. For that I wrote javascript fn settxtvalue1. I am using rowcommand event.
I have to call javascript fn in gridview. How to do it?

Html Src
<script type="text/javascript">

function settxtvalue1()


<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowCommand="GridView1_RowCommand" GridLines="None">
<asp:ButtonField ButtonType="Button" CommandName="Select" Text="Select" />
<asp:BoundField DataField="name" HeaderText="Name">


Code Behind

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)

if (e.CommandName == "Select")
int rowIndex = Convert.ToInt32(e.CommandArgument);
txtname.Text = GridView1.Rows[rowIndex].Cells[1].Text;


conn = new SqlConnection(ConnectionString);

cmd = new SqlCommand("select id from example where name ='" + txtname.Text + "' ", conn);
da = new SqlDataAdapter(cmd);


Author: Jean Paul             
Posted Date: November 02, 2010     Points: 5   

The row command happens on the server side.

Javascrip call should happen on the client side.

Jean Paul http://jeanpaulva.com/

Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend