开发者

Gridview ItemTemplate OnClientClick javascript function with DataItem value as parameter

开发者 https://www.devze.com 2023-01-11 03:51 出处:网络
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 func

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(<%#B开发者_开发百科ind("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?


See this:

loading gridview with hyperlink column

I think you should use DataBinder.Eval(Container, "DataItem.YourProperty").


You can also try like this:

<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>

This will help you when there is need to pass one or more variables to javascript function.

0

精彩评论

暂无评论...
验证码 换一张
取 消