[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

ASP.NET Formview update inside ModalPopupExtender

Posted on 2012-08-14
5
Medium Priority
?
3,537 Views
Last Modified: 2012-08-15
Hi Experts,

I'm trying to do something similar to that shown in a blog post by Matt Berseth.  I have a GridView reporting some records from a table.  If the user wants to edit the table, I'm using the AJAX Modal Popup extender to present the user a FormView where they can edit data.  It looks great, but when I save/fire the update, it sets the values in my SQL record to null.  Can anyone tell me where I may be going wrong?  Thanks for the help!

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WaterHydrantDashboard.aspx.vb" Inherits="Oconomowoc.WaterHydrantDashboard" %>
<%@ Register TagPrefix="ajax" Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit" %>
<!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>Hydrant Dashboard</title>
	<link type="text/css" href="~/Styles/Site.css" />
</head>
<body style="background-color:#e9eef0">
    <form id="form1" runat="server">
	<ajax:ToolkitScriptManager runat="server" />
	
	<asp:SqlDataSource ID="SqlDataSource2" runat="server" 
		ConnectionString="<%$ ConnectionStrings:OconGISConnectionString %>" 
		DeleteCommand="DELETE FROM [WaterHydrants_Inspection_backup] WHERE [InspectionID] = @InspectionID" 
		InsertCommand="INSERT INTO [WaterHydrants_Inspection_backup] ([HydNo], [InspectedBy], [InspectedBy2], [InspectionDate], [Packing], [DrainRod], [BelowGrade], [Broken], [Paint], [Stiff], [CapsMissing], [CapsStuck], [Stem], [Flagging], [Flushed], [InspectionComments], [EditDate], [UserID], [IsLocked]) VALUES (@HydNo, @InspectedBy, @InspectedBy2, @InspectionDate, @Packing, @DrainRod, @BelowGrade, @Broken, @Paint, @Stiff, @CapsMissing, @CapsStuck, @Stem, @Flagging, @Flushed, @InspectionComments, @EditDate, @UserID, @IsLocked)" 
		SelectCommand="SELECT * FROM [WaterHydrants_Inspection_backup] WHERE ([InspectionID] = @InspectionID)" 
		UpdateCommand="UPDATE [WaterHydrants_Inspection_backup] SET [InspectedBy] = @InspectedBy, [InspectedBy2] = @InspectedBy2, [InspectionDate] = @InspectionDate, [Packing] = @Packing, [DrainRod] = @DrainRod, [BelowGrade] = @BelowGrade, [Broken] = @Broken, [Paint] = @Paint, [Stiff] = @Stiff, [CapsMissing] = @CapsMissing, [CapsStuck] = @CapsStuck, [Stem] = @Stem, [Flagging] = @Flagging, [Flushed] = @Flushed, [InspectionComments] = @InspectionComments, [EditDate] = @EditDate, [UserID] = @UserID, [IsLocked] = @IsLocked WHERE [InspectionID] = @InspectionID">
		<DeleteParameters>
			<asp:Parameter Name="InspectionID" Type="Int32" />
		</DeleteParameters>
		<InsertParameters>
			<asp:Parameter Name="HydNo" Type="Int32" />
			<asp:Parameter Name="InspectedBy" Type="String" />
			<asp:Parameter Name="InspectedBy2" Type="String" />
			<asp:Parameter DbType="Date" Name="InspectionDate" />
			<asp:Parameter Name="Packing" Type="Boolean" />
			<asp:Parameter Name="DrainRod" Type="Boolean" />
			<asp:Parameter Name="BelowGrade" Type="Boolean" />
			<asp:Parameter Name="Broken" Type="Boolean" />
			<asp:Parameter Name="Paint" Type="Boolean" />
			<asp:Parameter Name="Stiff" Type="Boolean" />
			<asp:Parameter Name="CapsMissing" Type="Boolean" />
			<asp:Parameter Name="CapsStuck" Type="Boolean" />
			<asp:Parameter Name="Stem" Type="Boolean" />
			<asp:Parameter Name="Flagging" Type="Boolean" />
			<asp:Parameter Name="Flushed" Type="Boolean" />
			<asp:Parameter Name="InspectionComments" Type="String" />
			<asp:Parameter Name="EditDate" Type="DateTime" />
			<asp:Parameter Name="UserID" Type="String" />
			<asp:Parameter Name="IsLocked" Type="Boolean" />
		</InsertParameters>
		<SelectParameters>
			<asp:ControlParameter ControlID="GridView1" Name="InspectionID" 
				PropertyName="SelectedValue" Type="Int32" />
		</SelectParameters>
		<UpdateParameters>
			<asp:Parameter Name="HydNo" Type="Int32" />
			<asp:Parameter Name="InspectedBy" Type="String" />
			<asp:Parameter Name="InspectedBy2" Type="String" />
			<asp:Parameter DbType="Date" Name="InspectionDate" />
			<asp:Parameter Name="Packing" Type="Boolean" />
			<asp:Parameter Name="DrainRod" Type="Boolean" />
			<asp:Parameter Name="BelowGrade" Type="Boolean" />
			<asp:Parameter Name="Broken" Type="Boolean" />
			<asp:Parameter Name="Paint" Type="Boolean" />
			<asp:Parameter Name="Stiff" Type="Boolean" />
			<asp:Parameter Name="CapsMissing" Type="Boolean" />
			<asp:Parameter Name="CapsStuck" Type="Boolean" />
			<asp:Parameter Name="Stem" Type="Boolean" />
			<asp:Parameter Name="Flagging" Type="Boolean" />
			<asp:Parameter Name="Flushed" Type="Boolean" />
			<asp:Parameter Name="InspectionComments" Type="String" />
			<asp:Parameter Name="EditDate" Type="DateTime" />
			<asp:Parameter Name="UserID" Type="String" />
			<asp:Parameter Name="IsLocked" Type="Boolean" />
			<asp:Parameter Name="InspectionID" Type="Int32" />
		</UpdateParameters>
	</asp:SqlDataSource>
	<asp:SqlDataSource ID="SqlDataSource1" runat="server" ...>

	</asp:SqlDataSource>	 
	
	<asp:SqlDataSource ID="InspectorNames" runat="server" 
		ConnectionString="<%$ ConnectionStrings:OconGISConnectionString %>" 
		SelectCommand="SELECT [Inspector] FROM [lu_Water_Inspectors] ORDER BY [ID]">
	</asp:SqlDataSource>
	
	<h2>Inspections</h2>
    <div>
	<asp:UpdatePanel ID="upInspections" runat="server" UpdateMode="Conditional">
		<ContentTemplate>
		<asp:GridView ID="GridView1" runat="server"  DataSourceID="SqlDataSource1" AllowPaging="True" AllowSorting="True" 
		 AutoGenerateColumns="False" DataKeyNames="InspectionID" OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
		 HeaderStyle-Font-Names="Verdana" HeaderStyle-Font-Size="Small" HeaderStyle-BackColor="#F5F5DC"  CellPadding="6"
		 BackColor="White" ForeColor="Black" Font-Names="Verdana" Font-Size="X-Small" >
			<Columns>
				<asp:TemplateField>
					<ItemTemplate>
						<asp:LinkButton ID="gvInspection_Edit" runat="server" Text="Edit" CommandName="Select" />
						<asp:LinkButton ID="gvInspection_Delete" runat="server" Text="Delete" CommandName="Delete" />
					</ItemTemplate>
				</asp:TemplateField>
				<asp:BoundField DataField="InspectionID" HeaderText="ID" 
					InsertVisible="False" ReadOnly="True" SortExpression="InspectionID" />
				<asp:BoundField DataField="HydNo" HeaderText="Hyd #" SortExpression="HydNo" />
				<asp:BoundField DataField="InspectedBy" HeaderText="Inspector" SortExpression="InspectedBy" />
				<asp:BoundField DataField="InspectedBy2" HeaderText="Inspector 2" SortExpression="InspectedBy2" />
				<asp:BoundField DataField="InspectionDate" HeaderText="Date" SortExpression="InspectionDate" DataFormatString="{0:d}" HtmlEncode="false"/>
				<asp:CheckBoxField DataField="Packing" HeaderText="Packing" SortExpression="Packing"   />
				<asp:CheckBoxField DataField="DrainRod" HeaderText="Drain Rod" SortExpression="DrainRod" />
				<asp:CheckBoxField DataField="BelowGrade" HeaderText="Below Grade" SortExpression="BelowGrade" />
				<asp:CheckBoxField DataField="Broken" HeaderText="Broken" SortExpression="Broken" />
				<asp:CheckBoxField DataField="Paint" HeaderText="Paint" SortExpression="Paint" />
				<asp:CheckBoxField DataField="Stiff" HeaderText="Stiff" SortExpression="Stiff" />
				<asp:CheckBoxField DataField="CapsMissing" HeaderText="Caps Missing" SortExpression="CapsMissing" />
				<asp:CheckBoxField DataField="CapsStuck" HeaderText="Caps Stuck" SortExpression="CapsStuck" />
				<asp:CheckBoxField DataField="Stem" HeaderText="Stem" SortExpression="Stem" />
				<asp:CheckBoxField DataField="Flagging" HeaderText="Flagging" SortExpression="Flagging" />
				<asp:CheckBoxField DataField="Flushed" HeaderText="Flushed" SortExpression="Flushed"  />
				<asp:BoundField DataField="InspectionComments" HeaderText="Comments" SortExpression="InspectionComments" />
			</Columns>

			<HeaderStyle BackColor="Beige" Font-Names="Verdana" Font-Size="X-Small"></HeaderStyle>
		</asp:GridView>
		</ContentTemplate>
	</asp:UpdatePanel>


		<asp:Panel ID="pnlPopup" runat="server" style=" background-color:White">
			<asp:UpdatePanel ID="udpInspectionDetail" runat="server" UpdateMode="Conditional">
				<ContentTemplate>
					<asp:Button ID="btnShowPopup" runat="server" style="display:none;" />
					<ajax:ModalPopupExtender ID="mdlPopup" runat="server" TargetControlID="btnShowPopup"
						PopupControlID="pnlPopup" CancelControlID="btnClose" />
						
						<asp:FormView ID="fvInspection" runat="server" Visible="true" DataKeyNames="InspectionID" 
						DataSourceID="SqlDataSource2" DefaultMode="Edit">
							<EditItemTemplate>
								<table>
									<tr>
										<td>Hydrant:</td>
										<td><asp:Label ID="lblHydrant" runat="server" Text='<%# Eval("HydNo") %>' /></td>
										<td>Inspector:</td>
										<td>
											<asp:DropDownList ID="ddlInspector" runat="server" DataSourceID="InspectorNames" DataTextField="Inspector"
											DataValueField="Inspector" SelectedValue='<%# Eval("InspectedBy") %>' />
										</td>
										<td>Inspector 2:</td>
										<td>
											<asp:DropDownList ID="ddlInspector2" runat="server" DataSourceID="InspectorNames" DataTextField="Inspector"
											DataValueField="Inspector" SelectedValue='<%# Eval("InspectedBy2") %>' />
										</td>
									</tr>
									<tr>
										<td>Date:</td>
										<td><asp:TextBox ID="tbDate" runat="server" Text='<%# Eval("InspectionDate") %>' /> </td>
										<td>Packing:</td>
										<td><asp:CheckBox ID="chkPacking" runat="server" Checked='<%# Eval("Packing") %>' /></td>
										<td>Drain Rod:</td>
										<td><asp:CheckBox ID="chkDrainRod" runat="server" Checked='<%# Eval("DrainRod") %>' /></td>
									</tr>
									<tr>
										<td>Below Grade:</td>
										<td><asp:CheckBox ID="chkBG" runat="server" Checked='<%# Eval("BelowGrade") %>' /></td>
										<td>Broken:</td>
										<td><asp:CheckBox ID="chkBroken" runat="server" Checked='<%# Eval("Broken") %>' /></td>
										<td>Paint:</td>
										<td><asp:CheckBox ID="chkPaint" runat="server" Checked='<%# Eval("Paint") %>' /></td>
									</tr>
									<tr>
										<td>Stiff:</td>
										<td><asp:CheckBox ID="chkStiff" runat="server" Checked='<%# Eval("Stiff") %>' /></td>
										<td>Caps Missing:</td>
										<td><asp:CheckBox ID="chkMissing" runat="server" Checked='<%# Eval("CapsMissing") %>' /></td>
										<td>Caps Stuck:</td>
										<td><asp:CheckBox ID="chkStuck" runat="server" Checked='<%# Eval("CapsStuck") %>' /></td>
									</tr>
									<tr>
										<td>Stem:</td>
										<td><asp:CheckBox ID="chkStem" runat="server" Checked='<%# Eval("Stem") %>' /></td>
										<td>Flagging:</td>
										<td><asp:CheckBox ID="chkFlagging" runat="server" Checked='<%# Eval("Flagging") %>' /></td>
										<td>Flushed:</td>
										<td><asp:CheckBox ID="chkFlushed" runat="server" Checked='<%# Eval("Flushed") %>' /></td>
									</tr>
									<tr>
										<td>Comments</td>
										<td colspan="5"><asp:TextBox ID="tbComments" runat="server" Text='<%# Eval("InspectionComments") %>' /></td>
									</tr>

								</table>
							
							</EditItemTemplate>

						</asp:FormView>

						<div>
							<asp:LinkButton ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" CausesValidation="true"  />
							<asp:LinkButton ID="btnClose" runat="server" Text="Cancel" CausesValidation="false" />
						</div>

				</ContentTemplate>
			</asp:UpdatePanel>
		</asp:Panel>
    </div>
    </form>
</body>
</html>

Open in new window


And code behind:
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

	'Protected Function ChooseImage(ByVal value As Boolean) As String
	'	If value = True Then
	'		Return "~/images/icon_checkbox_1.gif"
	'	 Else
	'		Return "~/images/icon_checkbox_0.png"
	'	End If
	'End Function

	Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles GridView1.SelectedIndexChanged
		fvInspection.Visible = True
		fvInspection.DataBind()
		udpInspectionDetail.Update()
		mdlPopup.Show()
	End Sub

	Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnClose.Click
		If Page.IsValid Then
			'move data back to the object
			fvInspection.UpdateItem(False)
			fvInspection.Visible = False

			'hide popup
			mdlPopup.Hide()

			'refresh
			GridView1.DataBind()
			udpInspectionDetail.Update()
			upInspections.Update()
		End If
	End Sub
End Class

Open in new window

0
Comment
Question by:esri_koolaid
  • 3
  • 2
5 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38294065
Where are you setting the values for Insert/Update parameters?
0
 

Author Comment

by:esri_koolaid
ID: 38294177
I'm a newbie here (as you'll soon see) so be gentle.  I have a data source hooked up with insert and update commands. Do I need set these parameters from code behind here?
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 1500 total points
ID: 38294226
You can set values in code behind or you can use control parameters

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.controlparameter.aspx
0
 

Author Comment

by:esri_koolaid
ID: 38296496
It was a simple mistake- I was using Eval instead of Bind in the Edit Template. Once I changed that it works perfectly.  http://forums.asp.net/t/1097781.aspx/1
0
 

Author Closing Comment

by:esri_koolaid
ID: 38296535
I found the actual solution to my own problem, but the comments did eventually lead me there.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
There is a wide range of advantages associated with the use of ASP.NET. This is why this programming framework is used to create excellent enterprise-class websites, technologies, and web applications.
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
There may be issues when you are trying to access Outlook or send & receive emails or due to Outlook crash which leads to corrupt or damaged PST file. To eliminate the corruption from your PST file, you need to repair the corrupt Outlook PST file. U…
Suggested Courses

612 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question