Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion 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
Reply
 
Thread Tools Search this Thread Display Modes
  #11 (permalink)  
Old September 30th, 2014, 05:38 PM
Authorized User
Points: 303, Level: 6
Points: 303, Level: 6 Points: 303, Level: 6 Points: 303, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: , , United Kingdom.
Posts: 71
Thanks: 23
Thanked 0 Times in 0 Posts
Default

Hi Imar and many thanks for your reply. Is there another option I could look into to insert the date on an updatecommand eg can it by inserted from the updatecommand "UpdateCommand="UPDATE Main SET Line_Manager_Comments = @Line_Manager_Comments, Date_Authorised = Date.TimeNow, WHERE (ID = @ID)">",

Regards
Mark
Reply With Quote
  #12 (permalink)  
Old September 30th, 2014, 05:49 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

You could use SQL Server's getdate in your query for that, or you can handle the DetailView's ItemUpdating event: http://msdn.microsoft.com/en-us/libr...vs.110%29.aspx

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
The Following User Says Thank You to Imar For This Useful Post:
markhh (October 1st, 2014)
  #13 (permalink)  
Old October 1st, 2014, 05:36 AM
Authorized User
Points: 303, Level: 6
Points: 303, Level: 6 Points: 303, Level: 6 Points: 303, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: , , United Kingdom.
Posts: 71
Thanks: 23
Thanked 0 Times in 0 Posts
Default

Thanks Imar, I will have a look,

Regards
Mark
Reply With Quote
  #14 (permalink)  
Old October 1st, 2014, 11:57 AM
Authorized User
Points: 303, Level: 6
Points: 303, Level: 6 Points: 303, Level: 6 Points: 303, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: , , United Kingdom.
Posts: 71
Thanks: 23
Thanked 0 Times in 0 Posts
Default

Hello again Imar, I have had another go using the itemupdating event handler but it still appears to be not firing. Any help would be greatly appreciated,

Regards
Mark

Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="LineManager.aspx.cs" Inherits="LineManager_LineManager" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:DetailsView ID="DetailsView1" runat="server" DefaultMode="Edit" 
            Height="50px" Width="275px" AllowPaging="True" AutoGenerateRows="False" 
            DataKeyNames="ID" DataSourceID="SqlDataSource1LM" HorizontalAlign="Center" 
            onitemupdating="DetailsView1_ItemUpdating">
            <Fields>
                <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" 
                    ReadOnly="True" SortExpression="ID" />
                <asp:TemplateField HeaderText="Requested_By" SortExpression="Requested_By">
                    <EditItemTemplate>
                        <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="RequestedBy" 
                            DataTextField="Expr1" DataValueField="ID" 
                            SelectedValue='<%# Bind("Requested_By") %>'>
                        </asp:DropDownList>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Requested_By") %>'></asp:TextBox>
                    </InsertItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("Requested_By") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Nature_of_Request_Repair" 
                    SortExpression="Nature_of_Request_Repair">
                    <EditItemTemplate>
                        <asp:DropDownList ID="DropDownList2" runat="server" 
                            DataSourceID="NatureOfRequest" DataTextField="Nature_of_Request_Repair" 
                            DataValueField="ID" SelectedValue='<%# Bind("Nature_of_Request_Repair") %>'>
                        </asp:DropDownList>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:TextBox ID="TextBox2" runat="server" 
                            Text='<%# Bind("Nature_of_Request_Repair") %>'></asp:TextBox>
                    </InsertItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label2" runat="server" 
                            Text='<%# Bind("Nature_of_Request_Repair") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="Room_Number_Location" 
                    HeaderText="Room_Number_Location" SortExpression="Room_Number_Location" />
                <asp:TemplateField HeaderText="Details" SortExpression="Details">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox4" runat="server" Height="150px" 
                            Text='<%# Bind("Details") %>' TextMode="MultiLine" Width="250px"></asp:TextBox>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Details") %>'></asp:TextBox>
                    </InsertItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label3" runat="server" Text='<%# Bind("Details") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="Date_Opened" HeaderText="Date_Opened" 
                    SortExpression="Date_Opened" />
                <asp:BoundField DataField="Line_Manager_Comments" 
                    HeaderText="Line_Manager_Comments" SortExpression="Line_Manager_Comments" />
                <asp:BoundField DataField="Date_Authorised" HeaderText="Date_Authorised" 
                    SortExpression="Date_Authorised" />
                <asp:CommandField ShowEditButton="True" />
            </Fields>
        </asp:DetailsView>
        <asp:SqlDataSource ID="SqlDataSource1LM" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ConnectionStringV4 %>" 
            SelectCommand="SELECT ID, Requested_By, Nature_of_Request_Repair, Room_Number_Location, Details, Date_Opened, Line_Manager_Comments, Date_Authorised FROM Main WHERE (Date_Authorised IS NULL)" 
            UpdateCommand="UPDATE Main SET Line_Manager_Comments = @Line_Manager_Comments WHERE (ID = @ID)">
            <UpdateParameters>
                <asp:Parameter Name="Line_Manager_Comments" />
                <asp:Parameter Name="ID" />
            </UpdateParameters>
        </asp:SqlDataSource>
    
        <br />
        <asp:SqlDataSource ID="RequestedBy" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ConnectionStringV4 %>" 
            SelectCommand="SELECT ID, Title + ' ' + Name + ' ' + Surname AS Expr1 FROM Users"></asp:SqlDataSource>
    
        <br />
        <asp:SqlDataSource ID="NatureOfRequest" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ConnectionStringV4 %>" 
            SelectCommand="SELECT * FROM [Nature of Request]"></asp:SqlDataSource>
        <br />
        <br />
    
    </div>
    </form>
