Selected itemChanged

5 posts, 2 answers
  1. Ebenezer
    Ebenezer avatar
    39 posts
    Member since:
    Dec 2012

    Posted 15 May 2013 Link to this post

    I have a  RadGrid using GridDropDownColumn with two columns. Column1: Status and Column2: CompleteDate
     Column1: Status  has three items in the dropdown--->Not Started, In-Progress and Completed
    Column2 is using RadDatePicker as DbSelectedDate

    I need a way when Completed is selected from the Column1:status, Column2: CompleteDate should default to today's date and allow the user the opportunity to change it

     I am using the code below but missing alot. Any help out there.

       if (e.Item is GridEditableItem && e.Item.IsInEditMode)
           {
            GridDataItem item = (GridDataItem)e.Item;
              RadComboBox list = (e.Item as GridEditableItem)["MitigationStatusID"].Controls[7] as RadComboBox;
           //attach SelectedIndexChanged event for the combobox control
              list.AutoPostBack = true;
             list.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(list_SelectedIndexChanged);           
         }

     }
     void list_SelectedIndexChanged(object sender, EventArgs e)
     {
     
       GridEditableItem editedItem = (sender as RadComboBox).NamingContainer as GridEditableItem;
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 16 May 2013 Link to this post

    Hi Ebenezer,

    Please try the following code snippet to change the date of Date Picker to today's date depending on the selected value of ComboBox in edit mode.

    C#:
    protected void radGrdi_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)
        {
            GridEditableItem item = (GridEditableItem)e.Item;
            RadComboBox list = (RadComboBox)item["MitigationStatusID"].Controls[0];
            list.AutoPostBack = true;
            list.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(list_SelectedIndexChanged);           
        }        
    }
    void list_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        RadComboBox combo = (RadComboBox)sender;
             
        GridEditableItem edit = (GridEditableItem)com.NamingContainer;
        RadDatePicker Date = (RadDatePicker)edit["UniqueName"].Controls[0];
        if (combo.SelectedValue == "Completed ")
        {
            Date.SelectedDate = DateTime.Today;
        }
    }

    Thanks,
    Princy.
  3. Ebenezer
    Ebenezer avatar
    39 posts
    Member since:
    Dec 2012

    Posted 16 May 2013 Link to this post

    Hi Princy,
    Thanks for your help in advance. For some reasons when I use ItemCreated, the code doesn't fire at all on that event Handler. When I use ItemDataBound it does fire but the SelectedIndexChanged block doesn't   get hit. I am adding the html portion if it will help

    <telerik:GridTemplateColumn HeaderText="Completion Date" UniqueName="CompletionDate">
    <ItemTemplate>
     <asp:Label runat="server" ID="lblCompletionDate" Text='<%# String.Format("{0:d}" , Eval("CompletionDate")) %>'>
    </asp:Label>&nbsp;
     </ItemTemplate>
    <EditItemTemplate>
     <br />
    <telerik:RadDatePicker ID="picker2" runat="server" DbSelectedDate='<%# Bind("CompletionDate") %>'>
    </telerik:RadDatePicker>

    <telerik:GridDropDownColumn DataField="MitigationStatusID" DataSourceID="statusDataSource"
       HeaderStyle-Width="75px" DataType="System.Int32" DefaultInsertValue="" HeaderText="Status"
       ListTextField="Status" ListValueField="MitigationStatusID" SortExpression="MitigationStatusID"
       UniqueName="MitigationStatusID"  ItemStyle-Width="75px">
    </telerik:GridDropDownColumn>
  4. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 17 May 2013 Link to this post

    Hi Ebenezer,

    I tried your code and its working fine at my end. Please try attaching the ItemCreated event again and see whether its firing. The SelectedIndexChanged  event may not fire if it is attached inside the ItemDataBound event.

    Thanks,
    Princy.
  5. Ebenezer
    Ebenezer avatar
    39 posts
    Member since:
    Dec 2012

    Posted 17 May 2013 Link to this post

    Hi Princy,
    Thanks. It was my fault. I Misspelled the  ItemCreated EventHandler signature. Is working
Back to Top