Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > BOOK: Beginning ASP.NET 1.0
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 1.0
This is the forum to discuss the Wrox book Beginning ASP.NET 1.0 with C# by Chris Goode, John Kauffman, Christopher L. Miller, Neil Raybould, S. Srinivasa Sivakumar, Dave Sussman, Ollie Cornes, Rob Birdwell, Matt Butler, Gary Johnson, Ajoy Krishnamoorthy, Juan T. Llibre, Chris Ullman; ISBN: 9780764543708
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 1.0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 23rd, 2005, 05:10 PM
Registered User
 
Join Date: Mar 2005
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Ch14 Add New Event Does Have Errors

Hi,
I am having problem with Add New Event, When I click on the button I get the blank Text Boxes but when I click cancel the blank row is added to my DataGrid. I have tried it over and over again and same problem. The cancel does not work on the Add new....
Please help
thank you in advance

  #2 (permalink)  
Old March 24th, 2005, 09:13 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,111
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Ok...

Can we see your code?

  #3 (permalink)  
Old March 24th, 2005, 11:01 AM
Registered User
 
Join Date: Mar 2005
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is my Code I copied it from book...thanks again in Advance

<%@Page Language="VB" Debug="True" Explicit="True" %>
<%@Import NameSpace="System.Data" %>
<%@Import NameSpace="System.IO" %>
  <script runat="server">

    Sub Page_Load(Sender As Object, E As EventArgs)
      If Not Page.IsPostBack Then
        EventData.DataSource= LoadMyCalendarData
        EventData.DataBind()
      End If
    End Sub

    Protected Function LoadMyCalendarData() As DataSet
      Dim SourceXML As String = Server.MapPath("MyCalendar.xml")
        If ( Not File.Exists ( SourceXML ) ) Then
          Return Nothing
        End If

      Dim CachedDataSet As DataSet = Session("MyCalendarData")
        If ( Not CachedDataSet Is Nothing ) Then
          Return CachedDataSet
        End If

      Dim DataSet As DataSet = New DataSet()

      Try
        DataSet.ReadXml(SourceXML)

        Session("MyCalendarData") = DataSet

      Catch E As Exception
        ErrorMessage.Text = e.Message
        DataSet = Nothing
      End Try

      Return DataSet

    End Function

    Sub DEDR_Edit(Sender As Object, E As DataGridCommandEventArgs)
      EventData.EditItemIndex = CInt(E.Item.ItemIndex)
      EventData.DataSource = LoadMyCalendarData
      EventData.DataBind()
    End Sub

    Sub DEDR_Update(Sender As Object, E As DataGridCommandEventArgs)
      Dim DataSet As DataSet = LoadMyCalendarData
      Dim Row As Integer = CInt(E.Item.ItemIndex)
      Dim EditText As TextBox

      EditText = E.Item.FindControl("txtShortDesc")
      DataSet.Tables(0).Rows(Row).Item("ShortDesc") = EditText.Text
      EditText = E.Item.FindControl("txtDetailDesc")
      DataSet.Tables(0).Rows(Row).Item("DetailDesc") = EditText.Text
      EditText = E.Item.FindControl("txtEventDate")
      DataSet.Tables(0).Rows(Row).Item("EventDate") = EditText.Text
      EditText = E.Item.FindControl("txtStartTime")
      DataSet.Tables(0).Rows(Row).Item("StartTime") = EditText.Text
      EditText = E.Item.FindControl("txtEndTime")
      DataSet.Tables(0).Rows(Row).Item("EndTime") = EditText.Text

      DataSet.WriteXml(Server.MapPath("MyCalendar.xml"))

      Session("MyCalendarData") = Nothing

      EventData.EditItemIndex = -1

      EventData.DataSource = LoadMyCalendarData
      EventData.DataBind()
    End Sub

    Sub DEDR_Cancel(Sender As Object, E As DataGridCommandEventArgs)
      EventData.EditItemIndex = -1
      Session("MyCalendarData") = Nothing
      EventData.DataSource = LoadMyCalendarData
      EventData.DataBind()
    End Sub

    Sub DEDR_Delete(Sender As Object, E As DataGridCommandEventArgs)
      Dim DataSet As DataSet = LoadMyCalendarData
      Dim Row As Integer = CInt(E.Item.ItemIndex)
      DataSet.Tables(0).Rows(Row).Delete
      DataSet.WriteXml(Server.MapPath("MyCalendar.xml"))
      Session("MyCalendarData") = Nothing
      EventData.EditItemIndex = -1
      EventData.DataSource = LoadMyCalendarData
      EventData.DataBind()
    End Sub

    Sub DEDR_Add(Sender As Object, E As EventArgs)
      Dim DataSet As DataSet = LoadMyCalendarData
      Dim NewRow As DataRow
      NewRow = DataSet.Tables(0).NewRow()
      NewRow.Item("EventDate") = ""
      NewRow.Item("ShortDesc") = ""
      NewRow.Item("DetailDesc") = ""
      NewRow.Item("StartTime") = ""
      NewRow.Item("EndTime") = ""
      DataSet.Tables(0).Rows.Add(NewRow)
      DataSet.Writexml(Server.MapPath("MyCalendar.xml"))
      Session("MyCalendarData") = Nothing
      EventData.DataSource = LoadMyCalendarData
      EventData.DataBind()
      EventData.EditItemIndex = EventData.Items.Count - 1
      EventData.DataSource = LoadMyCalendarData
      EventData.DataBind()
    End Sub

  </script>
