Edit Items in DropDownList in EditTemplate

2 posts, 0 answers
  1. Danny
    Danny avatar
    35 posts
    Member since:
    May 2012

    Posted 10 May 2013 Link to this post

    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?
  2. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 10 May 2013 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top