加载asp.net网格后调用Jquery函数

时间:2015-02-03 09:40:43

标签: javascript c# jquery asp.net

一旦显示ASP.Net GridView,我想调用一个jQuery函数。我已经尝试过ready / load功能,但没有一个适用于我。

网格位于“更新面板”

<asp:GridView ID="grdNumberPlan" runat="server" 
    CssClass="table table-condensed table-hover table-striped rt"         
    Visible="false">
</asp:GridView>
$('#<%=grdNumberPlan.ClientID%>').ready(function () {
    alert('hello');
});

$('#<%=grdNumberPlan.ClientID%>').load(function () {
    alert('hello');
});

aspx.cs代码

protected void ddlCity_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {

            if (ddlHLR.SelectedValue == "0")
            {
                ((UIMaster)Page.Master).SetMessage(MessageType.Warnining, "Kindly select HLR");
                grdNumberPlan.DataSource = null;
                grdNumberPlan.DataBind();
                rowNewRanges.Visible = false;
                grdNumberPlan.Visible = false;
                return;
            }

            if (ddlCity.SelectedValue == "0")
            {
                ((UIMaster)Page.Master).SetMessage(MessageType.Warnining, "Select the city");
                grdNumberPlan.DataSource = null;
                grdNumberPlan.DataBind();
                rowNumPlanSum.Visible = false;
                grdNumberPlan.Visible = false;
                return;
            }

            //rangeList();

            NumberingPlan objNumberingPlan = new NumberingPlan();
            objNumberingPlan.CityID = Convert.ToInt32(ddlCity.SelectedValue);
            objNumberingPlan.HlrID = Convert.ToInt32(ddlHLR.SelectedValue);
            objNumberingPlan.ExclusiveType = Convert.ToInt32(ddlIssuanceType.IsExclusive.ToString());
            objNumberingPlan.Operation_Type = OperationType.Get;

            InventoryManagementServiceClient client = new InventoryManagementServiceClient();

            DataTable dt = new DataTable();
            dt = client.GetNumberingPlanRanges(objNumberingPlan).Tables[0];
            grdNumberPlan.Visible = true;
            rowNumPlanSum.Visible = true;
            grdNumberPlan.DataSource = dt;
            grdNumberPlan.DataBind();

            ///Fill NDC dropdown list
            ///
            NDC objNDC = new NDC();
            objNDC.HLRID = Convert.ToInt32(ddlHLR.SelectedValue);
            objNDC.CityID = Convert.ToInt32(ddlCity.SelectedValue);
            objNDC.Operation_Type = OperationType.Get;

            DataTable dtNDC = new DataTable();
            serviceClient = new CommonServiceClient();
            dtNDC = serviceClient.GetNDC(objNDC).Tables[0];
            //GlobalMethods.FillDropDownList(dtNDC, ddlNDC, "NDC", "NDC_ID");
            GlobalMethods.FillDropDownList(dtNDC, ddlNDC, "NDC", "NDC");

            ClientScript.RegisterStartupScript(GetType(), "Javascript", "javascript:fnPopUp();", true);

        }
        catch (Exception ex)
        {
            ((UIMaster)Page.Master).SetMessage(MessageType.Error, ex.Message);
        }
    }

2 个答案:

答案 0 :(得分:2)

$(document).ready(function(){
   callYourFunction();
});

或者在gridview bind

之后从代码后面调用javascript函数
grdNumberPlan.DataSource=yourDataTable;
grdNumberPlan.DataBind();
ClientScript.RegisterStartupScript(GetType(), "Javascript", "javascript:FUNCTIONNAME(); ", true);

答案 1 :(得分:1)

我没有足够的声誉来发表评论。所以我发布了一个新答案。在RegisterStartupScript代码中,删除&#34; javascript:&#34;并尝试发出警报声明。

ClientScript.RegisterStartupScript(GetType(), "Javascript", "functionName(); ", true);

ClientScript.RegisterStartupScript(GetType(), "Javascript", "alert('In function'); ", true);