</body>
</html>

Page Behind

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class LineManager_LineManager : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected void DetailsView1_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
    {
        e.NewValues["Date_Authorised"] = DateTime.Now;
    }
}
Reply With Quote
  #15 (permalink)  
Old October 1st, 2014, 12:08 PM
Authorized User
Points: 303, Level: 6
Points: 303, Level: 6 Points: 303, Level: 6 Points: 303, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: , , United Kingdom.
Posts: 71
Thanks: 23
Thanked 0 Times in 0 Posts
Default

Update on the above, there is currently a NULL value in the Date_Authorised column in question.

Mark
Reply With Quote
  #16 (permalink)  
Old October 1st, 2014, 03:27 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

I don't see the field you're updating in the code behind in your SQL statement. You need to add that for the update to work.

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #17 (permalink)  
Old October 2nd, 2014, 03:54 PM
Authorized User
Points: 303, Level: 6
Points: 303, Level: 6 Points: 303, Level: 6 Points: 303, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: , , United Kingdom.
Posts: 71
Thanks: 23
Thanked 0 Times in 0 Posts
Default

Hi Imar, I have some sort of result by adding Date_Authorised = GetDate() on the command control. I was really hoping to get at least one of the events working on the Details view as they look very handy.

Anyway, the column I am updating is in the page behind
Code:
 protected void DetailsView1_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
    {
        e.NewValues["Date_Authorised"] = DateTime.Now;
    }
I thought this would do the trick, as it is the same format as your example on page 472 (although that one is an ItemInserting)

Regards
Mark
Reply With Quote
  #18 (permalink)  
Old October 6th, 2014, 03:18 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

>> I thought this would do the trick, as it is the same format as your example on page 472

Yes, I believe that should work. Did you try debugging the code by putting a break point in that method with F9 and then running the site by pressing F5?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #19 (permalink)  
Old October 7th, 2014, 08:24 AM
Authorized User
Points: 303, Level: 6
Points: 303, Level: 6 Points: 303, Level: 6 Points: 303, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: , , United Kingdom.
Posts: 71
Thanks: 23
Thanked 0 Times in 0 Posts
Default

