Copy data from one Control to Another in RadGrid

4 posts, 0 answers
  1. Ebenezer
    Ebenezer avatar
    39 posts
    Member since:
    Dec 2012

    Posted 22 Nov 2013 Link to this post

    I need to copy data from a  RadDatePicker  Control which is  inside a RadGrid using GridTemplateColumn to a Label Control also in the same RadGrid also using GridTemplateColumn   when a Session Variable is True. My Situation is if Session Variable is true, Copy data form :
    When Session Variable is True, Copy data from this control below
    <
    telerik:GridTemplateColumn HeaderText="Start Date" UniqueName="StartDate"
     Visible="false">
            <ItemTemplate>
             <asp:Label runat="server" ID="startdate" Text='<%# String.Format("{0:d}" , Eval("StartDate")) %>'>
              </asp:Label
             </ItemTemplate>
            <EditItemTemplate>
           <br />
      <telerik:RadDatePicker ID="picker3" runat="server" DbSelectedDate='<%# Bind("StartDate") %>'>
    </telerik:RadDatePicker>            
    <
    asp:CustomValidator ID="CustomValidator3" ControlToValidate="picker3" ErrorMessage="This field was incorrect"
               runat="server" OnServerValidate="CustomValidator1_ServerValidate">
         </asp:CustomValidator>
         </EditItemTemplate>
                </telerik:GridTemplateColumn>


    To Destination Control
    <telerik:GridTemplateColumn HeaderText="Finish Date" UniqueName="FinishDate">
                        <ItemTemplate>
                <asp:Label runat="server" ID="FinishDate" Text=" ">
                      </asp:Label
                </ItemTemplate>
        </telerik:GridTemplateColumn>
    An idea is welcome please
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 25 Nov 2013 Link to this post

    Hi Ebenezer,

    I guess you want to show the selected date value in the label, when the Grid is in EditMode. Please try the following code snippet.

    ASPX:
    <EditItemTemplate>
        <telerik:RadDatePicker ID="picker3" runat="server" AutoPostBack="true" DbSelectedDate='<%# Bind("Startdate") %>' OnSelectedDateChanged="picker3_SelectedDateChanged">
        </telerik:RadDatePicker>
    </EditItemTemplate>

    C#:
    protected void picker3_SelectedDateChanged(object sender, Telerik.Web.UI.Calendar.SelectedDateChangedEventArgs e)
    {
        RadDatePicker datepicker = (RadDatePicker)sender;
        GridEditFormItem eitem = (GridEditFormItem)datepicker.NamingContainer;
     
        if//(Your condition to check Session Variable is true)
       {
        GridDataItem ditem = (GridDataItem)eitem.ParentItem;    
        Label lbl= ditem.FindControl("FinishDate")as Label;      
        lbl.Text = datepicker.SelectedDate.ToString();
       }       
    }

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

    Posted 25 Nov 2013 Link to this post

    Hi Princy,
    Thanks for your response. I need to show the selected date value in the label, when the Grid is in Normal Mode since users are not allowed to edit the label. That is my issue.
  4. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 25 Nov 2013 Link to this post

    Hi Ebenezer,

    Please try the following code snippet to bind the values to a Label in GridTemplateColumn. If this doesn't help, please elaborate on your required scenario.

    C#:
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
     {
        if (e.Item is GridDataItem) // Check here for session condition as well
         {
             GridDataItem item = (GridDataItem)e.Item;
             Label lbl = (Label)item.FindControl("FinishDate");
             lbl.Text = DataBinder.Eval(item.DataItem, "StartDate").ToString();
         }
     }

    Thanks,
    Princy
Back to Top