Solved

Call javascript function from header in Datagrid

Posted on 2007-11-22
3
867 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 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

690 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