This is a migrated thread and some comments may be shown as answers.

Call ItemCommand event on page load.

3 Answers 398 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Prajakta
Top achievements
Rank 1
Prajakta asked on 09 Aug 2011, 06:56 AM
Hi,

I need to call the item_command event of rad grid on page load event of the same page where its' used.
Can anyone help me with the code to do the above. Is there any event handler with which I can pass the command name and call the item command event on page load.

Thanks.

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 09 Aug 2011, 07:01 AM
Hello Prajakta,

Try the folowing code snippet.
C#:
protected void Page_Load(object sender, EventArgs e)
{
   RadGrid1.ItemCommand += new Telerik.Web.UI.GridCommandEventHandler(RadGrid1_ItemCommand);
}
void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
  {
      //Handle your code
  }

Thanks,
Princy.
0
Prajakta
Top achievements
Rank 1
answered on 09 Aug 2011, 09:59 AM
Thanks for your solution.

I have implemented it. But the code in event is not getting executed. Actually, I need to perform data base operation of insert and its not getting reflected in data base and also I am not able to debug the event. But in page load it does go to the call statement. Can you please help me on this..?


if (!Page.IsPostBack)
            {
                this.radGridReferences.Rebind();
            }
            else
            {
                if (Request.Params["hdnValue"] != null && Request.Params["hdnValue"].ToString() == "yes")
                {
                    radGridReferences.ItemCommand += new Telerik.Web.UI.GridCommandEventHandler(radGridReferences_ItemCommand);
                }
            }
 
 
private void radGridReferences_ItemCommand(Object sender, Telerik.Web.UI.GridCommandEventArgs e)
        {
            int ReferencesId = 0;
            GridEditableItem item = e.Item as GridEditableItem;
 
            if (item.ItemIndex > -1)
            {
                ReferencesId = Convert.ToInt32(item.OwnerTableView.DataKeyValues[item.ItemIndex]["ReferencesID"].ToString());
            }
 
            if (ReferencesId <= 0)
            {
                ReferencesInfo objReferenceInfo = ((ReferencesInfo)item.FindControl("uctrlReferencesInfo"));
 
                if (CheckRefFileValidations(objReferenceInfo))
                {
                    try
                    {
                        objReferenceInfo.ReferenceFileUpload.SaveAs(Server.MapPath(ConfigurationManager.AppSettings["References"].ToString()) + "\\" + objReferenceInfo.ReferenceFileUpload.FileName);
                        ReferencesDAP.InsertReferences(this.PopulateReferencesBO(objReferenceInfo, 0));
 
                        objReferenceInfo.FileUploadErrorMsg = string.Empty;
                    }
                    catch (Exception ex)
                    {
                        Response.Write(ex.Message);
                        objReferenceInfo.FileUploadErrorMsg = Utilities.GetMessage("MSG04");
                    }
                }
 
            }
 
        }
0
Pavlina
Telerik team
answered on 11 Aug 2011, 04:57 PM
Hello Prajakta,

For more information about how to perform data editing operations at database level with Update/Insert/Delete commands you can refer to the help article below:
http://www.telerik.com/help/aspnet-ajax/grid-insert-update-delete-at-database-level.html

Regards,
Pavlina
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Prajakta
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Prajakta
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or