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

Copy data from one Control to another RadGrid

4 Answers 111 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ebenezer
Top achievements
Rank 1
Ebenezer asked on 25 Nov 2013, 09:07 PM
I need to copy data from one control  --"PlannedStartDate"  in RadGrid using GridTemplateColumns to "bStartDate", but the code below that I am using is not working. Any suggestions?
<telerik:GridTemplateColumn HeaderText="New Start Date" UniqueName="bStartDate"  >                                                         
  <ItemTemplate>
  <asp:Label runat="server" ID="bStartDate" Text=" ">
  </asp:Label
   </ItemTemplate>
                                                              
 </telerik:GridTemplateColumn>
 
 
 
 
<telerik:GridTemplateColumn HeaderText="Planned Start Date" UniqueName="PlannedStartDate" >                                                          
  <ItemTemplate>
  <asp:Label runat="server" ID="plannedstartdate" Text='<%# String.Format("{0:d}" , Eval("PlannedStartDate")) %>'>
 </asp:Label
  </ItemTemplate>
 <EditItemTemplate>
  <br />
 <telerik:RadDatePicker ID="picker3" runat="server" DbSelectedDate='<%# Bind("PlannedStartDate") %>'>
  </telerik:RadDatePicker>
 <asp:CustomValidator ID="CustomValidator3" ControlToValidate="picker3" ErrorMessage="This field was incorrect"
    runat="server" OnServerValidate="CustomValidator1_ServerValidate">
  </asp:CustomValidator>
 </EditItemTemplate>
       </telerik:GridTemplateColumn>
 
 
 
 
 
 
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
 
 
         
 
              
            if (e.Item is GridCommandItem && blnApproved)
            {
                GridCommandItem dataitem = (GridCommandItem)e.Item;
                  
                Label PStart = dataitem.FindControl("plannedstartdate") as Label;
                                 
                 
                Label BStart = dataitem.FindControl("bStartDate") as Label;
                 
                BStart.Text = PStart.ToString();
                 
            }
 
 
        }
 
    }

4 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 26 Nov 2013, 05:32 AM
Hi Ebenezer,

Please try the following code snippet.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item = (GridDataItem)e.Item;
        Label lblPlanStartDate = (Label)item.FindControl("plannedstartdate");
        string valuestartdate = lblPlanStartDate.Text;
        if (blnApproved)
        {
            Label lblbStartDate = (Label)item.FindControl("bStartDate");
            lblbStartDate.Text = valuestartdate;
        }
    }
}

Thanks,
Princy
0
Ebenezer
Top achievements
Rank 1
answered on 26 Nov 2013, 02:13 PM
Hi Princy,
I have given your code a try. For some reasons this is returning null
Label lblPlanStartDate = (Label)item.FindControl("plannedstartdate");
and therefore blowing up at
string valuestartdate = lblPlanStartDate.Text;
Infact I have to change the code  to use GridCommandItem   because the your code was not reaching GridDataItem


if (e.Item is GridCommandItem)
           {
               GridCommandItem item = (GridCommandItem)e.Item;
               
               Label lblPlanStartDate = (Label)item.FindControl("plannedstartdate");
               string valuestartdate = lblPlanStartDate.ToString();
               if (blnApproved)
               {
                   Label lblbStartDate = (Label)item.FindControl("bStartDate");
                   lblbStartDate.Text = valuestartdate;
               }
           }

0
Accepted
Princy
Top achievements
Rank 2
answered on 27 Nov 2013, 06:00 AM
Hi Ebenezer,

The GridTableView object has an Items property that contains all the data rows in the table view. Each row is represented by a GridDataItem or GridEditFormItem object, depending on whether the row is an edit form. Since you are trying to access values of columns, you should access through GridDataItem. We use GridCommandItem, when we want to access controls inside the CommandItem, that is displayed on top or at the bottom of the each GridTableView base on the settings of CommandItemDisplay property. The above code works fine at my end, can you please provide your full code snippet to identify the issue.

Thanks,
Princy




0
Ebenezer
Top achievements
Rank 1
answered on 27 Nov 2013, 01:43 PM
Hi Princy
You are right. It was my mistake. I inserted the code in the wrong place. It works. Thanks
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