Wrox Programmer Forums
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old September 19th, 2014, 03:49 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 Detailsview not appearing

Hi Folks, in the below I have a Detailsview inside an updatepanel. In a nut shell it is not working at the moment, all that displays when I run the code is "Page Last Update: 19/09/2014 20:28:43" the detailsview does not appear.

Any help would be greatly appreciated

M

[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:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
DataKeyNames="ID" DataSourceID="SqlDataSource1" Height="50px"
Width="348px" AllowPaging="True" DefaultMode="Edit"
HorizontalAlign="Center">
<Fields>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False"
ReadOnly="True" SortExpression="ID" Visible="False" />
<asp:TemplateField HeaderText="Requested By" SortExpression="Requested By">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="RequestedBy"
DataTextField="Expr1" DataValueField="ID" Width="150px"
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="NatureOfReq"
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="500px"></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:TemplateField HeaderText="Line Manager Comments"
SortExpression="Line Manager Comments">
<EditItemTemplate>
<asp:TextBox ID="TextBox5" runat="server" Height="150px"
Text='<%# Bind("[Line Manager Comments]") %>' TextMode="MultiLine"
Width="500px"></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox4" runat="server"
Text='<%# Bind("[Line Manager Comments]") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server"
Text='<%# Bind("[Line Manager Comments]") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Technician Comments"
HeaderText="Technician Comments" SortExpression="Technician Comments"
Visible="False" />
<asp:BoundField DataField="Date Closed" HeaderText="Date Closed"
SortExpression="Date Closed" Visible="False" />
<asp:BoundField DataField="Date Authorised" HeaderText="Date Authorised"
SortExpression="Date Authorised" />
<asp:BoundField DataField="Hours / Time" HeaderText="Hours / Time"
SortExpression="Hours / Time" Visible="False" />
<asp:BoundField DataField="Priority" HeaderText="Priority"
SortExpression="Priority" Visible="False" />
<asp:BoundField DataField="Assigned to" HeaderText="Assigned to"
SortExpression="Assigned to" Visible="False" />
<asp:CommandField ShowEditButton="True" ShowInsertButton="True" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:RequestsV3ConnectionStringLM %>"
DeleteCommand="DELETE FROM [Main] WHERE [ID] = @ID"
InsertCommand="INSERT INTO [Main] ([Requested By], [Nature of Request / Repair], [Room Number / Location], [Details], [Date Opened], [Line Manager Comments], [Technician Comments], [Date Closed], [Date Authorised], [Hours / Time], [Priority], [Assigned to]) VALUES (@Requested_By, @column1, @column2, @Details, @Date_Opened, @Line_Manager_Comments, @Technician_Comments, @Date_Closed, @Date_Authorised, @column3, @Priority, @Assigned_to)"
SelectCommand="SELECT * FROM [Main] WHERE ([ID] = @ID)"

UpdateCommand="UPDATE [Main] SET [Requested By] = @Requested_By, [Nature of Request / Repair] = @column1, [Room Number / Location] = @column2, [Details] = @Details, [Date Opened] = @Date_Opened, [Line Manager Comments] = @Line_Manager_Comments, [Technician Comments] = @Technician_Comments, [Date Closed] = @Date_Closed, [Date Authorised] = @Date_Authorised, [Hours / Time] = @column3, [Priority] = @Priority, [Assigned to] = @Assigned_to WHERE [ID] = @ID">
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Requested_By" Type="Int32" />
<asp:Parameter Name="column1" Type="Int32" />
<asp:Parameter Name="column2" Type="String" />
<asp:Parameter Name="Details" Type="String" />
<asp:Parameter Name="Date_Opened" Type="DateTime" />
<asp:Parameter Name="Line_Manager_Comments" Type="String" />
<asp:Parameter Name="Technician_Comments" Type="String" />
<asp:Parameter Name="Date_Closed" Type="DateTime" />
<asp:Parameter Name="Date_Authorised" Type="DateTime" />
<asp:Parameter Name="column3" Type="Int32" />
<asp:Parameter Name="Priority" Type="Int32" />
<asp:Parameter Name="Assigned_to" Type="Int32" />
</InsertParameters>
<SelectParameters>
<asp:QueryStringParameter Name="ID" QueryStringField="ID" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="Requested_By" Type="Int32" />
<asp:Parameter Name="column1" Type="Int32" />
<asp:Parameter Name="column2" Type="String" />
<asp:Parameter Name="Details" Type="String" />
<asp:Parameter Name="Date_Opened" Type="DateTime" />
<asp:Parameter Name="Line_Manager_Comments" Type="String" />
<asp:Parameter Name="Technician_Comments" Type="String" />
<asp:Parameter Name="Date_Closed" Type="DateTime" />
<asp:Parameter Name="Date_Authorised" Type="DateTime" />
<asp:Parameter Name="column3" Type="Int32" />
<asp:Parameter Name="Priority" Type="Int32" />
<asp:Parameter Name="Assigned_to" Type="Int32" />
<asp:Parameter Name="ID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="RequestedBy" runat="server"
ConnectionString="<%$ ConnectionStrings:RequestsV3ConnectionString %>"
SelectCommand="SELECT ID, Title + ' ' + Name + ' ' + Surname AS Expr1 FROM Users">
</asp:SqlDataSource>
<asp:SqlDataSource ID="NatureOfReq" runat="server"
ConnectionString="<%$ ConnectionStrings:RequestsV3ConnectionString2 %>"
SelectCommand="SELECT * FROM [Nature of Request]"></asp:SqlDataSource>
<br />
<asp:Label ID="Label2" runat="server" Text="Page Last Update: " ></asp:Label>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Timer ID="Timer1" runat="server" ontick="Timer1_Tick" Interval = "50000"> </asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
 
 
 
</body>
</html>
 

/**Page behind file as below**/
[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)
{
if (!Page.IsPostBack)
{
Label1.Text = DateTime.Now.ToString();
}
}
protected void Timer1_Tick(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToString();
UpdatePanel1.Update();
/*DetailsView1.DataBind();
UpdatePanel1.Update();
*/
}
}

 
  #2 (permalink)  