<html>
  <body>
    <form runat="server">
      <asp:Label ID="ErrorMessage" runat="server" /><br>

      <asp:LinkButton OnClick="DEDR_Add" Text="Add New Event" runat="server"/><br>
      <a href="MyCalendar.aspx">Back To Calendar</a><br>

      <asp:DataGrid ID="EventData"
           AutoGenerateColumns="false" Width="100%" runat="server"
           OnEditCommand="DEDR_Edit"
           OnUpdateCommand="DEDR_Update"
           OnCancelCommand="DEDR_Cancel"
           OnDeleteCommand="DEDR_Delete"
           >

      <headerstyle ForeColor="White" BackColor="DodgerBlue" Font-Bold="true"/>

      <itemstyle BackColor="White"/>

      <alternatingitemstyle BackColor="Gainsboro"/>

      <columns>
        <asp:TemplateColumn HeaderText="Date">
          <itemtemplate>
            <%# DataBinder.Eval(Container.DataItem, "EventDate") %>
          </itemtemplate>
          <edititemtemplate>
            <asp:TextBox ID="txtEventDate" size="25" Text='<%# DataBinder.Eval(Container.DataItem, "EventDate") %>' runat="server"/>
          </edititemtemplate>
        </asp:TemplateColumn>

        <asp:TemplateColumn HeaderText="Event">
          <itemtemplate>
            <%# Container.DataItem("ShortDesc") %>
          </itemtemplate>
          <edititemtemplate>
            <asp:TextBox ID="txtShortDesc" Size="25" Text='<%# DataBinder.Eval(Container.DataItem, "ShortDesc") %>' runat="server"/>
          </edititemtemplate>
        </asp:TemplateColumn>

        <asp:TemplateColumn HeaderText="Description">
          <itemtemplate>
            <%# Container.DataItem("DetailDesc") %>
          </itemtemplate>
          <edititemtemplate>
            <asp:TextBox ID="txtDetailDesc" Size="50" Text='<%# DataBinder.Eval(Container.DataItem, "DetailDesc") %>' runat="server"/>
          </edititemtemplate>
        </asp:TemplateColumn>

        <asp:TemplateColumn HeaderText="Start Time">
          <itemtemplate>
            <%# Container.DataItem("StartTime") %>
          </itemtemplate>
          <edititemtemplate>
            <asp:TextBox ID="txtStartTime" size="7" Text='<%# DataBinder.Eval(Container.DataItem, "StartTime") %>' runat="server"/>
          </edititemtemplate>
        </asp:TemplateColumn>

        <asp:TemplateColumn HeaderText="End Time">
          <itemtemplate>
            <%# Container.DataItem("EndTime") %>
          </itemtemplate>
          <edititemtemplate>
            <asp:TextBox ID="txtEndTime" size="7" Text='<%# DataBinder.Eval(Container.DataItem, "EndTime") %>' runat="server"/>
          </edititemtemplate>
        </asp:TemplateColumn>

        <asp:TemplateColumn>
          <itemtemplate>
            <asp:LinkButton CommandName="Edit" Text="Edit" runat="server"/>
            <asp:LinkButton CommandName="Delete" Text="Delete" runat="server"/>
          </itemtemplate>
          <edititemtemplate>
            <asp:LinkButton CommandName="Cancel" Text="Cancel" runat="server"/>
            <asp:LinkButton CommandName="Update" Text="Update" runat="server"/>
          </edititemtemplate>
        </asp:TemplateColumn>
      </columns>
           </asp:DataGrid>
    </form>
  </body>
</html>

 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
HOW TO ADD AN EVENT HANDLER pallone .NET Framework 2.0 10 September 16th, 2008 12:28 PM
Chapter 19, p.970, Can't Add Event Handler Spasticus BOOK: Ivor Horton's Beginning Visual C++ 2005 0 January 6th, 2008 05:13 PM
My VB Code for Ch14 PatFrank BOOK: Beginning ASP.NET 2.0 and Databases 8 April 17th, 2007 02:34 PM



All times are GMT -4. The time now is 01:42 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.