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

Copy data from one Control to Another in RadGrid

3 Answers 139 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ebenezer
Top achievements
Rank 1
Ebenezer asked on 22 Nov 2013, 06:38 PM
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

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 25 Nov 2013, 10:34 AM
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
0
Ebenezer
Top achievements
Rank 1
answered on 26 Nov 2013, 03:05 AM
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.
0
Princy
Top achievements
Rank 2
answered on 26 Nov 2013, 04:29 AM
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
Tags
General Discussions
Asked by
Ebenezer
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Ebenezer
Top achievements
Rank 1
Share this question
or