Old September 19th, 2014, 03:55 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Your DefaultMode is set to Edit: DefaultMode="Edit"

Try setting it to ReadOnly. Also, make sure you call DataBind in the timer's tick event if you want to rebind the data.

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!
  #3 (permalink)  
Old September 20th, 2014, 07:21 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 and thanks for your reply, I removed a where clause from the sqldatasource for the detailsview (not sure what I was thinking) and it is now running….but not properly as the update command still will not work. When you click on update in my browser it does nothing.


UpdateCommand="UPDATE [Main] SET [Requested By] = @Requested_By, [Nature of Request / Repair] = @column1, [Room Number / Location] = @column2, [Details] = @Details, [Date Opened] = @Date_Opened, [Line Manager Comments] = @Line_Manager_Comments, [Technician Comments] = @Technician_Comments, [Date Closed] = @Date_Closed, [Date Authorised] = @Date_Authorised, [Hours / Time] = @column3, [Priority] = @Priority, [Assigned to] = @Assigned_to WHERE [ID] = @ID">

Any Ideas
Mark
  #4 (permalink)  
Old September 21st, 2014, 04:58 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Mark,

Does it work when you move the DetailsView outside the UpdatePanel?

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!
The Following User Says Thank You to Imar For This Useful Post:
markhh (September 22nd, 2014)
  #5 (permalink)  
Old September 21st, 2014, 02:53 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 help. I removed the updatepanel and the page partly ran. The page was rendered but when I clicked the update control the browser started to complain about a problem near a nvarchar which made me look at the whole project again. If I am correct when I click the update control it calls

UpdateCommand="UPDATE [Main] SET [Requested By] = @Requested_By, [Nature of Request / Repair] = @column1, [Room Number / Location] = @column2, [Details] = @Details, [Date Opened] = @Date_Opened, [Line Manager Comments] = @Line_Manager_Comments, [Technician Comments] = @Technician_Comments, [Date Closed] = @Date_Closed, [Date Authorised] = @Date_Authorised, [Hours / Time] = @column3, [Priority] = @Priority, [Assigned to] = @Assigned_to WHERE [ID] = @ID">

If this is correct I am trying to insert a string into some fields which have been defined as integers (which is not good!!) as I have put in some dropdownlists which bring in strings from one table and I have bound them to certain fields in another table eg Nature of Request repair which is defined as an integer.

Does this make sense.

Regards
Mark
  #6 (permalink)  
Old September 21st, 2014, 03:30 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You can't insert strings into integer columns, so it makes sense you're getting an error.

When the data comes from a drop down control, can't you set up that control to display the text but use the underlying int as a value? That should work and send the ID to the database instead of a text string.

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!
The Following User Says Thank You to Imar For This Useful Post:
markhh (September 22nd, 2014)
  #7 (permalink)  
Old September 22nd, 2014, 08:03 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, yes that sounds good. I had another look and created a new page and kept it very basic - an sqldatasource and a details view. Initially there were errors surrounding some of my column headers such as using "of" and "\". I removed them and an error now comes up regarding the scaler variable "@ID". Not sure what this is as the syntax looks fine,

Thanks again Imar
Regards
Mark
  #8 (permalink)  
Old September 22nd, 2014, 11:24 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

>> Not sure what this is as the syntax looks fine,

Neither do I without seeing any code or error messages....

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!
  #9 (permalink)  
Old September 30th, 2014, 06:32 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 went back and changed a few of my column headers in my database and that seems to have worked well for the update command. I have now set an event for the DetailsView, namely ItemInserting to set the date of my Date_Autohrised column but it fails to fire. I have included all my code below, any ideas,

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="125px" AllowPaging="True" AutoGenerateRows="False" 
            DataKeyNames="ID" DataSourceID="SqlDataSource1LM" HorizontalAlign="Center" 
            oniteminserting="DetailsView1_ItemInserting">
            <Fields>
                <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" 
                    ReadOnly="True" SortExpression="ID" />
                <asp:BoundField DataField="Requested_By" HeaderText="Requested_By" 
                    SortExpression="Requested_By" />
                <asp:BoundField DataField="Nature_of_Request_Repair" 
                    HeaderText="Nature_of_Request_Repair" 
                    SortExpression="Nature_of_Request_Repair" />
                <asp:BoundField DataField="Room_Number_Location" 
                    HeaderText="Room_Number_Location" SortExpression="Room_Number_Location" />
                <asp:BoundField DataField="Details" HeaderText="Details" 
                    SortExpression="Details" />
                <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>
    
    </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_ItemInserting(object sender, DetailsViewInsertEventArgs e)
    {
        e.Values ["Date_Authorised"] = DateTime.Now;
    }
}
  #10 (permalink)  
Old September 30th, 2014, 03:34 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

ItemInserting is used to handle SQL INSERTs, not UPDATEs, so I think you're handling the wrong event.

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!




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





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