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

Cannot implicitly convert type 'string' to 'Telerik.Web.UI.RadTextBox'

3 Answers 918 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nikola
Top achievements
Rank 2
Nikola asked on 09 Oct 2012, 08:30 AM
Heey Guys i got a problem ("Cannot implicitly convert type 'string' to 'Telerik.Web.UI.RadTextBox'") im tring to add some client insert edit update fucations to my grid,when i start to build it i got thist strange error here is my code if some one can help what would be awsome !!
 
<%@ Page Title="" Language="C#" MasterPageFile="~/ABBMaster.Master" AutoEventWireup="true" CodeBehind="Client.aspx.cs" Inherits="HolidayTracker.Testing.Client" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainRegionContentPlaceHolder" runat="server">
     <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
       <script type="text/javascript">
           var employeeID, currentEmployee, currentRowIndex = null;
           var employee =
           {
               EmployeeID: null,
               FirstName: null,
               LastName: null,
               Title: null,
               TitleOfCourtesy: null,
               BirthDate: null,
               Notes: null,
  
               create: function () {
                   var obj = new Object();
                   obj.EmployeeID = "";
                   obj.FirstName = "";
                   obj.LastName = "";
                   obj.Title = "";
                   obj.TitleOfCourtesy = "";
                   obj.BirthDate = "";
                   obj.Notes = "";
                   return obj;
               }
           };
  
           function getDataItemKeyValue(radGrid, item) {
               return parseInt(radGrid.get_masterTableView().getCellByColumnUniqueName(item, "EmployeeID").innerHTML);
           }
  
           function pageLoad(sender, args) {
               //employeeID = $find("<%= RadGrid1.ClientID %>").get_masterTableView().get_dataItems()[0].getDataKeyValue("EmployeeID");
               employeeID = getDataItemKeyValue($find("<%= RadGrid1.ClientID %>"), $find("<%= RadGrid1.ClientID %>").get_masterTableView().get_dataItems()[0]);
               $find("<%= LastName.ClientID %>").focus();
           }
  
           function rowSelected(sender, args) {
               //employeeID = args.getDataKeyValue("EmployeeID");
               employeeID = getDataItemKeyValue(sender, args.get_gridDataItem());
  
               currentRowIndex = args.get_gridDataItem().get_element().rowIndex;
               $find("<%= RadTabStrip1.ClientID %>").set_selectedIndex(0);
  
               MyWebService.GetEmployeeByEmployeeID(employeeID, setValues)
           }
  
           function setValues(employee) {
               $get("<%= EmployeeID.ClientID %>").innerHTML = employee.EmployeeID;
               $find("<%= LastName.ClientID %>").set_value(employee.LastName);
               $find("<%= FirstName.ClientID %>").set_value(employee.FirstName);
               $find("<%= Title.ClientID %>").set_value(employee.Title);
               $find("<%= TitleOfCourtesy.ClientID %>").findItemByText(employee.TitleOfCourtesy).select();
               $find("<%= BirthDate.ClientID %>").set_selectedDate(employee.BirthDate);
               $find("<%= Notes.ClientID %>").set_html(employee.Notes);
               $find("<%= LastName.ClientID %>").focus();
           }
           function getValues() {
               employee.EmployeeID = $get("<%= EmployeeID.ClientID %>").innerHTML;
               employee.LastName = $find("<%= LastName.ClientID %>").get_value();
               employee.FirstName = $find("<%= FirstName.ClientID %>").get_value();
               employee.Title = $find("<%= Title.ClientID %>").get_value();
               employee.TitleOfCourtesy = $find("<%= TitleOfCourtesy.ClientID %>").get_value();
               employee.BirthDate = $find("<%= BirthDate.ClientID %>").get_selectedDate();
               employee.Notes = $find("<%= Notes.ClientID %>").get_html();
               return employee;
           }
           function updateChanges() {
               MyWebService.UpdateEmployeeByEmployee(getValues(), updateGrid);
           }
  
           function updateGrid(result) {
               var tableView = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
               tableView.set_dataSource(result);
               tableView.dataBind();
  
               var grid = $find("<%= RadGrid1.ClientID %>");
               grid.repaint();
           }
  
           function tabSelected(sender, args) {
               if (currentEmployee == null) {
                   currentEmployee = getValues();
               }
  
               switch (args.get_tab().get_index()) {
                   case 1:
                       {
                           var gridItems = $find("<%= RadGrid1.ClientID %>").get_masterTableView().get_dataItems();
                           //var newID = parseInt(gridItems[gridItems.length - 1].getDataKeyValue("EmployeeID")) + 1;
                           var newID = getDataItemKeyValue($find("<%= RadGrid1.ClientID %>"), gridItems[gridItems.length - 1]) + 1;
                           var newEmployee = employee.create();
                           newEmployee.EmployeeID = newID;
                           setValues(newEmployee);
  
                           $get(" <%= SaveChanges.ClientID %>").value = "Add";
                           $get(" <%= Delete.ClientID %>").style.display = "none";
  
                           break;
                       }
                   default:
                       {
                           setValues(currentEmployee);
                           currentEmployee = null;
                           $get(" <%= SaveChanges.ClientID %>").value = "Save";
                           $get(" <%= Delete.ClientID %>").style.display = "";
                           break;
                       }
               }
           }
  
           function deleteCurrent() {
               var table = $find("<%= RadGrid1.ClientID %>").get_masterTableView().get_element();
               var row = table.rows[currentRowIndex];
               table.deleteRow(currentRowIndex);
  
               var dataItem = $find(row.id);
               if (dataItem) {
                   dataItem.dispose();
                   Array.remove($find(" <%= RadGrid1.ClientID %>").get_masterTableView()._dataItems, dataItem);
               }
  
               var gridItems = $find("<%= RadGrid1.ClientID %>").get_masterTableView().get_dataItems();
               MyWebService.DeleteEmployeeByEmployeeID(employeeID, updateGrid);
               gridItems[gridItems.length - 1].set_selected(true);
           }
  
       </script>
       </telerik:RadCodeBlock>
  
       <div style="height: 100%; padding: 10px">
  
       <telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1" runat="server" GridLines="None" OnDataBound="RadGrid1_DataBound" OnColumnCreated="RadGrid1_ColumnCreated" Height="300px" CellSpacing="0">
           <MasterTableView TableLayout="Fixed" ClientDataKeyNames="EmployeeID" AutoGenerateColumns="False" DataKeyNames="_EmployeeID" >
<CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
  
<RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column"></RowIndicatorColumn>
  
<ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column"></ExpandCollapseColumn>
  
               <Columns>
                   <telerik:GridBoundColumn DataField="_EmployeeID" DataType="System.Int32" FilterControlAltText="Filter _EmployeeID column" HeaderText="_EmployeeID" ReadOnly="True" SortExpression="_EmployeeID" UniqueName="_EmployeeID">
                   </telerik:GridBoundColumn>
                   <telerik:GridBoundColumn DataField="_LastName" FilterControlAltText="Filter _LastName column" HeaderText="_LastName" SortExpression="_LastName" UniqueName="_LastName">
                   </telerik:GridBoundColumn>
                   <telerik:GridBoundColumn DataField="_FirstName" FilterControlAltText="Filter _FirstName column" HeaderText="_FirstName" SortExpression="_FirstName" UniqueName="_FirstName">
                   </telerik:GridBoundColumn>
                   <telerik:GridBoundColumn DataField="_Title" FilterControlAltText="Filter _Title column" HeaderText="_Title" SortExpression="_Title" UniqueName="_Title">
                   </telerik:GridBoundColumn>
                   <telerik:GridBoundColumn DataField="_TitleOfCourtesy" FilterControlAltText="Filter _TitleOfCourtesy column" HeaderText="_TitleOfCourtesy" SortExpression="_TitleOfCourtesy" UniqueName="_TitleOfCourtesy">
                   </telerik:GridBoundColumn>
                   <telerik:GridBoundColumn DataField="_BirthDate" DataType="System.DateTime" FilterControlAltText="Filter _BirthDate column" HeaderText="_BirthDate" SortExpression="_BirthDate" UniqueName="_BirthDate">
                   </telerik:GridBoundColumn>
                   <telerik:GridBoundColumn DataField="_Notes" FilterControlAltText="Filter _Notes column" HeaderText="_Notes" SortExpression="_Notes" UniqueName="_Notes">
                   </telerik:GridBoundColumn>
               </Columns>
  
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
</EditFormSettings>
           </MasterTableView>
           <ClientSettings>
               <Selecting AllowRowSelect="true" />
               <ClientEvents OnRowSelected="rowSelected"/>
               <Scrolling AllowScroll="true" UseStaticHeaders="true" />
           </ClientSettings>
  
<FilterMenu EnableImageSprites="False"></FilterMenu>
       </telerik:RadGrid>
  
       <asp:SqlDataSource runat="server" ID="SqlDataSource1"
           ConnectionString="<%$ ConnectionStrings:HolidayTrackerConnectionString %>"
           SelectCommand="SELECT * FROM [Employee]">
       </asp:SqlDataSource>
  
       <telerik:RadTabStrip ID="RadTabStrip1" OnClientTabSelected="tabSelected" Style="margin-top: 10px;"
           SelectedIndex="1" runat="server" Skin="Hay">
           <Tabs>
               <telerik:RadTab Text="Edit employee" />
               <telerik:RadTab Text="Add new employee" Selected="True" />
           </Tabs>
            
       </telerik:RadTabStrip>
            </div>
       <div style="border: 1px solid threedshadow;">
           <table border="0" style="margin-top: 20px; width: 100%;">
               <tr>
                   <td>
                        Employee ID:
                   </td>
                   <td>
                        <asp:Label ID="EmployeeID" Style="float: left; font-weight: bold;" runat="server" />
                        <asp:Button ID="SaveChanges" CssClass="button" Style="float: right;
                            font-weight: bold;" OnClientClick="updateChanges(); return false;" Text="Save"
                            runat="server" BorderColor="White" />
                        <asp:Button ID="Delete" CssClass="button" Style="float: right; margin-right: 10px;
                             font-weight: bold;" OnClientClick="if(!confirm('Are you sure you want to delete this employee?'))return false; deleteCurrent(); return false;"
                            Text="Delete" runat="server" />
                   </td>
               </tr>
               <tr>
                   <td>
                        Last name:
                   </td>
                   <td>
                        <telerik:RadTextBox ID="LastName" runat="server" Skin="Hay" />
                   </td>
               </tr>
               <tr>
                   <td>
                        First name:
                   </td>
                   <td>
                        <telerik:RadTextBox ID="FirstName" runat="server" Skin="Hay" />
                   </td>
               </tr>
               <tr>
                   <td>
                        Title:
                   </td>
                   <td>
                        <telerik:RadTextBox ID="Title" runat="server" Skin="Hay" />
                   </td>
               </tr>
               <tr>
                   <td>
                        Title of courtesy:
                   </td>
                   <td>
                        <telerik:RadComboBox ID="TitleOfCourtesy" runat="server" Skin="Hay">
                            <Items>
                                <telerik:RadComboBoxItem Text="" Value="" />
                                <telerik:RadComboBoxItem Text="Dr." Value="Dr." />
                                <telerik:RadComboBoxItem Text="Mr." Value="Mr." />
                                <telerik:RadComboBoxItem Text="Mrs." Value="Mrs." />
                                <telerik:RadComboBoxItem Text="Ms." Value="Ms." />
                            </Items>
                        </telerik:RadComboBox>
                   </td>
               </tr>
               <tr>
                   <td>
                        Birth date:
                   </td>
                   <td>
                        <telerik:RadDatePicker ID="BirthDate" MinDate="01/01/1900" runat="server" Skin="Hay" />
                   </td>
               </tr>
               <tr>
                   <td style="vertical-align: top;">
                        Notes:
                   </td>
                   <td style="height: 400px;float:left;">
                        <telerik:RadEditor ID="Notes"  Width="100%" runat="server" Skin="Hay" />
                   </td>
               </tr>
           </table>
       </div>
</asp:Content>

3 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 09 Oct 2012, 11:31 AM
Hello,

In which line/Code you get this error?

Thanks,
Jayesh Goyani
0
Nikola
Top achievements
Rank 2
answered on 09 Oct 2012, 12:08 PM

the error is gone the problem was something with the id's if i change the id name of the

<telerik:RadTextBox ID="LastName1" runat="server" Skin="Hay" />

then it works and the error "was on line 1 " ?!... 

 

0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 09 Oct 2012, 12:34 PM
Hello,

May be already declared string variable "LastName" some where else that's why it gives error.

Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Nikola
Top achievements
Rank 2
Answers by
Jayesh Goyani
Top achievements
Rank 2
Nikola
Top achievements
Rank 2
Share this question
or