Avatar of M3hcSS
M3hcSS

asked on 

Details view not updating upon "update" click.

I have a DETAILS view that is dependent upon a GRIDVIEW. When the "select" button on the GRIDVIEW is selected the DETAILS view is populated. This part works correctly.

When I click "Edit" inside the DETAILS view the edit text fields and the update button come up correctly. When I change a text field (telephone, for example) and then click update, the database nor the text field is updated.

Argh!! What am I doing wrong?
.NET ProgrammingVisual Basic.NET

Avatar of undefined
Last Comment
M3hcSS
Avatar of 60MXG
60MXG

post your code example

-------- aspx code




---- code behide
using system;
Avatar of RedKelvin
RedKelvin

You may need to rebind again, to force it to update
Avatar of M3hcSS
M3hcSS

ASKER

--I rebinded that datagrid, the details view, and the datasource.
--I've deleted everything in the page, and restarted again (probably means I duplicated the original error).
--There is no error or exception. It simply doesn't update.


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Project_CarPool._Default" Trace="true"%>
 
<!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>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <br />
        <br />
        Add your name and telephone number.<br />
        <br />
        <asp:DropDownList ID="ddlCity" runat="server" DataSourceID="dsCity" DataTextField="City_Name"
            DataValueField="PK_City" AutoPostBack="True">
        </asp:DropDownList><asp:SqlDataSource ID="dsCity" runat="server" ConnectionString="<%$ ConnectionStrings:Project_CarPoolConnectionString %>"
            SelectCommand="SELECT [PK_City], [City_Name] FROM [City]"></asp:SqlDataSource>
        <br />
        &nbsp;<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br />
        <br />
        <br />
        &nbsp;&nbsp;<br />
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
            AutoGenerateColumns="False" DataKeyNames="PK_User,PK_Lot,PK_City,PK_ContactInfo"
            DataSourceID="dsAllPeopleAndLocations">
            <Columns>
                <asp:CommandField ShowSelectButton="True" />
                <asp:BoundField DataField="PK_User" HeaderText="PK_User" ReadOnly="True" SortExpression="PK_User" />
                <asp:BoundField DataField="PK_Lot" HeaderText="PK_Lot" ReadOnly="True" SortExpression="PK_Lot" />
                <asp:BoundField DataField="Lot_Name" HeaderText="Lot_Name" SortExpression="Lot_Name" />
                <asp:BoundField DataField="FK_Lot_City" HeaderText="FK_Lot_City" SortExpression="FK_Lot_City" />
                <asp:BoundField DataField="PK_City" HeaderText="PK_City" ReadOnly="True" SortExpression="PK_City" />
                <asp:BoundField DataField="City_Name" HeaderText="City_Name" SortExpression="City_Name" />
                <asp:BoundField DataField="User_FirstName" HeaderText="User_FirstName" SortExpression="User_FirstName" />
                <asp:BoundField DataField="User_LastName" HeaderText="User_LastName" SortExpression="User_LastName" />
                <asp:BoundField DataField="FK_User_Lot" HeaderText="FK_User_Lot" SortExpression="FK_User_Lot" />
                <asp:BoundField DataField="FK_User_ContactInfo" HeaderText="FK_User_ContactInfo"
                    SortExpression="FK_User_ContactInfo" />
                <asp:BoundField DataField="PK_ContactInfo" HeaderText="PK_ContactInfo" ReadOnly="True"
                    SortExpression="PK_ContactInfo" />
                <asp:BoundField DataField="ContactInfo_Tele" HeaderText="ContactInfo_Tele" SortExpression="ContactInfo_Tele" />
                <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="dsAllPeopleAndLocations" runat="server" ConnectionString="<%$ ConnectionStrings:Project_CarPoolConnectionString %>"
            SelectCommand="select *&#13;&#10;FROM         Lot INNER JOIN&#13;&#10;                      City ON Lot.FK_Lot_City = City.PK_City INNER JOIN&#13;&#10;                      UserS INNER JOIN&#13;&#10;                      ContactInfo ON UserS.FK_User_ContactInfo = ContactInfo.PK_ContactInfo ON Lot.PK_Lot = UserS.FK_User_Lot&#13;&#10;">
        </asp:SqlDataSource>
        <br />
        <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="PK_ContactInfo"
            DataSourceID="dsDetailsOfContactInfo" Height="50px" Width="125px">
            <Fields>
                <asp:BoundField DataField="PK_ContactInfo" HeaderText="PK_ContactInfo" ReadOnly="True"
                    SortExpression="PK_ContactInfo" />
                <asp:BoundField DataField="ContactInfo_Tele" HeaderText="ContactInfo_Tele" SortExpression="ContactInfo_Tele" />
                <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
                <asp:CommandField ShowEditButton="True" />
            </Fields>
        </asp:DetailsView>
        <asp:SqlDataSource ID="dsDetailsOfContactInfo" runat="server" ConflictDetection="CompareAllValues"
            ConnectionString="<%$ ConnectionStrings:Project_CarPoolConnectionString %>" DeleteCommand="DELETE FROM [ContactInfo] WHERE [PK_ContactInfo] = @original_PK_ContactInfo AND [ContactInfo_Tele] = @original_ContactInfo_Tele AND [Email] = @original_Email"
            InsertCommand="INSERT INTO [ContactInfo] ([PK_ContactInfo], [ContactInfo_Tele], [Email]) VALUES (@PK_ContactInfo, @ContactInfo_Tele, @Email)"
            OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM [ContactInfo] WHERE ([PK_ContactInfo] = @PK_ContactInfo)"
            UpdateCommand="UPDATE [ContactInfo] SET [ContactInfo_Tele] = @ContactInfo_Tele, [Email] = @Email WHERE [PK_ContactInfo] = @original_PK_ContactInfo AND [ContactInfo_Tele] = @original_ContactInfo_Tele AND [Email] = @original_Email">
            <SelectParameters>
                <asp:ControlParameter ControlID="GridView1" Name="PK_ContactInfo" PropertyName="SelectedValue"
                    Type="Int32" />
            </SelectParameters>
            <DeleteParameters>
                <asp:Parameter Name="original_PK_ContactInfo" Type="Int32" />
                <asp:Parameter Name="original_ContactInfo_Tele" Type="String" />
                <asp:Parameter Name="original_Email" Type="String" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="ContactInfo_Tele" Type="String" />
                <asp:Parameter Name="Email" Type="String" />
                <asp:Parameter Name="original_PK_ContactInfo" Type="Int32" />
                <asp:Parameter Name="original_ContactInfo_Tele" Type="String" />
                <asp:Parameter Name="original_Email" Type="String" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="PK_ContactInfo" Type="Int32" />
                <asp:Parameter Name="ContactInfo_Tele" Type="String" />
                <asp:Parameter Name="Email" Type="String" />
            </InsertParameters>
        </asp:SqlDataSource>
    </div>
    </form>
</body>
</html>

Open in new window

Avatar of M3hcSS
M3hcSS

ASKER


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
 
namespace Project_CarPool
{
	public partial class _Default : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			Label1.Text = ddlCity.SelectedValue.ToString();
		}
	}
}

Open in new window

Avatar of RedKelvin
RedKelvin

I cannot see your UPDATE button,

For the update to work the button that fires it must have the command name set to update, like so

CommandName="Update"

Is this the case.

Your data on screen will not update if the db is not updated.
Avatar of M3hcSS
M3hcSS

ASKER

The update button is the switch to the "edit" button. When edit is clicked the update button is shown.

Does that mean I have to somehow set the update button inside the source code?
Avatar of RedKelvin
RedKelvin

Is the update button automomagically generated for you, or are you coding it in your aspx page?
Avatar of M3hcSS
M3hcSS

ASKER

It's automatically generated.
ASKER CERTIFIED SOLUTION
Avatar of M3hcSS
M3hcSS

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo