Solved

Call javascript function from header in Datagrid

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

Independent Software Vendors: 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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

735 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