1

I have a button inside my <ItemTemplate> in GridView and I want to call a javascript function on the OnClientClick of that button passing the DataItem value as a parameter of the javascript function

<ItemTemplate>
    // Labels and Html styles
    ....
    <asp:Button ID="btnEdit" runat="server" Text="Edit" OnClientClick='javascript:CreateEditAddress(<%#Bind("Id") %>);' />
    <asp:Button ID="btnDelete" runat="server" Text="Delete" />
</ItemTemplate>

If I will not put a parameter in CreateEditAddess() this works well but I need the parameter.

I know I can put the OnClientClick event value in OnRowDataBound event of the gridview but I don't want to put it in CodeBehind. It seems like the server tag is not parsed correctly.

Am I missing something here?

4

2 回答 2

1

你也可以这样尝试:

<asp:TemplateField HeaderText="Link"> 
  <ItemTemplate> 
      <asp:HyperLink runat="server" ID="HLink" 
          Text='<%# Eval("FirstName").ToString() + " " + Eval("LastName").ToString()%>' 
          NavigateUrl='<%# "javascript:OpenPopup(" + "&#39;" + Eval("EmpId") + "&#39;);"   %> ' />
  </ItemTemplate> 
</asp:TemplateField>

这将在需要将一个或多个变量传递给 javascript 函数时为您提供帮助。

于 2014-07-14T09:00:19.137 回答
1

看到这个:

加载带有超链接列的gridview

我认为你应该使用DataBinder.Eval(Container, "DataItem.YourProperty").

于 2010-08-13T03:53:45.183 回答