Hi Imar, no I haven't tried debugging but I will and post the results,

Regards
Mark
Reply With Quote
  #20 (permalink)  
Old October 8th, 2014, 10:49 AM
Authorized User
Points: 303, Level: 6
Points: 303, Level: 6 Points: 303, Level: 6 Points: 303, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: , , United Kingdom.
Posts: 71
Thanks: 23
Thanked 0 Times in 0 Posts
Default

Hi Imar, I have created a basic page with single table to test what is going on. The code is as follows

Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="Test" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" 
            AutoGenerateRows="False" DataKeyNames="ID" DataSourceID="SqlDataSource1" 
            DefaultMode="Edit" Height="50px" oniteminserting="DetailsView1_ItemInserting" 
            Width="125px">
            <Fields>
                <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" 
                    ReadOnly="True" SortExpression="ID" />
                <asp:BoundField DataField="First_Name" HeaderText="First_Name" 
                    SortExpression="First_Name" />
                <asp:CommandField ShowEditButton="True" ShowInsertButton="True" />
            </Fields>
        </asp:DetailsView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
            DeleteCommand="DELETE FROM [Main_Table] WHERE [ID] = @ID" 
            InsertCommand="INSERT INTO [Main_Table] ([First_Name]) VALUES (@First_Name)" 
            SelectCommand="SELECT [ID], [First_Name] FROM [Main_Table]" 
            UpdateCommand="UPDATE [Main_Table] SET [First_Name] = @First_Name WHERE [ID] = @ID">
            <DeleteParameters>
                <asp:Parameter Name="ID" Type="Int32" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="First_Name" Type="String" />
            </InsertParameters>
            <UpdateParameters>
                <asp:Parameter Name="First_Name" Type="String" />
                <asp:Parameter Name="ID" Type="Int32" />
            </UpdateParameters>
        </asp:SqlDataSource>
    
    </div>
    </form>
</body>
</html>

Page Behind
Code:
page behind
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Test : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
    {
        e.Values["Your_Age"] = 22;
    }
}

I have inserted a breakpoint on the starting line of the item_inserting method, pressed F5 which renders the page in the browser. From here I can insert a new Name but the Your_Age column is not updated via the
DetailsView1_ItemInserting method. When I try pressing F10 to advance the code nothing happens in the browser and I am not returned VWD. The breakpoint has moved down one line but its colour remains red with no arrow. Pressing F10 does nothing here also.

the web.config page looks like this

Code:
<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
 <connectionStrings>
  <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
  <add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
 </connectionStrings>
 <system.web>
  <compilation debug="true" targetFramework="4.0"/>
  <authentication mode="Forms">
   <forms loginUrl="~/Account/Login.aspx" timeout="2880"/>
  </authentication>
  <membership>
   <providers>
    <clear/>
    <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/"/>
   </providers>
  </membership>
  <profile>
   <providers>
    <clear/>
    <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
   </providers>
  </profile>
  <roleManager enabled="false">
   <providers>
    <clear/>
    <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/"/>
    <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/"/>
   </providers>
  </roleManager>
 </system.web>
 <system.webServer>
  <modules runAllManagedModulesForAllRequests="true"/>
 </system.webServer>
</configuration>
Any pointers
Mark
Reply With Quote
Reply


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
Images and Graphics Not Appearing jh3144 BOOK: PHP and MySQL 24-Hour Trainer 0 August 17th, 2012 03:01 PM
instead of font boxes appearing macdev BOOK: Beginning Mac OS X Programming 1 August 22nd, 2007 05:27 AM
Database not appearing in browser sevans BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 1 May 30th, 2007 06:46 AM
form re-appearing problem Derek_05 Access VBA 1 January 16th, 2006 07:50 PM
Javascript Errors Not Appearing itHighway Javascript How-To 1 October 13th, 2005 01:30 AM



All times are GMT -4. The time now is 08:40 PM.


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