Solved

Call javascript function from header in Datagrid

Posted on 2007-11-22
3
863 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
ID: 20337271
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
ID: 20337346
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
ID: 20348146
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…

773 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