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

Problem in getting RadComboBox id in Grid Edit command.

3 Answers 106 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Guruvu
Top achievements
Rank 1
Guruvu asked on 25 Nov 2010, 08:32 AM
Hi.

I am getting Object reference not set to an instance of an object error while retriving RadComboBox id in RadGrid edit command.Please help me...

Here is my Code:

 

protected void gvPOW_ItemCommand(object sender, GridCommandEventArgs e)

 

{

 

if (e.CommandName == "Edit")

 

{

 

GridDataItem item = (GridDataItem)e.Item;

 

gvPOW.Rebind();

 

RadComboBox ddlCity = item.FindControl("gvddlPOWCity") as RadComboBox;

 

 

RadComboBox ddlProject = item.FindControl("gvddlPOWProject") as RadComboBox;

 

 

string city = ddlCity.SelectedValue;

 

 

cmd = new SqlCommand("select ProjectName, ProjectId from Projects where CityId =" + ddlCity.SelectedValue, con);

 

 

SqlDataAdapter da = new SqlDataAdapter(cmd);

 

 

DataSet ds = new DataSet("DS");

 

da.Fill(ds,

"Branches");

 

ddlProject.DataSourceID =

null;

 

ddlProject.Items.Clear();

ddlProject.Items.Add(

new RadComboBoxItem("Select Project", "0"));

 

ddlProject.DataSource = ds;

ddlProject.DataBind();

}

}

I want to bind Project details based on City which was selected in Edit mode.Please help me...

Thanks in advance...

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 25 Nov 2010, 09:31 AM
Hello Guruvu,

You can try it in ItemDataBound event like below.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
   {
       if (e.Item is GridEditFormItem && e.Item.IsInEditMode)// if EditMode is EditForm or PopUp
       {
           GridEditFormItem editItem = (GridEditFormItem)e.Item;
           RadComboBox ddlCity = editItem.FindControl("gvddlPOWCity") as RadComboBox;
           string city = ddlCity.SelectedValue;
           . . . . . . . .
       }
   }

Thanks,
Princy.
0
Guruvu
Top achievements
Rank 1
answered on 25 Nov 2010, 10:13 AM
Hi Princy,

Thanks for your quick response.

I am already tried in ItemDataBound Event,

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
   {
       if (e.Item is GridEditFormItem && e.Item.IsInEditMode)// if EditMode is EditForm or PopUp
       {
           GridEditFormItem editItem = (GridEditFormItem)e.Item;
           RadComboBox ddlCity = editItem.FindControl("gvddlPOWCity") as RadComboBox;
           string city = ddlCity.SelectedValue;
           . . . . . . . .
       }
   }


Here,I am getting e.Item.IsInEditMode is always false.I am set the property in MasterTable view as below:

<

 

MasterTableView DataKeyNames="POWId" EditMode="EditForms">

Is there any more modifications need to perform.Please tell me...

Thanks...

 

0
Pavlina
Telerik team
answered on 29 Nov 2010, 01:05 PM
Hello guruvu,

Try with the following if statement instead:
if(e.Item is GridEditableItem && e.Item.IsInEditMode)
{
    // your code goes here
}

This should evaluate to true for the edit form.

All the best,
Pavlina
the Telerik team
Browse the vast support resources we have to jumpstart 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
Guruvu
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Guruvu
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or