Solved

Call javascript function from header in Datagrid

Posted on 2007-11-22
3
860 Views
Last Modified: 2008-02-01
I have the following datagrid, and I want to set the onclick attribute in the code behind or in the client side page to call a javascript function.  I am using vb.net version 2.0. Does anyone know how to do this? Thanks.


<asp:datagrid id="gdExperts" runat="server"  AllowSorting="True" CellPadding="2" DataKeyField="UserID" AutoGenerateColumns="False" >
<ItemStyle></ItemStyle>
<HeaderStyle></HeaderStyle>
<FooterStyle></FooterStyle>
<Columns>
<asp:TemplateColumn HeaderText="SELECT">
<HeaderStyle Width="25px"></HeaderStyle>
<ItemStyle Wrap="False"></ItemStyle>
<ItemTemplate>
<span><a href="javascript:AssignExpert('function')">name</a></span>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
0
Comment
Question by:wilcor14
3 Comments
 
LVL 17

Accepted Solution

by:
gops1 earned 500 total points
Comment Utility
Try using onClientClick
<asp:datagrid OnClientClick="alert('Hello')" id="gdExperts" runat="server"  AllowSorting="True" CellPadding="2" DataKeyField="UserID" AutoGenerateColumns="False" >

Open in new window

0
 
LVL 39

Expert Comment

by:Pratima Pharande
Comment Utility
Try like this
<asp:datagrid id="gdExperts" runat="server"  AllowSorting="True" CellPadding="2" DataKeyField="UserID" AutoGenerateColumns="False" >

<ItemStyle></ItemStyle>

<HeaderStyle></HeaderStyle>

<FooterStyle></FooterStyle>

<Columns>

<asp:TemplateColumn HeaderText="SELECT">

<HeaderStyle Width="25px"></HeaderStyle>

<ItemStyle Wrap="False"></ItemStyle>

<ItemTemplate>

<span><a href="#" OnClick="javascript:AssignExpert('function')">name</a></span>

</ItemTemplate>

</asp:TemplateColumn>

</Columns>

</asp:datagrid>

Open in new window

0
 

Author Comment

by:wilcor14
Comment Utility
I figured it out:
<Columns>
<asp:TemplateColumn HeaderText="<a href='#' onclick='Experts()'><font color='white'>Experts</font></a>">
<ItemStyle Wrap="False"></ItemStyle>
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now