Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Datagrid templatecolumn, passing parameters
Message
From
28/05/2004 17:17:18
 
 
To
All
General information
Forum:
ASP.NET
Category:
Web forms
Title:
Datagrid templatecolumn, passing parameters
Miscellaneous
Thread ID:
00908339
Message ID:
00908339
Views:
48
Hi,

I have a datagrid with several boundcolumns and one TemplateColumn. I am using a TemplateColumn because I would like to call a javascript function to open a URL in a window with specific attributes. IE: no toolbar and of a specific size.

Before I get too specific about the javascript function I thought I would simply attempt to activate an alert window. That works just fine.

An HTML view of the javscript and TemplateColumn is seen below.
<script language="javascript">
  function TestFunction()
   {
     alert("test message:" )
   }
</script>


<asp:TemplateColumn HeaderText="txnotes">
<HeaderStyle Width="10%"></HeaderStyle>
<ItemStyle Font-Size="XX-Small" Font-Names="Arial"></ItemStyle>
<ItemTemplate>
  <asp:HyperLink runat="server"  NavigateUrl='javascript:TestFunction()'  Text='<%# DataBinder.Eval(Container, "DataItem.custid") %>'       ID="link1" NAME="HyperLink21">
  </asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>
After the grid is rendered I can click on the HyperLink, which displays a customer's ID (custid) because a set it in the Text attribute, and an alert window pops up.
But now I want to pass the customer's ID (custid) to the javascript function. How do you do it?

I modified the Javascript function like this to receive custid:
<script language="javascript">
  function TestFunction(tcCustID)
   {
     alert("test message:" + tcCustID)
   }
</script>
The next part is where I am lost. How to I pass custid ot the function? Based on how I am setting the Text attribute of the HyperLink, namely: Text='<%# DataBinder.Eval(Container, "DataItem.custid") %>', I thought I could do something similar like this but it does not work.
<asp:TemplateColumn HeaderText="txnotes">
<HeaderStyle Width="10%"></HeaderStyle>
<ItemStyle Font-Size="XX-Small" Font-Names="Arial"></ItemStyle>
<ItemTemplate>
  <asp:HyperLink runat="server"  NavigateUrl='javascript:TestFunction(<%# DataBinder.Eval(Container, "DataItem.custid") %>)'  Text='<%# DataBinder.Eval(Container, "DataItem.custid") %>'       ID="link1" NAME="HyperLink21">
  </asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>
Next
Reply
Map
View

Click here to load this message in the networking platform