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