Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to generate gridview dynamically.
I want call javascript function after data completely bind to gridview.provide a solution.
Posted
Updated 30-Sep-16 22:17pm

If you are using JQuery you can use document.getReady method of which will be called after all content of the page are loaded, of course assuming you want this to happen client side.
 
Share this answer
 
If you are using ItemTemplate in your gridView then you need to enable "RowDataBound" inside properties pane ->Events.
Steps to execute Javascript function.
1.Javascript function in your aspx page

C#
function fnPopUp(viewDetails) {
        alert(viewDetails);
    }


2. Create templateField :
XML
<asp:TemplateField HeaderText="View Information">
        <ItemTemplate>
        <asp:LinkButton ID="lnkDisplayPopUp" runat="server"
                Text='<%# Eval("ColumnName") %>' onclick="lnkDisplayPopUp_Click" ></asp:LinkButton>

            &nbsp;

        </ItemTemplate>
        </asp:TemplateField>

3. In events inside properties Pane of GridView RowDataBound specify (GridView_RowDataBound) name of the function which is created behind GridView code file .
3. Write This Code.In order to register your onclick event.
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                LinkButton btnAlert = (LinkButton)e.Row.FindControl("lnkDisplayPopUp");
                DataRowView drv = (DataRowView)e.Row.DataItem;
                string id = drv["ColumnName"].ToString();
                btnAlert.Attributes.Add("onclick", "fnPopUp("+id+");return false;");
            }
        }
 
Share this answer
 
C#
protected void gvListDTL_RowDataBound(object sender, GridViewRowEventArgs e)
       {
           if (e.Row.RowType == DataControlRowType.DataRow)
           {
               try
               {
                   HiddenField hdnRM_Qty = (HiddenField)e.Row.FindControl("hdnRM_Qty");
                   TextBox RM_Qty = (TextBox)e.Row.FindControl("RM_Qty");
                   RM_Qty.Attributes.Add("onchange", "FnValidate('"+hdnRM_Qty.ClientID+"','"+RM_Qty.ClientID+"')");
               }
               catch (Exception)
               { }
           }
       }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900