 |
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
|
|
|

April 26th, 2013, 08:36 AM
|
Authorized User
|
|
Join Date: Apr 2005
Posts: 71
Thanks: 23
Thanked 0 Times in 0 Posts
|
|
GridView Events
Hi Imar, I have entered some data into a database, Name and Date etc but what I am trying to do now is update the database entry with extra comments and the date the extra comments were entered. The extra comments can be entered fine using the update option but I am trying to automate the process of entering the date the extra comments were entered. So I was looking at using either of the RowUpdating or RowUpdated events for the GridView I cant find any code samples for this.
The table again is âMainâ and the field is âDate_Updatedâ
Thanks in advance
Mark
|

April 26th, 2013, 09:35 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
It's pretty much impossible to say something without seeing code and a more detailed description. Can you elaborate and post the relevant code for your pages?
Imar
|

April 29th, 2013, 04:13 AM
|
Authorized User
|
|
Join Date: Apr 2005
Posts: 71
Thanks: 23
Thanked 0 Times in 0 Posts
|
|
Hi Imar, please see below, Date_Updated has been renamed to Date_Authorised
Regards
Mark
.aspx file
Code:
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="LineManager.aspx.cs"Inherits="AdminProtected_LineManager" %>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
<asp:ScriptManagerID="ScriptManager1"runat="server">
</asp:ScriptManager>
<asp:UpdatePanelID="UpdatePanel1"runat="server"UpdateMode="Conditional">
<ContentTemplate>
<br/>
<asp:DetailsViewID="DetailsView1"runat="server"AllowPaging="True"
AutoGenerateRows="False"CellPadding="4"DataKeyNames="ID"
DataSourceID="LineManager"ForeColor="#333333"GridLines="None"Height="50px"
Width="125px"DefaultMode="Edit">
<AlternatingRowStyleBackColor="White"ForeColor="#284775"/>
<CommandRowStyleBackColor="#E2DED6"Font-Bold="True"/>
<EditRowStyleBackColor="#999999"/>
<FieldHeaderStyleBackColor="#E9ECF1"Font-Bold="True"/>
<Fields>
<asp:BoundFieldDataField="ID"HeaderText="ID"InsertVisible="False"
ReadOnly="True"SortExpression="ID"/>
<asp:TemplateFieldHeaderText="Requested_By"SortExpression="Requested_By">
<EditItemTemplate>
<asp:DropDownListID="DropDownList1"runat="server"
DataSourceID="LineManagerUsers"DataTextField="Expr1"DataValueField="ID"
SelectedValue='<%# Bind("Requested_By") %>'>
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownListID="DropDownList1"runat="server"
DataSourceID="LineManagerUsers"DataTextField="Expr1"DataValueField="ID"
SelectedValue='<%# Bind("Requested_By") %>'>
</asp:DropDownList>
</InsertItemTemplate>
<ItemTemplate>
<asp:LabelID="Label1"runat="server"Text='<%# Bind("Requested_By") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateFieldHeaderText="Nature_of_Request_Repair"
SortExpression="Nature_of_Request_Repair">
<EditItemTemplate>
<asp:DropDownListID="DropDownList2"runat="server"
DataSourceID="LineManagerNature"DataTextField="Nature_of_ Repair_Request"
DataValueField="ID"SelectedValue='<%# Bind("Nature_of_Request_Repair") %>'>
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownListID="DropDownList2"runat="server"
DataSourceID="LineManagerNature"DataTextField="Nature_of_ Repair_Request"
DataValueField="ID"SelectedValue='<%# Bind("Nature_of_Request_Repair") %>'>
</asp:DropDownList>
</InsertItemTemplate>
<ItemTemplate>
<asp:LabelID="Label2"runat="server"
Text='<%# Bind("Nature_of_Request_Repair") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundFieldDataField="Room_Number_Location"
HeaderText="Room_Number_Location"SortExpression="Room_Number_Location"/>
<asp:TemplateFieldHeaderText="Details"SortExpression="Details">
<EditItemTemplate>
<asp:TextBoxID="TextBox3"runat="server"Text='<%# Bind("Details") %>'
Height="75px"TextMode="MultiLine"Width="270px"></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBoxID="TextBox3"runat="server"Text='<%# Bind("Details") %>'
Height="75px"TextMode="MultiLine"Width="270px"></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:LabelID="Label3"runat="server"Text='<%# Bind("Details") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundFieldDataField="Date_Opened"HeaderText="Date_Opened"
SortExpression="Date_Opened"/>
<asp:TemplateFieldHeaderText="Line_Manager_Comments"
SortExpression="Line_Manager_Comments">
<EditItemTemplate>
<asp:TextBoxID="TextBox4"runat="server"
Text='<%# Bind("Line_Manager_Comments") %>'Height="75px"
TextMode="MultiLine"Width="270px"></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBoxID="TextBox4"runat="server"
Text='<%# Bind("Line_Manager_Comments") %>'Height="75px"
TextMode="MultiLine"Width="270px"></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:LabelID="Label4"runat="server"
Text='<%# Bind("Line_Manager_Comments") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundFieldDataField="Date_Authorised"HeaderText="Date_Authorised"
SortExpression="Date_Authorised"/>
<asp:CommandFieldShowEditButton="True"ShowInsertButton="True"/>
</Fields>
<FooterStyleBackColor="#5D7B9D"Font-Bold="True"ForeColor="White"/>
<HeaderStyleBackColor="#5D7B9D"Font-Bold="True"ForeColor="White"/>
<PagerStyleBackColor="#284775"ForeColor="White"HorizontalAlign="Center"/>
<RowStyleBackColor="#F7F6F3"ForeColor="#333333"/>
</asp:DetailsView>
<br/>
<asp:SqlDataSourceID="LineManager"runat="server"
ConnectionString="<%$ ConnectionStrings:LineManager %>"
DeleteCommand="DELETE FROM [MainTable] WHERE [ID] = @ID"
InsertCommand="INSERT INTO [MainTable] ([Requested_By], [Nature_of_Request_Repair], [Room_Number_Location], [Details], [Date_Opened], [Line_Manager_Comments], [Date_Authorised]) VALUES (@Requested_By, @Nature_of_Request_Repair, @Room_Number_Location, @Details, @Date_Opened, @Line_Manager_Comments, @Date_Authorised)"
SelectCommand="SELECT [ID], [Requested_By], [Nature_of_Request_Repair], [Room_Number_Location], [Details], [Date_Opened], [Line_Manager_Comments], [Date_Authorised] FROM [MainTable] WHERE ([Date_Authorised] IS NULL)"
UpdateCommand="UPDATE [MainTable] SET [Requested_By] = @Requested_By, [Nature_of_Request_Repair] = @Nature_of_Request_Repair, [Room_Number_Location] = @Room_Number_Location, [Details] = @Details, [Date_Opened] = @Date_Opened, [Line_Manager_Comments] = @Line_Manager_Comments, [Date_Authorised] = @Date_Authorised WHERE [ID] = @ID">
<DeleteParameters>
<asp:ParameterName="ID"Type="Int32"/>
</DeleteParameters>
<InsertParameters>
<asp:ParameterName="Requested_By"Type="Int32"/>
<asp:ParameterName="Nature_of_Request_Repair"Type="Int32"/>
<asp:ParameterName="Room_Number_Location"Type="String"/>
<asp:ParameterName="Details"Type="String"/>
<asp:ParameterName="Date_Opened"Type="DateTime"/>
<asp:ParameterName="Line_Manager_Comments"Type="String"/>
<asp:ParameterName="Date_Authorised"Type="DateTime"/>
</InsertParameters>
<UpdateParameters>
<asp:ParameterName="Requested_By"Type="Int32"/>
<asp:ParameterName="Nature_of_Request_Repair"Type="Int32"/>
<asp:ParameterName="Room_Number_Location"Type="String"/>
<asp:ParameterName="Details"Type="String"/>
<asp:ParameterName="Date_Opened"Type="DateTime"/>
<asp:ParameterName="Line_Manager_Comments"Type="String"/>
<asp:ParameterName="Date_Authorised"Type="DateTime"/>
<asp:ParameterName="ID"Type="Int32"/>
</UpdateParameters>
</asp:SqlDataSource>
<asp:SqlDataSourceID="LineManagerUsers"runat="server"
ConnectionString="<%$ ConnectionStrings:LineManager %>"
SelectCommand="SELECT ID, First_Name + ' ' + Surname AS Expr1 FROM Users">
</asp:SqlDataSource>
<asp:SqlDataSourceID="LineManagerNature"runat="server"
ConnectionString="<%$ ConnectionStrings:LineManager %>"
SelectCommand="SELECT * FROM [NatureOfRequestRepair]">
</asp:SqlDataSource>
<br/>
<asp:TimerID="Timer1"runat="server"Interval="10000"OnTick="Timer1_Tick">
</asp:Timer>
<asp:LabelID="Label1"runat="server"Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
Page behind file
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
publicpartialclassAdminProtected_LineManager : System.Web.UI.Page
{
protectedvoid Timer1_Tick(object sender, EventArgs e)
{
DetailsView1.DataBind();
UpdatePanel1.Update();
Label1.Text = DateTime.Now.ToString();
}
}
|

