?
Solved

Call javascript function from header in Datagrid

Posted on 2007-11-22
3
Medium Priority
?
868 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 17

Accepted Solution

by:
gops1 earned 2000 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…
Suggested Courses

777 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