简体   繁体   中英

Refreshing gridview after update

I am having trouble trying to get my gridview to refresh after I update it. The DB takes the updates and I can see them there when I manually refresh the page, but not when I click the update link to commit the changes.

I tried to call the function that fills the grid, I receive a js error "Microsoft JScript runtime error: Unable to get value of the property 'firstChild': object is null or undefined". It runs through the method and doesn't throw that error until after it has exited.

Is there another approach that I can take to refresh my grid after Update?

Here is the code:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindCustodiansByProjectID();
            BindCustodianMedia(EditMediaClass.outRequestMediaID);
        }
    }

        private void BindCustodianMedia(string MediaID)
    {
        DataTable dt = new DataTable();
        SqlConnection conn = new SqlConnection(GetConnString());
        DataSet ds = new DataSet();
        try
        {
            conn.Open();
            SqlCommand cmd = new SqlCommand("usps_displayEditMedia_CustodianMedia", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@aspMediaID", SqlDbType.Int)).Value = int.Parse(MediaID);
            cmd.ExecuteNonQuery();

            SqlDataAdapter da = new SqlDataAdapter(cmd);

            da.Fill(ds);

            grd_custodianMedia.DataSource = ds;
            grd_custodianMedia.DataBind();
        }

        protected void updateCustodianMedia_OnUpdateCommand(object sender, GridRecordEventArgs e)
    {
        SqlConnection conn = new SqlConnection(GetConnString());
        conn.Open();
        try
        {
            SqlCommand cmd = new SqlCommand("usps_updateCustodianMedia_EditMedia", conn);
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add(new SqlParameter("@aspCustodianMediaID", SqlDbType.Int)).Value = int.Parse(e.Record["CustodianMediaID"].ToString());
            cmd.Parameters.Add(new SqlParameter("@aspMediaID", SqlDbType.Int)).Value = int.Parse(EditMediaClass.outRequestMediaID.ToString());
            cmd.Parameters.Add(new SqlParameter("@aspCustodianID", SqlDbType.Int)).Value = int.Parse(e.Record["CustodianID"].ToString());
            cmd.Parameters.Add(new SqlParameter("@aspUploadPath", SqlDbType.VarChar)).Value = e.Record["UploadPath"];
            cmd.Parameters.Add(new SqlParameter("@aspDataSize", SqlDbType.VarChar)).Value = e.Record["DataSize"];
            cmd.Parameters.Add(new SqlParameter("@aspDataDesc", SqlDbType.VarChar)).Value = e.Record["DataDescription"];

            cmd.ExecuteNonQuery();
            //BindCustodianMedia(EditMediaClass.outRequestMediaID);    

        }

For Javascript error, try to debug with Firebug or IE developer tools and find out exactly which line is causing you the issue. You are trying access a property "firstchild" from an object which is null. With this information it is very hard to tell which could be the exact problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM