Protected Sub FormView1_ItemInserted(ByVal sender As Object, ByVal e As FormViewInsertedEventArgs)
If (Not e.Exception Is Nothing) Then
' lblError.Text = e.Exception.Message
e.ExceptionHandled = True
Return
End If
ScheduleCalendar1.DataBind()
End Sub
Protected Sub FormView1_ItemUpdated(ByVal sender As Object, ByVal e As FormViewUpdatedEventArgs)
If (Not e.Exception Is Nothing) Then
' lblError.Text = e.Exception.Message
e.ExceptionHandled = True
Return
End If
ScheduleCalendar1.DataBind()
End Sub
Protected Sub FormView1_ItemDeleted(ByVal sender As Object, ByVal e As FormViewDeletedEventArgs)
If (Not e.Exception Is Nothing) Then
'lblError.Text = e.Exception.Message
e.ExceptionHandled = True
Return
End If
ScheduleCalendar1.DataBind()
End Sub
Protected Function RemoveDatePart(ByVal dt As DateTime) As DateTime
' MS Access uses 12/30/1899 as the date for short times
Return New DateTime(1899, 12, 30, dt.Hour, dt.Minute, dt.Second)
End Function
Protected Sub FormView1_ItemUpdating(ByVal sender As Object, ByVal e As FormViewUpdateEventArgs)
' Intercept update and remove date part from time fields
e.NewValues("StartTime") = RemoveDatePart(e.NewValues("StartTime"))
e.NewValues("EndTime") = RemoveDatePart(e.NewValues("EndTime"))
End Sub
Protected Sub FormView1_ItemInserting(ByVal sender As Object, ByVal e As FormViewInsertEventArgs)
' Intercept insert and remove date part from time fields
e.Values("StartTime") = RemoveDatePart(e.Values("StartTime"))
e.Values("EndTime") = RemoveDatePart(e.Values("EndTime"))
End Sub
Protected Sub FormView1_DataBound(ByVal sender As Object, ByVal e As EventArgs)
If (FormView1.CurrentMode = FormViewMode.ReadOnly) Then
Dim btnDelete As LinkButton = FormView1.FindControl("DeleteButton")
If (btnDelete IsNot Nothing) Then
btnDelete.Attributes.Add("onclick", "return confirm(""Are you sure?"")")
End If
End If
End Sub
Protected Sub Schedule1_EmptySlotClick(ByVal sender As Object, ByVal e As ClickableTableCellEventArgs)
' prepare the FormView for inserting the selected slot
FormView1.DefaultMode = FormViewMode.Insert
If (FormView1.FindControl("StartTimeTextBox") Is Nothing) Then
' When there has been a postback already, and the FormView is not yet in insert mode,
' we end up here. As a consequence, in this case, the user needs to click twice
' on the slot to add a new item.
' Any help with this problem is appreciated.
FormView1.ChangeMode(FormViewMode.Insert)
Return
End If
CType(FormView1.FindControl("StartTimeTextBox"), TextBox).Text = e.RangeStartValue
CType(FormView1.FindControl("EndTimeTextBox"), TextBox).Text = e.RangeEndValue
CType(FormView1.FindControl("EventDateTextBox"), TextBox).Text = CDate(e.Title).ToShortDateString()
CType(FormView1.FindControl("TaskTextBox"), TextBox).Text = ""
End Sub
Protected Sub Schedule1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
FormView1.ChangeMode(FormViewMode.ReadOnly)
End Sub
chintan12
0 Points
2 Posts
schdulecalendar
Apr 15, 2012 05:56 AM|LINK
i had used th eschedule calendar n formview to add n delete the entries to the ccalendar for my vey important module but i m facing the error
Property 'ID' not found in object of type System.Data.DataRowView
here is the code please help me out its urgent....
<%@ Page Title="" Language="VB" MasterPageFile="~/DoctorMasterPage.master" AutoEventWireup="false" CodeFile="Default6.aspx.vb" Inherits="Default6" %>
<%@ Import Namespace="rw.Objects" %>
<%@ Register assembly="Schedule2" namespace="rw" tagprefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<p>
<script runat="server">
Protected Sub FormView1_ItemInserted(ByVal sender As Object, ByVal e As FormViewInsertedEventArgs)
If (Not e.Exception Is Nothing) Then
' lblError.Text = e.Exception.Message
e.ExceptionHandled = True
Return
End If
ScheduleCalendar1.DataBind()
End Sub
Protected Sub FormView1_ItemUpdated(ByVal sender As Object, ByVal e As FormViewUpdatedEventArgs)
If (Not e.Exception Is Nothing) Then
' lblError.Text = e.Exception.Message
e.ExceptionHandled = True
Return
End If
ScheduleCalendar1.DataBind()
End Sub
Protected Sub FormView1_ItemDeleted(ByVal sender As Object, ByVal e As FormViewDeletedEventArgs)
If (Not e.Exception Is Nothing) Then
'lblError.Text = e.Exception.Message
e.ExceptionHandled = True
Return
End If
ScheduleCalendar1.DataBind()
End Sub
Protected Function RemoveDatePart(ByVal dt As DateTime) As DateTime
' MS Access uses 12/30/1899 as the date for short times
Return New DateTime(1899, 12, 30, dt.Hour, dt.Minute, dt.Second)
End Function
Protected Sub FormView1_ItemUpdating(ByVal sender As Object, ByVal e As FormViewUpdateEventArgs)
' Intercept update and remove date part from time fields
e.NewValues("StartTime") = RemoveDatePart(e.NewValues("StartTime"))
e.NewValues("EndTime") = RemoveDatePart(e.NewValues("EndTime"))
End Sub
Protected Sub FormView1_ItemInserting(ByVal sender As Object, ByVal e As FormViewInsertEventArgs)
' Intercept insert and remove date part from time fields
e.Values("StartTime") = RemoveDatePart(e.Values("StartTime"))
e.Values("EndTime") = RemoveDatePart(e.Values("EndTime"))
End Sub
Protected Sub FormView1_DataBound(ByVal sender As Object, ByVal e As EventArgs)
If (FormView1.CurrentMode = FormViewMode.ReadOnly) Then
Dim btnDelete As LinkButton = FormView1.FindControl("DeleteButton")
If (btnDelete IsNot Nothing) Then
btnDelete.Attributes.Add("onclick", "return confirm(""Are you sure?"")")
End If
End If
End Sub
Protected Sub Schedule1_EmptySlotClick(ByVal sender As Object, ByVal e As ClickableTableCellEventArgs)
' prepare the FormView for inserting the selected slot
FormView1.DefaultMode = FormViewMode.Insert
If (FormView1.FindControl("StartTimeTextBox") Is Nothing) Then
' When there has been a postback already, and the FormView is not yet in insert mode,
' we end up here. As a consequence, in this case, the user needs to click twice
' on the slot to add a new item.
' Any help with this problem is appreciated.
FormView1.ChangeMode(FormViewMode.Insert)
Return
End If
CType(FormView1.FindControl("StartTimeTextBox"), TextBox).Text = e.RangeStartValue
CType(FormView1.FindControl("EndTimeTextBox"), TextBox).Text = e.RangeEndValue
CType(FormView1.FindControl("EventDateTextBox"), TextBox).Text = CDate(e.Title).ToShortDateString()
CType(FormView1.FindControl("TaskTextBox"), TextBox).Text = ""
End Sub
Protected Sub Schedule1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
FormView1.ChangeMode(FormViewMode.ReadOnly)
End Sub
</script>
<br />
</p>
<cc1:ScheduleCalendar ID="ScheduleCalendar1" runat="server"
DataSourceID="SqlDataSource1" StartOfTimeScale="08:00:00"
ShowValueMarks="True"
EndOfTimeScale="16:00:00" TimeScaleInterval="30" BorderColor="Gray"
DateField="EventDate" StartTimeField="StartTime" EndTimeField="EndTime"
Layout="Vertical" GridLines="Both" CellSpacing="0"
DataKeyNames="ID" HorizontalAlign="NotSet"
StartDay="Monday" EnableEmptySlotClick="True"
OnEmptySlotClick="Schedule1_EmptySlotClick"
OnSelectedIndexChanged="Schedule1_SelectedIndexChanged"
FullTimeScale="True" ItemStyleField="" StartDate="2012-04-09" Weeks="1">
<TimeTemplate>
<%#Container.DataItem.ToShortTimeString()%>
</TimeTemplate>
<DateStyle cssclass="title"></DateStyle>
<DateTemplate>
<%# CDate(Container.DataItem).ToString("ddd d/M/yyyy") %>
</DateTemplate>
<BackgroundStyle cssclass="bground"></BackgroundStyle>
<ItemStyle cssclass="item" Width="50px"></ItemStyle>
<TimeStyle cssclass="rangeheader"></TimeStyle>
<ItemTemplate>
<asp:LinkButton id="LinkButton1" runat="Server" CommandName="Select" ><%#Eval("Task")%></asp:LinkButton>
</ItemTemplate>
</cc1:ScheduleCalendar>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:medicalConnectionString %>"
SelectCommand="SELECT * FROM [app]"></asp:SqlDataSource>
<asp:FormView ID="FormView1" runat="server" CellPadding="4" DataKeyNames="Task"
DataSourceID="SqlDataSource2" ForeColor="#333333">
<EditItemTemplate>
StartTime:
<asp:TextBox ID="StartTimeTextBox" runat="server"
Text='<%# Bind("StartTime") %>' />
<br />
EndTime:
<asp:TextBox ID="EndTimeTextBox" runat="server" Text='<%# Bind("EndTime") %>' />
<br />
EventDate:
<asp:TextBox ID="EventDateTextBox" runat="server"
Text='<%# Bind("EventDate") %>' />
<br />
Task:
<asp:Label ID="TaskLabel1" runat="server" Text='<%# Eval("Task") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<InsertItemTemplate>
StartTime:
<asp:TextBox ID="StartTimeTextBox" runat="server"
Text='<%# Bind("StartTime") %>' />
<br />
EndTime:
<asp:TextBox ID="EndTimeTextBox" runat="server" Text='<%# Bind("EndTime") %>' />
<br />
EventDate:
<asp:TextBox ID="EventDateTextBox" runat="server"
Text='<%# Bind("EventDate") %>' />
<br />
Task:
<asp:TextBox ID="TaskTextBox" runat="server" Text='<%# Bind("Task") %>' />
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="Insert" />
<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
StartTime:
<asp:Label ID="StartTimeLabel" runat="server" Text='<%# Bind("StartTime") %>' />
<br />
EndTime:
<asp:Label ID="EndTimeLabel" runat="server" Text='<%# Bind("EndTime") %>' />
<br />
EventDate:
<asp:Label ID="EventDateLabel" runat="server" Text='<%# Bind("EventDate") %>' />
<br />
Task:
<asp:Label ID="TaskLabel" runat="server" Text='<%# Eval("Task") %>' />
<br />
<asp:LinkButton ID="EditButton" runat="server" CausesValidation="False"
CommandName="Edit" Text="Edit" />
<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False"
CommandName="Delete" Text="Delete" />
<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False"
CommandName="New" Text="New" />
</ItemTemplate>
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:medicalConnectionString %>"
DeleteCommand="DELETE FROM [app] WHERE [Task] = @original_Task AND (([StartTime] = @original_StartTime) OR ([StartTime] IS NULL AND @original_StartTime IS NULL)) AND (([EndTime] = @original_EndTime) OR ([EndTime] IS NULL AND @original_EndTime IS NULL)) AND (([EventDate] = @original_EventDate) OR ([EventDate] IS NULL AND @original_EventDate IS NULL))"
InsertCommand="INSERT INTO [app] ([StartTime], [EndTime], [EventDate], [Task]) VALUES (@StartTime, @EndTime, @EventDate, @Task)"
OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT * FROM [app]"
UpdateCommand="UPDATE [app] SET [StartTime] = @StartTime, [EndTime] = @EndTime, [EventDate] = @EventDate WHERE [Task] = @original_Task AND (([StartTime] = @original_StartTime) OR ([StartTime] IS NULL AND @original_StartTime IS NULL)) AND (([EndTime] = @original_EndTime) OR ([EndTime] IS NULL AND @original_EndTime IS NULL)) AND (([EventDate] = @original_EventDate) OR ([EventDate] IS NULL AND @original_EventDate IS NULL))">
<DeleteParameters>
<asp:Parameter Name="original_Task" Type="String" />
<asp:Parameter Name="original_StartTime" Type="DateTime" />
<asp:Parameter Name="original_EndTime" Type="DateTime" />
<asp:Parameter DbType="Date" Name="original_EventDate" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="StartTime" Type="DateTime" />
<asp:Parameter Name="EndTime" Type="DateTime" />
<asp:Parameter DbType="Date" Name="EventDate" />
<asp:Parameter Name="Task" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="StartTime" Type="DateTime" />
<asp:Parameter Name="EndTime" Type="DateTime" />
<asp:Parameter DbType="Date" Name="EventDate" />
<asp:Parameter Name="original_Task" Type="String" />
<asp:Parameter Name="original_StartTime" Type="DateTime" />
<asp:Parameter Name="original_EndTime" Type="DateTime" />
<asp:Parameter DbType="Date" Name="original_EventDate" />
</UpdateParameters>
</asp:SqlDataSource>
<p>
</p>
<p>
</p>
</asp:Content>
TimoYang
Contributor
3732 Points
1275 Posts
Re: schdulecalendar
Apr 15, 2012 08:59 AM|LINK
Check whether your DataTable that is bound to the GridView has the property column "ID" or not……
chintan12
0 Points
2 Posts
Re: schdulecalendar
Apr 15, 2012 10:48 AM|LINK
i had not use gridview.i have use formview and it does not have propert column 'ID'.
TimoYang
Contributor
3732 Points
1275 Posts
Re: schdulecalendar
Apr 16, 2012 01:18 AM|LINK
Add the column of ID first,
And then make sure that your dataSource MUST HAVE THAT.