Monday, February 2, 2015

Passing-parameter-value-through-a-function-from-anchor-tag-in-a-gridview

We have a requirement where we have to pass Session values and DataBound values to Javascript function using Anchor tag in Gridview.

Following is the Anchor defined in the Gridview where we are passing Session and Eval values as parameter to the Javascript function

OpenAttachmentWindow(roomId,StudentId,Id).


Javascript function description

<script language="javascript" type="text/javascript">

       function OpenAttachmentWindow(roomId, StudentId, Id)
         {
             var ReadOnly = 0;

             window.open('UploadSupplierAttachments.aspx?roomId=' + roomId + '&studentId=' +
             StudentId + '&id=' + Id + '&ReadOnly=' + ReadOnly, '', 'width=700,height=500')
         
          }

   </script>


Gridview Template column

We have anchor html control which will pas the server side arguments to javascript function.

<asp:TemplateField HeaderText="view">

    <ItemTemplate>

           <a  onclick='<%# "OpenAttachmentWindow(" +Session["roomId"] + " , " +        
           Session["StudentId"] + ", " + Eval("Id") +" );" %>'  id="a1" runat="server" >Attachment </a>

    </ItemTemplate>

</asp:TemplateField>


No comments: