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

Client Grid Example not working

12 Answers 149 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sucheta Patil
Top achievements
Rank 1
Sucheta Patil asked on 06 Sep 2010, 04:12 PM
Visitors.aspx
<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/CWCStaffnet.Master" CodeBehind="VisitorsTry.aspx.cs" Inherits="CWC.Staffnet.Forms.FBMS.VisitorsTry" %>
<%@ MasterType VirtualPath="~/CWCStaffnet.Master" %>
  
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link href="../Styles/Styles.css" rel="stylesheet" type="text/css" />  
<style type="text/css">
        .body
        {
            margin: 0px;
            padding: 0px;
            height: 100%;
            width: 100%;
            background-color: #FFFFE0;
        }
        .grid td
        {
            cursor: pointer;
        }
        .grid
        {
            height: 300px;
        }
        .button
        {
            background: transparent url(http://www.telerik.com/DEMOS/ASPNET/Prometheus/TabStrip/Examples/ApplicationScenarios/Wizard/images/button.gif) no-repeat scroll left top;
            border: medium none;
            height: 28px;
            width: 90px;
        }
          
    </style>
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
  
        <script type="text/javascript">
            var Id, currentEmployee, currentRowIndex = null;          
  
            var visitor =
            {
                Id : null,
                VisitorsName : null,
                VisitorsOrg : null,
                Name : null,
                Division : null,                
                School : null,
                Centre : null,                
                Extension : null,
                RoomNo : null,
                ExpectedDate : null,
                Arriving_at_hr : null,
                Arriving_at_mm : null,
                WireLessAccess : null,
                ParkingSpace : null,
                VehicleReg : null,
                ParkingReason : null,
                Call_on_arrival : null,
                Send_to_room : null,
                Comments : null,         
                create : function()
                {
                    var obj = new Object();
                obj.Id ="";
                obj.VisitorsName ="";
                obj.VisitorsOrg ="";
                obj.Name ="";
                obj.Division ="";
                obj.School ="";
                obj.Centre="";          
                obj.Extension="";
                obj.RoomNo ="";
                obj.ExpectedDate="";
                obj.Arriving_at_hr ="";
                obj.Arriving_at_mm ="";
                obj.WireLessAccess ="";
                obj.ParkingSpace ="";
                obj.VehicleReg ="";
                obj.ParkingReason="";
                obj.Call_on_arrival ="";
                obj.Send_to_room ="";
                obj.Comments="";                
  
                    return obj;
                }
          };
              
            function getDataItemKeyValue(radGrid, item)
            {
                return parseInt(radGrid.get_masterTableView().getCellByColumnUniqueName(item,"Id").innerHTML);
            }
              
            function pageLoad(sender, args)
            
                //Id = $find("<%= RadGrid1.ClientID %>").get_masterTableView().get_dataItems()[0].getDataKeyValue("Id");
                Id = getDataItemKeyValue($find("<%= RadGrid1.ClientID %>"),$find("<%= RadGrid1.ClientID %>").get_masterTableView().get_dataItems()[0]); 
                $find("<%= VisitorsName.ClientID %>").focus();                
                currentRowIndex = 0;
            }
              
            function rowSelected(sender, args)
            {                
                Id = getDataItemKeyValue(sender,args.get_gridDataItem());
                  
                currentRowIndex = args.get_gridDataItem().get_element().rowIndex;
  
                $find("<%= RadTabStrip1.ClientID %>").set_selectedIndex(0);
                  
                ParkingVisit.GetVisitorByVisitorID(Id, setValues)              
                 
            }
              
            function setValues(visitor)
            
                $get("<%= Id.ClientID %>").innerHTML = visitor.Id;
                $find("<%= VisitorsName.ClientID %>").set_value(visitor.VisitorsName);
                $find("<%= VisitorsOrg.ClientID %>").set_value(visitor.VisitorsOrg);                
                $find("<%= Name.ClientID %>").set_value(visitor.Name);
                $find("<%= Division.ClientID %>").findItemByText(visitor.Division).select();
                $find("<%= School.ClientID %>").findItemByText(visitor.School).select();                 
                $find("<%= Centre.ClientID %>").findItemByText(visitor.Centre).select();
                $find("<%= Extension.ClientID %>").set_value(visitor.Extension);
                $find("<%= RoomNo.ClientID %>").set_value(visitor.RoomNo);
                $find("<%= ExpectedDate.ClientID %>").set_selectedDate(visitor.ExpectedDate);
                $find("<%= Arriving_at_hr.ClientID %>").findItemByText(visitor.Arriving_at_hr).select();
                $find("<%= Arriving_at_mm.ClientID %>").findItemByText(visitor.Arriving_at_mm).select();
                  
                $find("<%= WireLessAccess.ClientID %>").set_value(visitor.WireLessAccess);
                  
                $find("<%= ParkingSpace.ClientID %>").set_value(visitor.ParkingSpace);
                $find("<%= VehicleReg.ClientID %>").set_value(visitor.VehicleReg);
                $find("<%= ParkingReason.ClientID %>").set_value(visitor.ParkingReason);
                  
                $find("<%= Call_on_arrival.ClientID %>").set_value(visitor.Call_on_arrival);
                $find("<%= Send_to_room.ClientID %>").set_value(visitor.Send_to_room);
                $find("<%= Comments.ClientID %>").set_value(visitor.Comments);     
  
                $find("<%= VisitorsName.ClientID %>").focus();
            }
  
            function getValues()
            {
                visitor.Id = $get("<%= Id.ClientID %>").innerHTML;             
  
                visitor.VisitorsName = $find("<%= VisitorsName.ClientID %>").get_value();
                visitor.VisitorsOrg = $find("<%= VisitorsOrg.ClientID %>").get_value();
                visitor.Name = $find("<%= Name.ClientID %>").get_value();
                visitor.Division = $find("<%= Division.ClientID %>").get_value();
                  
                visitor.School = $find("<%= School.ClientID %>").get_value();
                visitor.Centre = $find("<%= Centre.ClientID %>").get_value();
                visitor.Extension = $find("<%= Extension.ClientID %>").get_value();
                visitor.RoomNo = $find("<%= RoomNo.ClientID %>").get_value();              
                visitor.ExpectedDate = $find("<%= ExpectedDate.ClientID %>").get_selectedDate();
                  
                visitor.Arriving_at_hr = $find("<%= Arriving_at_hr.ClientID %>").get_value();
                visitor.Arriving_at_mm = $find("<%= Arriving_at_mm.ClientID %>").get_value();
                visitor.WireLessAccess = $find("<%= WireLessAccess.ClientID %>").get_value();
                visitor.ParkingSpace = $find("<%= ParkingSpace.ClientID %>").get_value(); 
                  
                visitor.VehicleReg = $find("<%= VehicleReg.ClientID %>").get_value();
                visitor.ParkingReason = $find("<%= ParkingReason.ClientID %>").get_value();
                visitor.Call_on_arrival = $find("<%= Call_on_arrival.ClientID %>").get_value();
                visitor.Send_to_room = $find("<%= Send_to_room.ClientID %>").get_value(); 
                visitor.Comments = $find("<%= Comments.ClientID %>").get_html();
  
                return visitor;
            }
  
            function updateChanges()
            {
                ParkingVisit.UpdateVisitorByVisitor(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(currentVisitor == null)
                {
                    currentVisitor = 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("Id")) + 1; 
                        var newID = getDataItemKeyValue($find("<%= RadGrid1.ClientID %>"),gridItems[gridItems.length - 1]) + 1;
  
                        var newVisitor = visitor.create();
                        newVisitor.Id = newID;
                        setValues(newVisitor);
                          
                        $get("<%= SaveChanges.ClientID %>").value = "Add";
                        $get("<%= Delete.ClientID %>").style.display = "none";
                          
                        break;
                    }
                    default:
                    {
                        setValues(currentVisitor);
                        currentVisitor = 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();
  
                ParkingVisit.DeleteVisitorByVisitorID(Id, updateGrid);
  
                gridItems[gridItems.length - 1].set_selected(true);
            }
                          
        </script>
  
    </telerik:RadCodeBlock>
  
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <h1> Visitors Parking Form</h1>
      
    <asp:Panel ID="plForm" runat="server">
    <telerik:RadAjaxLoadingPanel ID="LoadingPanel1" runat="server" IsSticky="True" Style="position: absolute; top: 0; left: 0; height: 100%; width: 100%;">
        </telerik:RadAjaxLoadingPanel>
        <asp:LinqDataSource ID="LinqVisitors" runat="server" 
            ContextTypeName="CWC.Staffnet.Forms.StaffnetDataContext" 
            TableName="tblVisitors" EnableDelete="True" EnableInsert="True" 
            EnableUpdate="True">
        </asp:LinqDataSource>
           
  
         <telerik:RadGrid ID="RadGrid1" CssClass="grid" DataSourceID="LinqVisitors" runat="server"
                GridLines="None"  Height="300px" OnDataBound="RadGrid1_DataBound" OnColumnCreated="RadGrid1_ColumnCreated">
                <MasterTableView TableLayout="Fixed" ClientDataKeyNames="Id" />
                <ClientSettings>
                    <Selecting AllowRowSelect="true" />
                    <ClientEvents OnRowSelected="rowSelected" />
                    <Scrolling AllowScroll="true" UseStaticHeaders="true" />
                </ClientSettings>
            </telerik:RadGrid>
 <telerik:RadTabStrip ID="RadTabStrip1" OnClientTabSelected="tabSelected" Style="margin-top: 10px;"
                SelectedIndex="0" runat="server">
                <Tabs>
                    <telerik:RadTab Text="Edit Visitor" />
                    <telerik:RadTab Text="Add new Visitor" />
                </Tabs>
            </telerik:RadTabStrip>
            <div style="border: 1px solid threedshadow;">
                <table border="0" style="margin-top: 20px; width: 100%;">
                    <tr>
                        <td>
                           Visitors Id
                        </td>
                        <td>
                            <asp:Label ID="Id" Style="float: left; font-weight: bold;" runat="server" />
<asp:Button ID="SaveChanges" CssClass="button" Style="float: right; color: black;
font-weight: bold;" OnClientClick="updateChanges(); return false;" Text="Save"
runat="server" />
<asp:Button ID="Delete" CssClass="button" Style="float: right; margin-right: 10px;
color: black; 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>
               </table>
               </div>
                <ol><li>
            <asp:Label ID="lbName" runat="server" Text="Visitor's Name: " AssociatedControlID="VisitorsName"> </asp:Label><telerik:RadTextBox ID="VisitorsName" runat="server" MaxLength="150" Width="200px"></telerik:RadTextBox><asp:RequiredFieldValidator ID="RFV_txtName" runat="server" ControlToValidate="VisitorsName" 
           ErrorMessage="Please enter Visitor's Name"  ValidationGroup="Visitor">*</asp:RequiredFieldValidator></li>
           <li><asp:Label ID="lbOrg" runat="server" Text="Visitor's Organisation: " AssociatedControlID="VisitorsOrg"> </asp:Label><telerik:RadTextBox ID="VisitorsOrg" runat="server" MaxLength="150" Width="200px"></telerik:RadTextBox><asp:RequiredFieldValidator ID="RFV_txtOrg" runat="server" ControlToValidate="VisitorsOrg" 
           ErrorMessage="Please enter Visitor's Organisation Name"  ValidationGroup="Visitor">*</asp:RequiredFieldValidator></li>
           <li><asp:Label ID="lbVisitingName" runat="server" Text="Visting Name: " AssociatedControlID="Name"> </asp:Label><telerik:RadComboBox ID="Name" runat="server" ReadOnly="true" DataTextField="Name"
    DataValueField="Name" AppendDataBoundItems="True" AllowCustomText="True"  MarkFirstMatch="True"  OnSelectedIndexChanged="Name_SelectedIndexChanged" AutoPostBack="True" CausesValidation="False"></telerik:RadComboBox><asp:RequiredFieldValidator ID="RFV_lstVName" runat="server" ValidationGroup="Visitor"  ControlToValidate="Name" ErrorMessage="Please name the Person Visiting ">*</asp:RequiredFieldValidator></li>
        <li><asp:Label ID="lbFaculty" runat="server" Text="Faculty/Service:" AssociatedControlID="Division"></asp:Label><telerik:RadComboBox ID="Division" runat="server" ReadOnly="true" Enabled="false" DataTextField="Division" DataValueField="Division"></telerik:RadComboBox></li><li></li>
        <li><asp:Label ID="lbSchool" runat="server" Text="School/Section:" AssociatedControlID="School"></asp:Label><telerik:RadComboBox ID="School" runat="server" ReadOnly="true" Enabled="False"           AppendDataBoundItems="False" DataTextField="School" DataValueField="School"></telerik:RadComboBox></li>        <li></li>
        <li><asp:Label ID="lbCentre" runat="server" Text="Centre:" AssociatedControlID="Centre"></asp:Label><telerik:RadComboBox ID="Centre" runat="server" AppendDataBoundItems="True" DataSourceID="LinqCentre" DataTextField="Centre" DataValueField="ID" DataKeyField="ID" DataSortField="Centre" ReadOnly="true"  CausesValidation="False" onselectedindexchanged="Centre_SelectedIndexChanged" AutoPostBack="true">
       <Items><telerik:RadComboBoxItem Text="Choose One..." Value="10" /><telerik:RadComboBoxItem Text="Outreach Centre" Value="Outreach Centre" />
       </Items></telerik:RadComboBox><asp:RequiredFieldValidator ID="RFV_Centre" runat="server" ValidationGroup="Visitor"  InitialValue="Choose One..." ControlToValidate="Centre" ErrorMessage="Please enter Centre">*</asp:RequiredFieldValidator></li>
       <li><asp:LinqDataSource ID="LinqCentre" runat="server" ContextTypeName="CWC.Staffnet.Forms.StaffnetDataContext" TableName="tblCentres" OrderBy="Centre"></asp:LinqDataSource></li>
       <li><asp:Label ID="lbRoom" runat="server" Text="Meeting in Room Number:" AssociatedControlID="RoomNo"></asp:Label><telerik:RadTextBox ID="RoomNo" runat="server" MaxLength="150" Width="200px"></telerik:RadTextBox><asp:RequiredFieldValidator ID="RFV_txtRoom" runat="server" ValidationGroup="Visitor"
ControlToValidate="RoomNo" ErrorMessage="Please enter Room Number">*</asp:RequiredFieldValidator></li>          <li><asp:Label ID="lbOnDate" runat="server" Text="On (Date):" AssociatedControlID="ExpectedDate"></asp:Label><telerik:RadDatePicker ID="ExpectedDate" runat="server" DateFormat="dd/MM/yyyy" Enabled="true" Culture="English (United Kingdom)">
<DateInput DateFormat="dd-MM-yyyy" runat="server" DisplayDateFormat="dd-MM-yyyy"></DateInput>
  
</telerik:RadDatePicker><asp:RequiredFieldValidator ID="RFV_txtOnDate" ControlToValidate="ExpectedDate" ValidationGroup="Visitor" runat="server" ErrorMessage="Please enter On Date.">*</asp:RequiredFieldValidator></li>
        <li><asp:Label ID="lbhhmm" runat="server" Text="Due at(time) hours:minutes:" AssociatedControlID="Arriving_at_hr"></asp:Label><telerik:RadComboBox ID="Arriving_at_hr" runat="server" AppendDataBoundItems="True" AutoPostBack="True" CausesValidation="False"  Width="40px" MaxLength="40"><Items><telerik:RadComboBoxItem Text="Choose One..." Value="Choose One..." Selected="True" /><telerik:RadComboBoxItem runat="server" Text="06" Value="06" /><telerik:RadComboBoxItem runat="server" Text="07" Value="07" /><telerik:RadComboBoxItem runat="server" Text="08" Value="08" /><telerik:RadComboBoxItem runat="server" Text="09" Value="09" /><telerik:RadComboBoxItem runat="server" Text="10" Value="10" /><telerik:RadComboBoxItem runat="server" Text="11" Value="11" /><telerik:RadComboBoxItem runat="server" Text="12" Value="12" /><telerik:RadComboBoxItem runat="server" Text="13" Value="13" /><telerik:RadComboBoxItem runat="server" Text="14" Value="14" /><telerik:RadComboBoxItem runat="server" Text="15" Value="15" /><telerik:RadComboBoxItem runat="server" Text="16" Value="16" /><telerik:RadComboBoxItem runat="server" Text="17" Value="17" /><telerik:RadComboBoxItem runat="server" Text="18" Value="18" /><telerik:RadComboBoxItem runat="server" Text="19" Value="19" /><telerik:RadComboBoxItem runat="server" Text="20" Value="20" /><telerik:RadComboBoxItem runat="server" Text="21" Value="21" /></Items></telerik:RadComboBox>
           <b>:</b
        <telerik:RadComboBox ID="Arriving_at_mm" runat="server" AppendDataBoundItems="True" AutoPostBack="True" CausesValidation="False" Width="40px" MaxLength="40"><Items><telerik:RadComboBoxItem Text="Choose One..." Value="Choose One..." Selected="True" /><telerik:RadComboBoxItem runat="server" Text="00" Value="00" /><telerik:RadComboBoxItem runat="server" Text="05" Value="05" /><telerik:RadComboBoxItem runat="server" Text="10" Value="10" /><telerik:RadComboBoxItem runat="server" Text="15" Value="15" /><telerik:RadComboBoxItem runat="server" Text="20" Value="20" /><telerik:RadComboBoxItem runat="server" Text="25" Value="25" /><telerik:RadComboBoxItem runat="server" Text="30" Value="30" /><telerik:RadComboBoxItem runat="server" Text="35" Value="35" /><telerik:RadComboBoxItem runat="server" Text="40" Value="40" /><telerik:RadComboBoxItem runat="server" Text="45" Value="45" /><telerik:RadComboBoxItem runat="server" Text="50" Value="50" /><telerik:RadComboBoxItem runat="server" Text="55" Value="55" /></Items></telerik:RadComboBox>
        <asp:RequiredFieldValidator ID="RFV_lsthh" runat="server" ValidationGroup="Visitor" InitialValue="Choose One..." ControlToValidate="Arriving_at_hr" ErrorMessage="Please enter time in hours of visit">*</asp:RequiredFieldValidator>
        <asp:RequiredFieldValidator ID="RFV_lstmm" runat="server" ValidationGroup="Visitor" InitialValue="Choose One..." ControlToValidate="Arriving_at_mm" ErrorMessage="Please enter time in minutes of visit">*</asp:RequiredFieldValidator>
        </li><li></li>
        <li><asp:Label ID="Label4" runat="server" Text="Wireless Access" AssociatedControlID="WireLessAccess"></asp:Label><asp:CheckBox ID="WireLessAccess" runat="server" /></li>
        <li><asp:Label ID="lbcarprev" runat="server" Text="<br/>Parking Space" AssociatedControlID="ParkingSpace" Height="24px" Width="300px"></asp:Label>
          <asp:RadioButtonList ID="ParkingSpace" runat="server" RepeatDirection="Horizontal" RepeatColumns="2" Height="16px" Width="126px" AutoPostBack="true" onselectedindexchanged="ParkingSpace_SelectedIndexChanged"><asp:ListItem Value="Yes">Yes</asp:ListItem><asp:ListItem Value="No" Selected="True">No</asp:ListItem></asp:RadioButtonList></li>
          <li><asp:Label ID="Label5" runat="server" Text="Vehicle Registration: " AssociatedControlID="VehicleReg"> </asp:Label><telerik:RadTextBox ID="VehicleReg" runat="server"  Enabled="false" MaxLength="150" Width="200px"></telerik:RadTextBox><asp:RequiredFieldValidator ID="RFV_txtVehReg" runat="server" ControlToValidate="VehicleReg" ErrorMessage="Please enter Vehicle Registration" Visible="False" ValidationGroup="Visitor">*</asp:RequiredFieldValidator></li>
          <li><asp:Label ID="lbReason" runat="server" Text="Reason for parking:" AssociatedControlID="ParkingReason"></asp:Label>
          <telerik:RadComboBox ID="ParkingReason" CausesValidation="false" AutoPostBack="true" runat="server" Enabled="false">
          <Items><telerik:RadComboBoxItem Text="Choose One..." Value="0" /><telerik:RadComboBoxItem Text="Meeting" Value="1" /><telerik:RadComboBoxItem Text="Disabled Driver" Value="2" /><telerik:RadComboBoxItem Text="Equipment Collection" Value="3" /><telerik:RadComboBoxItem Text="Equipment Delivery" Value="4" /><telerik:RadComboBoxItem Text="PickUp" Value="5" /><telerik:RadComboBoxItem Text="Minibus" Value="6" /><telerik:RadComboBoxItem Text="Engineer" Value="7" /></Items>
          </telerik:RadComboBox><asp:RequiredFieldValidator ID="RFV_lstParkingReason" ControlToValidate="ParkingReason" ValidationGroup="Visitor" runat="server" InitialValue="Choose One..."  ErrorMessage="Please enter reason for parking." Visible="False">*</asp:RequiredFieldValidator></li>
          <li></li>
          <li><asp:Label ID="Label7" runat="server" Text="Please call on arrival "  AssociatedControlID="Call_on_arrival"></asp:Label><asp:CheckBox ID="Call_on_arrival" runat="server" Checked="true" /><asp:Label ID="Label9" runat="server" Text="Extension " AssociatedControlID="Extension"></asp:Label><telerik:RadComboBox ID="Extension" runat="server" ReadOnly="true" Enabled="False" DataTextField="Ext"
            DataValueField="Ext" AppendDataBoundItems="False"></telerik:RadComboBox></li>
          <li><asp:Label ID="Label8" runat="server" Text="Please send to room " AssociatedControlID="Send_to_room"></asp:Label><asp:CheckBox ID="Send_to_room" runat="server" /></li><li></li>
          <li><asp:Label ID="lbAddNotes" runat="server" Text="Additional Comments:" AssociatedControlID="Comments"></asp:Label><asp:TextBox ID="Comments" runat="server" TextMode="MultiLine" Height="64px" Width="221px"></asp:TextBox><asp:RequiredFieldValidator ID="RFV_AdditionalNotes" ControlToValidate="Comments" ValidationGroup="Visitor"  runat="server" ErrorMessage="Please enter Additional Comments">*</asp:RequiredFieldValidator></li>          
              
   </ol>
                 
  
    </asp:Panel>
    </asp:Content>
  
  
****************************************
Visitors.aspx.cs
  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using System.Net.Mail;
using config = CWC.Staffnet.Forms.Properties.Settings;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
  
namespace CWC.Staffnet.Forms.FBMS
{
    public partial class VisitorsTry : System.Web.UI.Page
    {
        private StaffnetDataContext dc;      
         
        protected void Page_Init(object sender, EventArgs e)
        {
            dc = new StaffnetDataContext();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            RadGrid1.SelectedIndexes.Add(0);
           
        }
        protected void RadGrid1_DataBound(object sender, EventArgs e)
        {
            GridDataItem selectedItem = RadGrid1.Items[0];
  
            Id.Text = selectedItem["Id"].Text;
            VisitorsName.Text = selectedItem["VisitorsName"].Text;
            VisitorsOrg.Text = selectedItem["VisitorsOrg"].Text;
            Name.Text = selectedItem["Name"].Text;
            Division.Text = selectedItem["Division"].Text;
            School.Text = selectedItem["School"].Text;           
            Centre.Text = selectedItem["Centre"].Text;
            Extension.Text = selectedItem["Extension"].Text;
            RoomNo.Text = selectedItem["RoomNo"].Text;
        //getting error for date---String was not recognized as a valid DateTime.
          //  ExpectedDate.SelectedDate = DateTime.Parse(selectedItem["ExpectedDate"].Text);
            Arriving_at_hr.FindItemByText(selectedItem["Arriving_at_hr"].Text).Selected = true;
            Arriving_at_mm.FindItemByText(selectedItem["Arriving_at_mm"].Text).Selected = true;
            WireLessAccess.Text = selectedItem["WireLessAccess"].Text;
            ParkingSpace.Text = selectedItem["ParkingSpace"].Text;
            VehicleReg.Text = selectedItem["VehicleReg"].Text;
            ParkingReason.FindItemByText(selectedItem["ParkingReason"].Text).Selected = true;
            Call_on_arrival.Text = selectedItem["Call_on_arrival"].Text;
            Send_to_room.Text = selectedItem["Send_to_room"].Text;
            Comments.Text = selectedItem["Comments"].Text;
        }
  
        protected void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
        {
            if (e.Column.IsBoundToFieldName("ExpectedDate"))
            {
                ((GridBoundColumn)e.Column).DataFormatString = "{0:MM/dd/yyyy}";
            }
            else if (e.Column.IsBoundToFieldName("Comments"))
            {
                e.Column.Visible = false;
            }
        }
  
        protected void Name_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {
              
        }       
  
        protected void Centre_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            if (Centre.SelectedValue == "Outreach Centre")
                RFV_AdditionalNotes.Enabled = true;
            else
                RFV_AdditionalNotes.Enabled = false;
        }
        protected void ParkingSpace_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ParkingSpace.SelectedValue == "Yes")
            {
                VehicleReg.Enabled = true;
                ParkingReason.Enabled = true;
                RFV_txtVehReg.Enabled = true;
                RFV_lstParkingReason.Enabled = true;
            }
            else
            {
                VehicleReg.Enabled = false;
                ParkingReason.Enabled = false;
                RFV_txtVehReg.Enabled = false;
                RFV_lstParkingReason.Enabled = false;
            }
        }
    }
}
********************************************************
ParkingVisit.asmx
  
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
  
namespace CWC.Staffnet.Forms.App_Code.Grid
{
    /// <summary>
    /// Summary description for WebService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class ParkingVisit : System.Web.Services.WebService
    {
  
        VisitorsList visitorList = null;
  
        public ParkingVisit()
        {
            visitorList = new VisitorsList();
  
            if (HttpContext.Current.Session["MyData"] == null)
            {
                HttpContext.Current.Session["MyData"] = visitorList;
            }
        }
        [WebMethod(EnableSession = true)]
        public VisitorsList UpdateVisitorByVisitor(Visitor visitor)
        {
            Visitor VisitorsToUpdate = GetVisitorByVisitorID(visitor.Id);
  
            VisitorsList list = (VisitorsList)HttpContext.Current.Session["MyData"];
  
            if (VisitorsToUpdate == null)
            {
                VisitorsToUpdate = new Visitor();
                VisitorsToUpdate.Id = visitor.Id;
                list.Add(VisitorsToUpdate);
            }
  
            VisitorsToUpdate.VisitorsName = visitor.VisitorsName;
            VisitorsToUpdate.VisitorsOrg = visitor.VisitorsOrg;
            VisitorsToUpdate.Name = visitor.Name;
            VisitorsToUpdate.Division = visitor.Division;
            VisitorsToUpdate.School = visitor.School;
            VisitorsToUpdate.Centre = visitor.Centre;
            VisitorsToUpdate.Extension = visitor.Extension;
            VisitorsToUpdate.RoomNo = visitor.RoomNo;
            VisitorsToUpdate.ExpectedDate = visitor.ExpectedDate;
            VisitorsToUpdate.Arriving_at_hr = visitor.Arriving_at_hr;
            VisitorsToUpdate.Arriving_at_mm = visitor.Arriving_at_mm;
            VisitorsToUpdate.WireLessAccess = visitor.WireLessAccess;
            VisitorsToUpdate.ParkingSpace = visitor.ParkingSpace;
            VisitorsToUpdate.VehicleReg = visitor.VehicleReg;
            VisitorsToUpdate.ParkingReason = visitor.ParkingReason;
            VisitorsToUpdate.Call_on_arrival = visitor.Call_on_arrival;
            VisitorsToUpdate.Send_to_room = visitor.Send_to_room;
            VisitorsToUpdate.Comments = visitor.Comments;
  
            HttpContext.Current.Session["MyData"] = list;
  
            return list;
        }
  
        [WebMethod(EnableSession = true)]
        public VisitorsList DeleteVisitorByVisitorID(int Id)
        {
            Visitor visitorToDelete = GetVisitorByVisitorID(Id);
  
            VisitorsList list = (VisitorsList)HttpContext.Current.Session["MyData"];
            list.Remove(visitorToDelete);
  
            HttpContext.Current.Session["MyData"] = list;
  
            return list;
        }
  
  
        [WebMethod(EnableSession = true)]
        public Visitor GetVisitorByVisitorID(int Id)
        {
            VisitorsList list = (VisitorsList)HttpContext.Current.Session["MyData"];
  
            return list.GetVisitorByVisitorID(Id);
        }
  
    }
}
*********************************************
Visitor.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
  
namespace CWC.Staffnet.Forms.App_Code.Grid
{
    public class Visitor
    {
        private int _Id;
        private string _VisitorsName;
        private string _VisitorsOrg;
        private string _Name;
        private string _Division;
        private string _School;
        private string _Centre;
        private string _Extension;
        private string _RoomNo;
        private System.Nullable<System.DateTime> _ExpectedDate;
        private string _Arriving_at_hr;
        private string _Arriving_at_mm;
        private string _WireLessAccess;
        private string _ParkingSpace;
        private string _VehicleReg;
        private string _ParkingReason;
        private string _Call_on_arrival;
        private string _Send_to_room;
        private string _Comments;
  
        public Visitor()
        {        
        }
        public Visitor(SqlDataReader reader)
        {
            _Id = Convert.ToInt32(reader["Id"]);
            _VisitorsName = reader["VisitorsName"].ToString();
            _VisitorsOrg = reader["VisitorsOrg"].ToString();
            _Name = reader["Name"].ToString();
            _Division = reader["Division"].ToString();
            _School = reader["School"].ToString();
            _Centre = reader["Centre"].ToString();
            _Extension = reader["Extension"].ToString();
            _RoomNo = reader["RoomNo"].ToString();
  
            _ExpectedDate = Convert.ToDateTime(reader["ExpectedDate"]);
            _Arriving_at_hr = reader["Arriving_at_hr"].ToString();
            _Arriving_at_mm = reader["Arriving_at_mm"].ToString();
            _WireLessAccess = reader["WireLessAccess"].ToString();
            _ParkingSpace = reader["ParkingSpace"].ToString();
            _VehicleReg = reader["VehicleReg"].ToString();
            _ParkingReason = reader["ParkingReason"].ToString();
            _Call_on_arrival = reader["Call_on_arrival"].ToString();
            _Send_to_room = reader["Send_to_room"].ToString();
            _Comments = reader["Comments"].ToString();
              
        }
        #region Public properties
  
        public int Id
        {
            get
            {
                return this._Id;
            }
            set
            {
                if ((this._Id != value))
                {
                    this._Id = value;
                }
            }
        }
  
        public string VisitorsName
        {
            get
            {
                return this._VisitorsName;
            }
            set
            {
                if ((this._VisitorsName != value))
                {
                    this._VisitorsName = value;
                }
            }
        }
  
        public string VisitorsOrg
        {
            get
            {
                return this._VisitorsOrg;
            }
            set
            {
                if ((this._VisitorsOrg != value))
                {
                    this._VisitorsOrg = value;
                }
            }
        }
  
        public string Name
        {
            get
            {
                return this._Name;
            }
            set
            {
                if ((this._Name != value))
                {
                    this._Name = value;
                }
            }
        }
  
        public string Division
        {
            get
            {
                return this._Division;
            }
            set
            {
                if ((this._Division != value))
                {
                    this._Division = value;
                }
            }
        }
  
        public string School
        {
            get
            {
                return this._School;
            }
            set
            {
                if ((this._School != value))
                {
                    this._School = value;
                }
            }
        }
  
        public string Centre
        {
            get
            {
                return this._Centre;
            }
            set
            {
                if ((this._Centre != value))
                {
                    this._Centre = value;
                }
            }
        }
  
        public string Extension
        {
            get
            {
                return this._Extension;
            }
            set
            {
                if ((this._Extension != value))
                {
                    this._Extension = value;
                }
            }
        }
        public string RoomNo
        {
            get
            {
                return this._RoomNo;
            }
            set
            {
                if ((this._RoomNo != value))
                {
                    this._RoomNo = value;
                }
            }
        }
        public System.Nullable<System.DateTime> ExpectedDate
        {
            get
            {
                return this._ExpectedDate;
            }
            set
            {
                if ((this._ExpectedDate != value))
                {
                    this._ExpectedDate = value;
                }
            }
        }
  
        public string Arriving_at_hr
        {
            get
            {
                return this._Arriving_at_hr;
            }
            set
            {
                if ((this._Arriving_at_hr != value))
                {
                    this._Arriving_at_hr = value;
                }
            }
        }
  
        public string Arriving_at_mm
        {
            get
            {
                return this._Arriving_at_mm;
            }
            set
            {
                if ((this._Arriving_at_mm != value))
                {
                    this._Arriving_at_mm = value;
                }
            }
        }
  
        public string WireLessAccess
        {
            get
            {
                return this._WireLessAccess;
            }
            set
            {
                if ((this._WireLessAccess != value))
                {
                    this._WireLessAccess = value;
                }
            }
        }
  
        public string ParkingSpace
        {
            get
            {
                return this._ParkingSpace;
            }
            set
            {
                if ((this._ParkingSpace != value))
                {
                    this._ParkingSpace = value;
                }
            }
        }
  
        public string VehicleReg
        {
            get
            {
                return this._VehicleReg;
            }
            set
            {
                if ((this._VehicleReg != value))
                {
                    this._VehicleReg = value;
                }
            }
        }
  
        public string ParkingReason
        {
            get
            {
                return this._ParkingReason;
            }
            set
            {
                if ((this._ParkingReason != value))
                {
                    this._ParkingReason = value;
                }
            }
        }
  
        public string Call_on_arrival
        {
            get
            {
                return this._Call_on_arrival;
            }
            set
            {
                if ((this._Call_on_arrival != value))
                {
                    this._Call_on_arrival = value;
                }
            }
        }
  
        public string Send_to_room
        {
            get
            {
                return this._Send_to_room;
            }
            set
            {
                if ((this._Send_to_room != value))
                {
                    this._Send_to_room = value;
                }
            }
        }       
          
        public string Comments
        {
            get
            {
                return this._Comments;
            }
            set
            {
                if ((this._Comments != value))
                {
  
                    this._Comments = value;
                }
            }
        }
  
        #endregion
    }
}
***************************************************
VisitorsList.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;
using System.Data.SqlClient;
  
  
namespace CWC.Staffnet.Forms.App_Code.Grid
{
    public class VisitorsList:List<Visitor>
    {
        public VisitorsList()
        {
            LoadAllVisitors();
        }
        private void LoadAllVisitors()
        
            if(this.Count > 0)
            this.Clear();           
  
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["cwc_staffnetConnectionString"].ConnectionString);
        SqlCommand cmd = new SqlCommand
            ("SELECT [Id], [VisitorsName], [VisitorsOrg], [Name], [Division], [School], [Centre], [Extension],[RoomNo], [ExpectedDate], [Arriving_at_hr], [Arriving_at_mm], [WireLessAccess], [ParkingSpace], [VehicleReg], [ParkingReason], [Call_on_arrival], [Send_to_room], [Comments] FROM [tblVisitors]", conn);
        cmd.CommandType = CommandType.Text;
  
        try
        {
  
            conn.Open();
  
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                this.Add(new Visitor(dr));
            }
  
        }
        finally
        {
            conn.Close();
        }
    }
  
    public Visitor GetVisitorByVisitorID(int id)
    {
        foreach (Visitor visitor in this)
        {
            if (visitor.Id == id)
            {
                return visitor;
            }
        }
        return null;
    }
  
    
    }
}

Hi
I have created similar VisitingTry.aspx file as to this example. 
http://demos.telerik.com/aspnet-ajax/grid/examples/client/insertupdatedelete/defaultcs.aspx

I have a 'FBMS' folder with
ParkingVisit.asmx
Visitor.cs
VisitorsList.cs
VisitorsTry.aspx

Error1
I run it with build success.
When I select any record from the RadGrid I get error as shown in Screen1.
Also the same error comes up for Add new record.Basically I can see it cannot find the ParkingVisit.asmx file.
How do I correct this?

Error2
I get

 

String was not recognized as a valid DateTime

 

for

 

ExpectedDate.SelectedDate = DateTime.Parse(selectedItem["ExpectedDate"].Text);


Thanks in advance.
Sucheta

12 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 09 Sep 2010, 08:18 AM
Hello Sucheta,

Have you referenced your web service from the ScriptManager? You probably need something like:

<asp:ScriptManager ID="ScriptManager1" runat="server">
  <Services>
    <asp:ServiceReference Path="ParkingVisit.asmx" />
  </Services>
</asp:ScriptManager>

As for the second error your are getting, it says the text in the ExpectedDate cell of the selected item cannot be parsed into a valid DateTime object, so you may want to check if your cell content holds a valid date string.

Greetings,
Veli
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Sucheta Patil
Top achievements
Rank 1
answered on 09 Sep 2010, 10:35 AM
Master file
  
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Staffnet.master.cs" Inherits="Staffnet" %>
  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  
<head runat="server">
    <title>Untitled Page</title>
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
    <link id="Link1" href="~/Styles/Styles.css"  rel="stylesheet"  runat="server" type="text/css" />
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
   <form id="form1" runat="server">
    <h1></h1>
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    <Services>
                <asp:ServiceReference Path="FBMS/ParkingVisit.asmx" />
    </Services>
    </telerik:RadScriptManager>
    <telerik:RadFormDecorator ID="RadFormDecorator1" runat="server" />
    <div id="maincontent">
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
        </asp:ContentPlaceHolder>
    </div>
     
    </form>
</body>
</html>

Hi
Above is my master file in which I have the parkingVisit.asmx included.
Porblem still not resolved!!!!
Thanks
0
Veli
Telerik team
answered on 10 Sep 2010, 01:55 PM
Hi Sucheta,

You also need to reference a web service proxy object together with its namespace:

CWC.Staffnet.Forms.App_Code.Grid.ParkingVisit

Veli
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Sucheta Patil
Top achievements
Rank 1
answered on 15 Sep 2010, 03:46 PM
Sorry guys,
I am a new bie to this ..Can u ellaborate as to how I can reference a web service proxy object together with its namespace.
Where do i do this?
In web.config file or in my project solution.
I am glad, if u give me some more links to read over this.
Thanks in advance.
Sucheta
0
Veli
Telerik team
answered on 16 Sep 2010, 12:15 PM
Hi Sucheta,

This is how you call the web service from its client-side object in your javascript:

CWC.Staffnet.Forms.App_Code.Grid.ParkingVisit.GetVisitorByVisitorID(Id, setValues);

When calling web service methods, the client-side object is wrapped in the same namespace the server-side WebService class is in. In your case, CWC.Staffnet.Forms.App_Code.Grid.ParkingVisit is the fully qualified class name of both the server WebService object and the client-side proxy object that is automatically created for you.

Here is a good ASP.NET tutorial on web services if you need more info.

Greetings,
Veli
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Sucheta Patil
Top achievements
Rank 1
answered on 17 Sep 2010, 01:45 PM
Hi
I have done as you have said.
Now it does give me the following error:

$find("<%=VisitorsName.ClientID %>").focus();

I dont know whats this error about.

Is it to do with $find() in javascript not working!!!!!

Please help me to resolve this.I have been trying to do this form since too many days.

Problem is not solved.!!!

Thanks
Sucheta

0
Sucheta Patil
Top achievements
Rank 1
answered on 20 Sep 2010, 12:27 PM
Hi
Still getting error:

CS0103: The name 'VisitorsName' does not exist in the current context
at line
  $find("<%=VisitorsName.ClientID %>").focus(); 

Can anyone come back to me soon.
Thanks
0
Veli
Telerik team
answered on 21 Sep 2010, 02:28 PM
Hello Sucheta,

The error you are getting indicates that control with ID VisitorsName is not visible as a first-level property in your page class. This means that, most probably, your control is in a naming container and is not directly accessible from the page. If this is the case, you should emit the ClientID of this control to the page. You can, for example, put it in a hidden field whose ID you now both on the client and the server. If we assume there is a hidden field with ID="VisitorsNameContainer" on the page, you can use the following script to get the client ID of the VisitorsName control:

var hiddenField = $get("VisitorsNameContainer");
$find(hiddenField.value).focus();


Veli
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Sucheta Patil
Top achievements
Rank 1
answered on 21 Sep 2010, 03:48 PM
Hi
Thanks for the reply.
But it didnt help again.
I have done exactly the replica of your
http://demos.telerik.com/aspnet-ajax/grid/examples/client/insertupdatedelete/defaultcs.aspx 
this demo.
If this one does not contain a hidden field then so is my code.
Can someone help me in some better way.
         I getting this error on $find() not for just VisitorName but on all other $find() variables.

Thanks,
Sucheta
0
Veli
Telerik team
answered on 22 Sep 2010, 09:59 AM
Can you post your code?

Veli
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Sucheta Patil
Top achievements
Rank 1
answered on 22 Sep 2010, 10:25 AM
Hi Veli,
Many thanks for your help.
Following is the code.
I get an error on $find() for all javascript variables.
Any help is appreciated..

Visitors.aspx
***************
  
<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/CWCStaffnet.Master" CodeBehind="Visitors.aspx.cs" Inherits="CWC.Staffnet.Forms.Visitor.Visitors" %>
<%@ MasterType VirtualPath="~/CWCStaffnet.Master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link href="../Styles/Styles.css" rel="stylesheet" type="text/css" />  
<style type="text/css">
        .body
        {
            margin: 0px;
            padding: 0px;
            height: 100%;
            width: 100%;
            background-color: #FFFFE0;
        }
        .grid td
        {
            cursor: pointer;
        }
        .grid
        {
            height: 300px;
        }
        .button
        {            
            border: medium none;
            height: 28px;
            width: 90px;
        }
          
    </style>
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script  type="text/javascript">
            var Id, currentEmployee, currentRowIndex = null;
            var visitor =
            {
                Id : null,
                VisitorsName : null,
                VisitorsOrg : null,
                Name : null,
                Division : null,                
                School : null,
                Centre : null,                
                Extension : null,
                RoomNo : null,
                ExpectedDate : null,
                Arriving_at_hr : null,
                Arriving_at_mm : null,
                WireLessAccess : null,
                ParkingSpace : null,
                VehicleReg : null,
                ParkingReason : null,
                Call_on_arrival : null,
                Send_to_room : null,
                Comments : null,         
                create : function()
                {
                    var obj = new Object();
                obj.Id ="";
                obj.VisitorsName ="";
                obj.VisitorsOrg ="";
                obj.Name ="";
                obj.Division ="";
                obj.School ="";
                obj.Centre="";          
                obj.Extension="";
                obj.RoomNo ="";
                obj.ExpectedDate="";
                obj.Arriving_at_hr ="";
                obj.Arriving_at_mm ="";
                obj.WireLessAccess ="";
                obj.ParkingSpace ="";
                obj.VehicleReg ="";
                obj.ParkingReason="";
                obj.Call_on_arrival ="";
                obj.Send_to_room ="";
                obj.Comments="";                
  
                    return obj;
                }
          };
              
            function getDataItemKeyValue(radGrid, item)
            {
                return parseInt(radGrid.get_masterTableView().getCellByColumnUniqueName(item,"Id").innerHTML);
            }
              
            function pageLoad(sender, args)
            
                //Id = $find("<%= RadGrid1.ClientID %>").get_masterTableView().get_dataItems()[0].getDataKeyValue("Id");
                Id = getDataItemKeyValue($find("<%= RadGrid1.ClientID %>"),$find("<%= RadGrid1.ClientID %>").get_masterTableView().get_dataItems()[0]);                
  
               $find("<%=VisitorsName.ClientID %>").focus();  
                                
                currentRowIndex = 0;
            }
              
            function rowSelected(sender, args)
            {
                //employeeID = args.getDataKeyValue("EmployeeID");
                Id = getDataItemKeyValue(sender,args.get_gridDataItem());
                  
                currentRowIndex = args.get_gridDataItem().get_element().rowIndex;
  
                $find("<%= RadTabStrip1.ClientID %>").set_selectedIndex(0);               
                 
                ParkingVisit.GetVisitorByVisitorID(Id, setValues);
            }
              
            function setValues(visitor)
            {
                $get("<%= Id.ClientID %>").innerHTML = visitor.Id;
                $find("<%= VisitorsName.ClientID %>").set_value(visitor.VisitorsName);
                $find("<%= VisitorsOrg.ClientID %>").set_value(visitor.VisitorsOrg);
                  
                $find("<%= Name.ClientID %>").set_value(visitor.Name);
                $find("<%= Division.ClientID %>").findItemByText(visitor.Division).select();
                $find("<%= School.ClientID %>").findItemByText(visitor.School).select();                 
                $find("<%= Centre.ClientID %>").findItemByText(visitor.Centre).select();
                $find("<%= Extension.ClientID %>").set_value(visitor.Extension);
                $find("<%= RoomNo.ClientID %>").set_value(visitor.RoomNo);
                $find("<%= ExpectedDate.ClientID %>").set_selectedDate(visitor.ExpectedDate);
                $find("<%= Arrival_at_hr.ClientID %>").findItemByText(visitor.Arriving_at_hr).select();
                $find("<%= Arriving_at_mm.ClientID %>").findItemByText(visitor.Arriving_at_mm).select();
                  
                $find("<%= WireLessAccess.ClientID %>").set_value(visitor.WireLessAccess);
                  
                $find("<%= ParkingSpace.ClientID %>").set_value(visitor.ParkingSpace);
                $find("<%= VehicleReg.ClientID %>").set_value(visitor.VehicleReg);
                $find("<%= ParkingReason.ClientID %>").set_value(visitor.ParkingReason);
                  
                $find("<%= Call_on_arrival.ClientID %>").set_value(visitor.Call_on_arrival);
                $find("<%= Send_to_room.ClientID %>").set_value(visitor.Send_to_room);
                $find("<%= Comments.ClientID %>").set_value(visitor.Comments);     
  
                $find("<%= VisitorsName.ClientID %>").focus();
            }
  
            function getValues()
            {
                visitor.Id = $get("<%= Id.ClientID %>").innerHTML;             
  
                visitor.VisitorsName = $find("<%= VisitorsName.ClientID %>").get_value();
                visitor.VisitorsOrg = $find("<%= VisitorsOrg.ClientID %>").get_value();
                visitor.Name = $find("<%= Name.ClientID %>").get_value();
                visitor.Division = $find("<%= Division.ClientID %>").get_value();
                  
                visitor.School = $find("<%= School.ClientID %>").get_value();
                visitor.Centre = $find("<%= Centre.ClientID %>").get_value();
                visitor.Extension = $find("<%= Extension.ClientID %>").get_value();
                visitor.RoomNo = $find("<%= RoomNo.ClientID %>").get_value();              
                visitor.ExpectedDate = $find("<%= ExpectedDate.ClientID %>").get_selectedDate();
                  
                visitor.Arrival_at_hr = $find("<%= Arrival_at_hr.ClientID %>").get_value();
                visitor.Arriving_at_mm = $find("<%= Arriving_at_mm.ClientID %>").get_value();
                visitor.WireLessAccess = $find("<%= WireLessAccess.ClientID %>").get_value();
                visitor.ParkingSpace = $find("<%= ParkingSpace.ClientID %>").get_value(); 
                  
                visitor.VehicleReg = $find("<%= VehicleReg.ClientID %>").get_value();
                visitor.ParkingReason = $find("<%= ParkingReason.ClientID %>").get_value();
                visitor.Call_on_arrival = $find("<%= Call_on_arrival.ClientID %>").get_value();
                visitor.Send_to_room = $find("<%= Send_to_room.ClientID %>").get_value(); 
                visitor.Comments = $find("<%= Comments.ClientID %>").get_html();
  
                return visitor;
            }
  
            function updateChanges()
            {
                  
               ParkingVisit.UpdateVisitorByVisitor(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(currentVisitor == null)
                {
                    currentVisitor = 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("Id")) + 1; 
                        var newID = getDataItemKeyValue($find("<%= RadGrid1.ClientID %>"),gridItems[gridItems.length - 1]) + 1;
  
                        var newVisitor = visitor.create();
                        newVisitor.Id = newID;
                        setValues(newVisitor);
                          
                        $get("<%= SaveChanges.ClientID %>").value = "Add";
                        $get("<%= Delete.ClientID %>").style.display = "none";
                          
                        break;
                    }
                    default:
                    {
                        setValues(currentVisitor);
                        currentVisitor = 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();
                 
               ParkingVisit.DeleteVisitorByVisitorID(Id, updateGrid);
                gridItems[gridItems.length - 1].set_selected(true);
            }
                          
        </script>
  
    </telerik:RadCodeBlock>
  
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <h1> Visitors Parking Form</h1>
      
    <asp:Panel ID="plForm" runat="server">
    <telerik:RadAjaxLoadingPanel ID="LoadingPanel1" runat="server" IsSticky="True" Style="position: absolute; top: 0; left: 0; height: 100%; width: 100%;">
        </telerik:RadAjaxLoadingPanel>
        <asp:LinqDataSource ID="LinqVisitors" runat="server" 
            ContextTypeName="CWC.Staffnet.Forms.StaffnetDataContext" 
            TableName="tblVisitors" EnableDelete="True" EnableInsert="True" 
            EnableUpdate="True">
        </asp:LinqDataSource>         
  
         <telerik:RadGrid ID="RadGrid1" CssClass="grid" DataSourceID="LinqVisitors" runat="server"
                GridLines="None"  Height="300px" OnDataBound="RadGrid1_DataBound" OnColumnCreated="RadGrid1_ColumnCreated">
                <MasterTableView TableLayout="Fixed" ClientDataKeyNames="Id" />
                <ClientSettings>
                    <Selecting AllowRowSelect="true" />
                    <ClientEvents OnRowSelected="rowSelected" />
                    <Scrolling AllowScroll="true" UseStaticHeaders="true" />
                </ClientSettings>
            </telerik:RadGrid>
 <telerik:RadTabStrip ID="RadTabStrip1" OnClientTabSelected="tabSelected" Style="margin-top: 10px;"
                SelectedIndex="0" runat="server">
                <Tabs>
                    <telerik:RadTab Text="Edit Visitor" />
                    <telerik:RadTab Text="Add new Visitor" />
                </Tabs>
            </telerik:RadTabStrip>
            <div style="border: 1px solid threedshadow;">
                <table border="0" style="margin-top: 20px; width: 100%;">
                    <tr>
                        <td>
                           Visitors Id
                        </td>
                        <td>
                            <asp:Label ID="Id" Style="float: left; font-weight: bold;" runat="server" />
<asp:Button ID="SaveChanges" CssClass="button" Style="float: right; color: black;
font-weight: bold;" OnClientClick="updateChanges(); return false;" Text="Save"
runat="server" />
<asp:Button ID="Delete" CssClass="button" Style="float: right; margin-right: 10px;
color: black; 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>
               </table>
               </div>
                <ol><li>
            <asp:Label ID="lbName" runat="server" Text="Visitor's Name: " AssociatedControlID="txtName"> </asp:Label><telerik:RadTextBox ID="txtName" runat="server" MaxLength="150" Width="200px"></telerik:RadTextBox><asp:RequiredFieldValidator ID="RFV_txtName" runat="server" ControlToValidate="txtName" 
           ErrorMessage="Please enter Visitor's Name"  ValidationGroup="Visitor">*</asp:RequiredFieldValidator></li>
           <li><asp:Label ID="lbOrg" runat="server" Text="Visitor's Organisation: " AssociatedControlID="txtOrg"> </asp:Label><telerik:RadTextBox ID="txtOrg" runat="server" MaxLength="150" Width="200px"></telerik:RadTextBox><asp:RequiredFieldValidator ID="RFV_txtOrg" runat="server" ControlToValidate="txtOrg" 
           ErrorMessage="Please enter Visitor's Organisation Name"  ValidationGroup="Visitor">*</asp:RequiredFieldValidator></li>
           <li><asp:Label ID="lbVisitingName" runat="server" Text="Visting Name: " AssociatedControlID="lstVName"> </asp:Label><telerik:RadComboBox ID="lstVName" runat="server" ReadOnly="true" DataTextField="Name"
    DataValueField="Name" AppendDataBoundItems="True" AllowCustomText="True"  MarkFirstMatch="True"  OnSelectedIndexChanged="lstVName_SelectedIndexChanged" AutoPostBack="True" CausesValidation="False"></telerik:RadComboBox><asp:RequiredFieldValidator ID="RFV_lstVName" runat="server" ValidationGroup="Visitor"  ControlToValidate="lstVName" ErrorMessage="Please name the Person Visiting ">*</asp:RequiredFieldValidator></li>
        <li><asp:Label ID="lbFaculty" runat="server" Text="Faculty/Service:" AssociatedControlID="lstFaculty"></asp:Label><telerik:RadComboBox ID="lstFaculty" runat="server" ReadOnly="true" Enabled="false" DataTextField="Division" DataValueField="Division"></telerik:RadComboBox></li><li></li>
        <li><asp:Label ID="lbSchool" runat="server" Text="School/Section:" AssociatedControlID="lstSchool"></asp:Label><telerik:RadComboBox ID="lstSchool" runat="server" ReadOnly="true" Enabled="False"           AppendDataBoundItems="False" DataTextField="School" DataValueField="School"></telerik:RadComboBox></li>        <li></li>
        <li><asp:Label ID="lbCentre" runat="server" Text="Centre:" AssociatedControlID="lstCentre"></asp:Label><telerik:RadComboBox ID="lstCentre" runat="server" AppendDataBoundItems="True" DataSourceID="LinqCentre" DataTextField="Centre" DataValueField="ID" DataKeyField="ID" DataSortField="Centre" ReadOnly="true"  CausesValidation="False" onselectedindexchanged="lstCentre_SelectedIndexChanged" AutoPostBack="true">
       <Items><telerik:RadComboBoxItem Text="Choose One..." Value="10" /><telerik:RadComboBoxItem Text="Outreach Centre" Value="Outreach Centre" />
       </Items></telerik:RadComboBox><asp:RequiredFieldValidator ID="RFV_Centre" runat="server" ValidationGroup="Visitor"  InitialValue="Choose One..." ControlToValidate="lstCentre" ErrorMessage="Please enter Centre">*</asp:RequiredFieldValidator></li>
       <li><asp:LinqDataSource ID="LinqCentre" runat="server" ContextTypeName="CWC.Staffnet.Forms.StaffnetDataContext" TableName="tblCentres" OrderBy="Centre"></asp:LinqDataSource></li>
       <li><asp:Label ID="lbRoom" runat="server" Text="Meeting in Room Number:" AssociatedControlID="txtRoom"></asp:Label><telerik:RadTextBox ID="txtRoom" runat="server" MaxLength="150" Width="200px"></telerik:RadTextBox><asp:RequiredFieldValidator ID="RFV_txtRoom" runat="server" ValidationGroup="Visitor"
ControlToValidate="txtRoom" ErrorMessage="Please enter Room Number">*</asp:RequiredFieldValidator></li>          <li><asp:Label ID="lbOnDate" runat="server" Text="On (Date):" AssociatedControlID="txtOnDate"></asp:Label><telerik:RadDatePicker ID="txtOnDate" runat="server" DateFormat="dd/MM/yyyy" Enabled="true" Culture="English (United Kingdom)"></telerik:RadDatePicker><asp:RequiredFieldValidator ID="RFV_txtOnDate" ControlToValidate="txtOnDate" ValidationGroup="Visitor" runat="server" ErrorMessage="Please enter On Date.">*</asp:RequiredFieldValidator></li>
        <li><asp:Label ID="lbhhmm" runat="server" Text="Due at(time) hours:minutes:" AssociatedControlID="lsthh"></asp:Label><telerik:RadComboBox ID="lsthh" runat="server" AppendDataBoundItems="True" AutoPostBack="True" CausesValidation="False"  Width="40px" MaxLength="40"><Items><telerik:RadComboBoxItem Text="Choose One..." Value="Choose One..." Selected="True" /><telerik:RadComboBoxItem runat="server" Text="06" Value="06" /><telerik:RadComboBoxItem runat="server" Text="07" Value="07" /><telerik:RadComboBoxItem runat="server" Text="08" Value="08" /><telerik:RadComboBoxItem runat="server" Text="09" Value="09" /><telerik:RadComboBoxItem runat="server" Text="10" Value="10" /><telerik:RadComboBoxItem runat="server" Text="11" Value="11" /><telerik:RadComboBoxItem runat="server" Text="12" Value="12" /><telerik:RadComboBoxItem runat="server" Text="13" Value="13" /><telerik:RadComboBoxItem runat="server" Text="14" Value="14" /><telerik:RadComboBoxItem runat="server" Text="15" Value="15" /><telerik:RadComboBoxItem runat="server" Text="16" Value="16" /><telerik:RadComboBoxItem runat="server" Text="17" Value="17" /><telerik:RadComboBoxItem runat="server" Text="18" Value="18" /><telerik:RadComboBoxItem runat="server" Text="19" Value="19" /><telerik:RadComboBoxItem runat="server" Text="20" Value="20" /><telerik:RadComboBoxItem runat="server" Text="21" Value="21" /></Items></telerik:RadComboBox>
           <b>:</b
        <telerik:RadComboBox ID="lstmm" runat="server" AppendDataBoundItems="True" AutoPostBack="True" CausesValidation="False" Width="40px" MaxLength="40"><Items><telerik:RadComboBoxItem Text="Choose One..." Value="Choose One..." Selected="True" /><telerik:RadComboBoxItem runat="server" Text="00" Value="00" /><telerik:RadComboBoxItem runat="server" Text="05" Value="05" /><telerik:RadComboBoxItem runat="server" Text="10" Value="10" /><telerik:RadComboBoxItem runat="server" Text="15" Value="15" /><telerik:RadComboBoxItem runat="server" Text="20" Value="20" /><telerik:RadComboBoxItem runat="server" Text="25" Value="25" /><telerik:RadComboBoxItem runat="server" Text="30" Value="30" /><telerik:RadComboBoxItem runat="server" Text="35" Value="35" /><telerik:RadComboBoxItem runat="server" Text="40" Value="40" /><telerik:RadComboBoxItem runat="server" Text="45" Value="45" /><telerik:RadComboBoxItem runat="server" Text="50" Value="50" /><telerik:RadComboBoxItem runat="server" Text="55" Value="55" /></Items></telerik:RadComboBox>
        <asp:RequiredFieldValidator ID="RFV_lsthh" runat="server" ValidationGroup="Visitor" InitialValue="Choose One..." ControlToValidate="lsthh" ErrorMessage="Please enter time in hours of visit">*</asp:RequiredFieldValidator>
        <asp:RequiredFieldValidator ID="RFV_lstmm" runat="server" ValidationGroup="Visitor" InitialValue="Choose One..." ControlToValidate="lstmm" ErrorMessage="Please enter time in minutes of visit">*</asp:RequiredFieldValidator>
        </li><li></li>
        <li><asp:Label ID="Label4" runat="server" Text="Wireless Access" AssociatedControlID="chkWireLessRequired"></asp:Label><asp:CheckBox ID="chkWireLessRequired" runat="server" /></li>
        <li><asp:Label ID="lbcarprev" runat="server" Text="<br/>Parking Space" AssociatedControlID="btn_CarPark" Height="24px" Width="300px"></asp:Label>
          <asp:RadioButtonList ID="btn_CarPark" runat="server" RepeatDirection="Horizontal" RepeatColumns="2" Height="16px" Width="126px" AutoPostBack="true" onselectedindexchanged="btn_CarPark_SelectedIndexChanged"><asp:ListItem Value="Yes">Yes</asp:ListItem><asp:ListItem Value="No" Selected="True">No</asp:ListItem></asp:RadioButtonList></li>
          <li><asp:Label ID="Label5" runat="server" Text="Vehicle Registration: " AssociatedControlID="txtVehReg"> </asp:Label><telerik:RadTextBox ID="txtVehReg" runat="server"  Enabled="false" MaxLength="150" Width="200px"></telerik:RadTextBox><asp:RequiredFieldValidator ID="RFV_txtVehReg" runat="server" ControlToValidate="txtVehReg" ErrorMessage="Please enter Vehicle Registration" Visible="False" ValidationGroup="Visitor">*</asp:RequiredFieldValidator></li>
          <li><asp:Label ID="lbReason" runat="server" Text="Reason for parking:" AssociatedControlID="lstParkingReason"></asp:Label>
          <telerik:RadComboBox ID="lstParkingReason" CausesValidation="false" AutoPostBack="true" runat="server" Enabled="false">
          <Items><telerik:RadComboBoxItem Text="Choose One..." Value="0" /><telerik:RadComboBoxItem Text="Meeting" Value="1" /><telerik:RadComboBoxItem Text="Disabled Driver" Value="2" /><telerik:RadComboBoxItem Text="Equipment Collection" Value="3" /><telerik:RadComboBoxItem Text="Equipment Delivery" Value="4" /><telerik:RadComboBoxItem Text="PickUp" Value="5" /><telerik:RadComboBoxItem Text="Minibus" Value="6" /><telerik:RadComboBoxItem Text="Engineer" Value="7" /></Items>
          </telerik:RadComboBox><asp:RequiredFieldValidator ID="RFV_lstParkingReason" ControlToValidate="lstParkingReason" ValidationGroup="Visitor" runat="server" InitialValue="Choose One..."  ErrorMessage="Please enter reason for parking." Visible="False">*</asp:RequiredFieldValidator></li>
          <li></li>
          <li><asp:Label ID="Label7" runat="server" Text="Please call on arrival "  AssociatedControlID="chkArrCall"></asp:Label><asp:CheckBox ID="chkArrCall" runat="server" Checked="true" /><asp:Label ID="Label9" runat="server" Text="Extension " AssociatedControlID="lstExt"></asp:Label><telerik:RadComboBox ID="lstExt" runat="server" ReadOnly="true" Enabled="False" DataTextField="Ext"
            DataValueField="Ext" AppendDataBoundItems="False"></telerik:RadComboBox></li>
          <li><asp:Label ID="Label8" runat="server" Text="Please send to room " AssociatedControlID="chkRoomSend"></asp:Label><asp:CheckBox ID="chkRoomSend" runat="server" /></li><li></li>
          <li><asp:Label ID="lbAddNotes" runat="server" Text="Additional Comments:" AssociatedControlID="txtAddNotes"></asp:Label><asp:TextBox ID="txtAddNotes" runat="server" TextMode="MultiLine" Height="64px" Width="221px"></asp:TextBox><asp:RequiredFieldValidator ID="RFV_AdditionalNotes" ControlToValidate="txtAddNotes" ValidationGroup="Visitor"  runat="server" ErrorMessage="Please enter Additional Comments">*</asp:RequiredFieldValidator></li>          
              
   </ol>
                 
  
    </asp:Panel>
    </asp:Content>
  
*******************************************************************
Visitors.aspx.cs
*******************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using System.Net.Mail;
using config = CWC.Staffnet.Forms.Properties.Settings;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
using System.Configuration;
using System.Data;
  
namespace CWC.Staffnet.Forms.Visitor
{
    public partial class Visitors : System.Web.UI.Page
    {
        private StaffnetDataContext dc;
        protected void Page_Init(object sender, EventArgs e)
        {
            dc = new StaffnetDataContext();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            RadGrid1.SelectedIndexes.Add(0);
  
        }
        protected void RadGrid1_DataBound(object sender, EventArgs e)
        {
            GridDataItem selectedItem = RadGrid1.Items[0];
  
            Id.Text = selectedItem["Id"].Text;
            txtName.Text = selectedItem["VisitorsName"].Text;
            txtOrg.Text = selectedItem["VisitorsOrg"].Text;
            lstVName.FindItemByText(selectedItem["Name"].Text).Selected = true;
            lstFaculty.FindItemByText(selectedItem["Division"].Text).Selected = true;
            lstSchool.FindItemByText(selectedItem["School"].Text).Selected = true;
            lstCentre.FindItemByText(selectedItem["Centre"].Text).Selected = true;
            lstExt.FindItemByText(selectedItem["Extension"].Text).Selected = true;
            txtRoom.Text = selectedItem["RoomNo"].Text;
            txtOnDate.SelectedDate = DateTime.Parse(selectedItem["ExpectedDate"].Text);
            lsthh.FindItemByText(selectedItem["Arriving_at_hr"].Text).Selected = true;
            lstmm.FindItemByText(selectedItem["Arriving_at_mm"].Text).Selected = true;
            chkWireLessRequired.Text = selectedItem["WireLessAccess"].Text;
            btn_CarPark.Text = selectedItem["ParkingSpace"].Text;
            txtVehReg.Text = selectedItem["VehicleReg"].Text;
            lstParkingReason.FindItemByText(selectedItem["ParkingReason"].Text).Selected = true;
            chkArrCall.Text = selectedItem["Call_on_arrival"].Text;
            chkRoomSend.Text = selectedItem["Send_to_room"].Text;
            txtAddNotes.Text = selectedItem["Comments"].Text;
        }
  
        protected void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
        {
            if (e.Column.IsBoundToFieldName("ExpectedDate"))
            {
                ((GridBoundColumn)e.Column).DataFormatString = "{0:MM/dd/yyyy}";
            }
            else if (e.Column.IsBoundToFieldName("Comments"))
            {
                e.Column.Visible = false;
            }
        }
  
        protected void lstVName_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {
  
        }
  
        protected void lstCentre_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            if (lstCentre.SelectedValue == "Outreach Centre")
                RFV_AdditionalNotes.Enabled = true;
            else
                RFV_AdditionalNotes.Enabled = false;
        }
        protected void btn_CarPark_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (btn_CarPark.SelectedValue == "Yes")
            {
                txtVehReg.Enabled = true;
                lstParkingReason.Enabled = true;
                RFV_txtVehReg.Enabled = true;
                RFV_lstParkingReason.Enabled = true;
            }
            else
            {
                txtVehReg.Enabled = false;
                lstParkingReason.Enabled = false;
                RFV_txtVehReg.Enabled = false;
                RFV_lstParkingReason.Enabled = false;
            }
        }
    }
}
***************************************************************
Masters file for scriptmanager
***************************************************************
  
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="CWCStaffnet.master.cs" Inherits="CWC.Staffnet.Forms.CWCStaffnet" %>
  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  
<head runat="server">
    <title>Untitled Page</title>
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
    <link id="Link1" href="~/Styles/Styles.css"  rel="stylesheet"  runat="server" type="text/css" />
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
   <form id="form1" runat="server">
    <h1></h1>
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    <Services>
                <asp:ServiceReference Path="Visitor/ParkingVisit.asmx" />
            </Services>
  
    </telerik:RadScriptManager>
    <telerik:RadFormDecorator ID="RadFormDecorator1" runat="server" />
    <div id="maincontent">
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
        </asp:ContentPlaceHolder>
    </div>
     
    </form>
</body>
</html>
  
*******************************************************************
ParkingVisit.asmx.cs
*******************************************************************
  
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Web;
using System.Web.Script.Services;
using System.Web.Services;
using System.Web.UI;
  
  
namespace CWC.Staffnet.Forms.Visitor
{
    /// <summary>
    /// Summary description for ParkingVisit
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]    
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class ParkingVisit : System.Web.Services.WebService
    {
        VisitorsList visitorList = null;
  
        public ParkingVisit()
        {
            visitorList = new VisitorsList();
  
            if (HttpContext.Current.Session["MyData"] == null)
            {
                HttpContext.Current.Session["MyData"] = visitorList;
            }
        }
        [WebMethod(EnableSession = true)]
        public VisitorsList UpdateVisitorByVisitor(Visitor visitor)
        {
            Visitor VisitorsToUpdate = GetVisitorByVisitorID(visitor.Id);
  
            VisitorsList list = (VisitorsList)HttpContext.Current.Session["MyData"];
  
            if (VisitorsToUpdate == null)
            {
                VisitorsToUpdate = new Visitor();
                VisitorsToUpdate.Id = visitor.Id;
                list.Add(VisitorsToUpdate);
            }
  
            VisitorsToUpdate.VisitorsName = visitor.VisitorsName;
            VisitorsToUpdate.VisitorsOrg = visitor.VisitorsOrg;
            VisitorsToUpdate.Name = visitor.Name;
            VisitorsToUpdate.Division = visitor.Division;
            VisitorsToUpdate.School = visitor.School;
            VisitorsToUpdate.Centre = visitor.Centre;
            VisitorsToUpdate.Extension = visitor.Extension;
            VisitorsToUpdate.RoomNo = visitor.RoomNo;
            VisitorsToUpdate.ExpectedDate = visitor.ExpectedDate;
            VisitorsToUpdate.Arriving_at_hr = visitor.Arriving_at_hr;
            VisitorsToUpdate.Arriving_at_mm = visitor.Arriving_at_mm;
            VisitorsToUpdate.WireLessAccess = visitor.WireLessAccess;
            VisitorsToUpdate.ParkingSpace = visitor.ParkingSpace;
            VisitorsToUpdate.VehicleReg = visitor.VehicleReg;
            VisitorsToUpdate.ParkingReason = visitor.ParkingReason;
            VisitorsToUpdate.Call_on_arrival = visitor.Call_on_arrival;
            VisitorsToUpdate.Send_to_room = visitor.Send_to_room;
            VisitorsToUpdate.Comments = visitor.Comments;
  
            HttpContext.Current.Session["MyData"] = list;
  
            return list;
        }
  
        [WebMethod(EnableSession = true)]
        public VisitorsList DeleteVisitorByVisitorID(int Id)
        {
            Visitor visitorToDelete = GetVisitorByVisitorID(Id);
  
            VisitorsList list = (VisitorsList)HttpContext.Current.Session["MyData"];
            list.Remove(visitorToDelete);
  
            HttpContext.Current.Session["MyData"] = list;
  
            return list;
        }
  
  
        [WebMethod(EnableSession = true)]
        public Visitor GetVisitorByVisitorID(int Id)
        {
            VisitorsList list = (VisitorsList)HttpContext.Current.Session["MyData"];
  
            return list.GetVisitorByVisitorID(Id);
        }
    }
}
**********************************************************************
Visitor.cs
**********************************************************************
  
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
  
