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

Edit Items in DropDownList in EditTemplate

1 Answer 40 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Danny
Top achievements
Rank 2
Danny asked on 10 May 2013, 05:24 PM

There is a dropdownlist being populated in the OnItemDataBound event.

protected void RadGrid1_OnItemDataBound(object source, GridItemEventArgs e)
        {
            if (e.Item is GridEditableItem && e.Item.IsInEditMode)
            {
            GridEditableItem gEditableItem = (GridEditableItem)e.Item;
       
             //hit the framework and get a datatable
  
             DropDownList ddlEffectiveDate = (DropDownList)gEditableItem["efct_period_date"].FindControl("DdlEffectiveDate");
  
                 ddlEffectiveDate.DataSource = dt;
                dlEffectiveDate.DataTextField = "start_date";
                ddlEffectiveDate.DataValueField = "period_id";
                ddlEffectiveDate.DataBind();
                  
                ddlEffectiveDate.Items.Remove(ddlEffectiveDate.Items[0]);
   
  
  
                 


That last line removes the firstitem of the datatable that I've bound the dropdown list to- but the value from the column itself somehow ends up appended into the dropdown list.   I'd like to know what event that happens in.

I want to remove the column value from the dropdownlist Edit Item.   How do I do that?

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 11 May 2013, 04:36 AM
Hello,

Please try with below code snippet.

DropDownList ddlEffectiveDate = (DropDownList)gEditableItem["efct_period_date"].FindControl("DdlEffectiveDate");
            if (ddlEffectiveDate != null)
            {
                if (ddlEffectiveDate.Items.FindByValue("YourValue") != null)
                {
                    ddlEffectiveDate.Items.Remove(ddlEffectiveDate.Items.FindByValue("YourValue"));
                }
            }


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Danny
Top achievements
Rank 2
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or