April 29th, 2013, 06:59 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Quote:
It's pretty much impossible to say something without seeing code and a more detailed description. Can you elaborate and post the relevant code for your pages?
|
You posted your code, but you haven't really explained what the problem is exactly and what you're trying to accomplish.
Also, when you post code, can you paste it in Notepad first to remove color coding? Otherwise this forum messes up the formatting.
Cheers,
Imar
|

April 29th, 2013, 08:26 AM
|
Authorized User
|
|
Join Date: Apr 2005
Posts: 71
Thanks: 23
Thanked 0 Times in 0 Posts
|
|
Hi Imar, what I am trying to do is use the GridViews event handlers, something like the RowUpdating or RowUpdated events to automatically insert the date into Date_Authorised when the update button is clicked on the Gridview.
Cheers
Mark
|

April 29th, 2013, 08:32 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Have you tried hooking into RowUpdating and then using the NewValues column of the e argument (of type GridViewUpdateEventArgs)?
http://msdn.microsoft.com/en-us/libr...eventargs.aspx
http://msdn.microsoft.com/en-us/libr...newvalues.aspx
My Google has thousands of examples of this.
Sorry I can't be more specific. Your messed up code (forum's fault) and limited description make it really hard to suggest something better. Ask better questions and you get better answers.
Imar
|

May 3rd, 2013, 03:45 AM
|
Authorized User
|
|
Join Date: Apr 2005
Posts: 71
Thanks: 23
Thanked 0 Times in 0 Posts
|
|
Hi Imar, and thanks for your suggestion. I will have a look
Regards
Mark
|
|
 |