namespace CWC.Staffnet.Forms.Visitor
{
    public class Visitor
    {
        private int _Id;
        private string _VisitorsName;
        private string _VisitorsOrg;
        private string _Name;
        private string _Division;
        private string _School;
        private string _Centre;
        private string _Extension;
        private string _RoomNo;
        private System.Nullable<System.DateTime> _ExpectedDate;
        private string _Arriving_at_hr;
        private string _Arriving_at_mm;
        private string _WireLessAccess;
        private string _ParkingSpace;
        private string _VehicleReg;
        private string _ParkingReason;
        private string _Call_on_arrival;
        private string _Send_to_room;
        private string _Comments;
  
        public Visitor()
        {
        }
        public Visitor(SqlDataReader reader)
        {
            _Id = Convert.ToInt32(reader["Id"]);
            _VisitorsName = reader["VisitorsName"].ToString();
            _VisitorsOrg = reader["VisitorsOrg"].ToString();
            _Name = reader["Name"].ToString();
            _Division = reader["Division"].ToString();
            _School = reader["School"].ToString();
            _Centre = reader["Centre"].ToString();
            _Extension = reader["Extension"].ToString();
            _RoomNo = reader["RoomNo"].ToString();
  
            _ExpectedDate = Convert.ToDateTime(reader["ExpectedDate"]);
            _Arriving_at_hr = reader["Arriving_at_hr"].ToString();
            _Arriving_at_mm = reader["Arriving_at_mm"].ToString();
            _WireLessAccess = reader["WireLessAccess"].ToString();
            _ParkingSpace = reader["ParkingSpace"].ToString();
            _VehicleReg = reader["VehicleReg"].ToString();
            _ParkingReason = reader["ParkingReason"].ToString();
            _Call_on_arrival = reader["Call_on_arrival"].ToString();
            _Send_to_room = reader["Send_to_room"].ToString();
            _Comments = reader["Comments"].ToString();
  
        }
        #region Public properties
  
        public int Id
        {
            get
            {
                return this._Id;
            }
            set
            {
                if ((this._Id != value))
                {
                    this._Id = value;
                }
            }
        }
  
        public string VisitorsName
        {
            get
            {
                return this._VisitorsName;
            }
            set
            {
                if ((this._VisitorsName != value))
                {
                    this._VisitorsName = value;
                }
            }
        }
  
        public string VisitorsOrg
        {
            get
            {
                return this._VisitorsOrg;
            }
            set
            {
                if ((this._VisitorsOrg != value))
                {
                    this._VisitorsOrg = value;
                }
            }
        }
  
        public string Name
        {
            get
            {
                return this._Name;
            }
            set
            {
                if ((this._Name != value))
                {
                    this._Name = value;
                }
            }
        }
  
        public string Division
        {
            get
            {
                return this._Division;
            }
            set
            {
                if ((this._Division != value))
                {
                    this._Division = value;
                }
            }
        }
  
        public string School
        {
            get
            {
                return this._School;
            }
            set
            {
                if ((this._School != value))
                {
                    this._School = value;
                }
            }
        }
  
        public string Centre
        {
            get
            {
                return this._Centre;
            }
            set
            {
                if ((this._Centre != value))
                {
                    this._Centre = value;
                }
            }
        }
  
        public string Extension
        {
            get
            {
                return this._Extension;
            }
            set
            {
                if ((this._Extension != value))
                {
                    this._Extension = value;
                }
            }
        }
        public string RoomNo
        {
            get
            {
                return this._RoomNo;
            }
            set
            {
                if ((this._RoomNo != value))
                {
                    this._RoomNo = value;
                }
            }
        }
        public System.Nullable<System.DateTime> ExpectedDate
        {
            get
            {
                return this._ExpectedDate;
            }
            set
            {
                if ((this._ExpectedDate != value))
                {
                    this._ExpectedDate = value;
                }
            }
        }
  
        public string Arriving_at_hr
        {
            get
            {
                return this._Arriving_at_hr;
            }
            set
            {
                if ((this._Arriving_at_hr != value))
                {
                    this._Arriving_at_hr = value;
                }
            }
        }
  
        public string Arriving_at_mm
        {
            get
            {
                return this._Arriving_at_mm;
            }
            set
            {
                if ((this._Arriving_at_mm != value))
                {
                    this._Arriving_at_mm = value;
                }
            }
        }
  
        public string WireLessAccess
        {
            get
            {
                return this._WireLessAccess;
            }
            set
            {
                if ((this._WireLessAccess != value))
                {
                    this._WireLessAccess = value;
                }
            }
        }
  
        public string ParkingSpace
        {
            get
            {
                return this._ParkingSpace;
            }
            set
            {
                if ((this._ParkingSpace != value))
                {
                    this._ParkingSpace = value;
                }
            }
        }
  
        public string VehicleReg
        {
            get
            {
                return this._VehicleReg;
            }
            set
            {
                if ((this._VehicleReg != value))
                {
                    this._VehicleReg = value;
                }
            }
        }
  
        public string ParkingReason
        {
            get
            {
                return this._ParkingReason;
            }
            set
            {
                if ((this._ParkingReason != value))
                {
                    this._ParkingReason = value;
                }
            }
        }
  
        public string Call_on_arrival
        {
            get
            {
                return this._Call_on_arrival;
            }
            set
            {
                if ((this._Call_on_arrival != value))
                {
                    this._Call_on_arrival = value;
                }
            }
        }
  
        public string Send_to_room
        {
            get
            {
                return this._Send_to_room;
            }
            set
            {
                if ((this._Send_to_room != value))
                {
                    this._Send_to_room = value;
                }
            }
        }
  
        public string Comments
        {
            get
            {
                return this._Comments;
            }
            set
            {
                if ((this._Comments != value))
                {
  
                    this._Comments = value;
                }
            }
        }
  
        #endregion
    }
}
  
********************************************************************
VisitorsList.cs
********************************************************************
  
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;
using System.Data.SqlClient;
  
namespace CWC.Staffnet.Forms.Visitor
{
    public class VisitorsList : List<Visitor>
    {
        public VisitorsList()
        {
            LoadAllVisitors();
        }
        private void LoadAllVisitors()
        {
            if (this.Count > 0)
                this.Clear();
  
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["cwc_staffnetConnectionString"].ConnectionString);
            SqlCommand cmd = new SqlCommand
                ("SELECT [Id], [VisitorsName], [VisitorsOrg], [Name], [Division], [School], [Centre], [Extension],[RoomNo], [ExpectedDate], [Arriving_at_hr], [Arriving_at_mm], [WireLessAccess], [ParkingSpace], [VehicleReg], [ParkingReason], [Call_on_arrival], [Send_to_room], [Comments] FROM [tblVisitors]", conn);
            cmd.CommandType = CommandType.Text;
  
            try
            {
  
                conn.Open();
  
                SqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    this.Add(new Visitor(dr));
                }
  
            }
            finally
            {
                conn.Close();
            }
        }
  
        public Visitor GetVisitorByVisitorID(int id)
        {
            foreach (Visitor visitor in this)
            {
                if (visitor.Id == id)
                {
                    return visitor;
                }
            }
            return null;
        }
  
  
    }
}


Thanks
Sucheta


0
Veli
Telerik team
answered on 22 Sep 2010, 02:38 PM
$find() is used to find client-side AJAX compontents associated to server controls. So, $find() expects the ClientID of a server control that has its own AJAX component. All those IDs you use with $find() do not appear to be IDs of server controls on your page.

Veli
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Sucheta Patil
Top achievements
Rank 1
Answers by
Veli
Telerik team
Sucheta Patil
Top achievements
Rank 1
Share this question
or