• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 353
  • Last Modified:

asp.net FormView won't update properly?

Attached is my complete code for the page.  When the page loads, it populates the textbox with the correct data.  When you change the textbox to anything, then hit "update" it just reloads the original data.
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="servers-editnotes.aspx.vb" Inherits="MISD.servers_editnotes" %>
 
<!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">
    <asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1" DefaultMode="Edit">
        <EditItemTemplate>
            &nbsp;<asp:TextBox ID="notesTextBox" runat="server" Text='<%# Bind("notes") %>' 
                Height="100%" Width="100%" TextMode="MultiLine" />
            <br />
            <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
                CommandName="Update" Text="Update" />
        </EditItemTemplate>
        <ItemTemplate>
            <asp:Label ID="notesLabel" runat="server" Text='<%# Bind("notes") %>' />
            <br />
        </ItemTemplate>
    </asp:FormView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:PortalProdConnectionString1 %>" 
        SelectCommand="SELECT [notes] FROM [ServerData] WHERE ([ServerName] = @ServerName)" 
        ConflictDetection="CompareAllValues" 
        UpdateCommand="UPDATE [ServerData] SET [notes] = @notes WHERE ([ServerName] = @ServerName)">
        <SelectParameters>
            <asp:QueryStringParameter Name="ServerName" QueryStringField="ServerName" 
                Type="String" />
        </SelectParameters>
        <UpdateParameters>
            <asp:Parameter Name="notes" Type="String" />
            <asp:QueryStringParameter Name="ServerName" QueryStringField="ServerName" 
                Type="String" />
        </UpdateParameters>
    </asp:SqlDataSource>
    </form>
 
</body>
</html>

Open in new window

0
Cerixus
Asked:
Cerixus
  • 4
  • 4
1 Solution
 
GiftsonDJohnCommented:
Hi,

Make sure that you are not rebinding the FormView again during Postback
0
 
CerixusAuthor Commented:
Well... I don't think I am.  That's my entire code, other than the attached Page_Load.  I also verified that the DB is definitely not being updated.
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If (User.IsInRole("InfraPortalAdmin")) Or (User.IsInRole("InfraPortal_InfrastructureEng")) Or (User.IsInRole("InfraPortal_InfrastructureOperations")) Then
            'success
        Else
            Session("Referrer") = Request.Url.ToString()
            Response.Redirect("AccessDenied.aspx", True)
        End If
 
    End Sub

Open in new window

0
 
GiftsonDJohnCommented:
It is okay.

But in the success area are you using

If Not Page.IsPostBack Then
.
.
End If
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
CerixusAuthor Commented:
I'm not sure what you mean by "Success Area"... do you mean FormView1_ItemUpdated?  Either way, I have no code that says anything about postbacks.
0
 
GiftsonDJohnCommented:
Are you doing any

FormView1.DataBind()

anywhere in the Form_Load event?
0
 
CerixusAuthor Commented:
No, I have pretty much posted all the code for this page...
0
 
GiftsonDJohnCommented:
Hi,

Try this.
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:modelConnectionString %>" 
            
            SelectCommand="SELECT [Notes], [ServerName] FROM [ServerData] WHERE ([ServerName] = @ServerName)" 
            UpdateCommand="UPDATE ServerData SET Notes = @Notes WHERE (ServerName = @ServerName)">
            <SelectParameters>
                <asp:QueryStringParameter Name="ServerName" QueryStringField="ServerName" Type="String" />
            </SelectParameters>
            <UpdateParameters>
                <asp:Parameter Name="Notes" />
                <asp:QueryStringParameter Name="ServerName" QueryStringField="ServerName" />
            </UpdateParameters>
        </asp:SqlDataSource>
        <asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1" DefaultMode="Edit"
            DataMember="DefaultView" DataKeyNames="ServerName">
             <EditItemTemplate>
                <asp:TextBox ID="notesTextBox" runat="server" Text='<%# Bind("notes") %>' Height="100%"
                    Width="100%" TextMode="MultiLine" />
                <br />
                <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
                    Text="Update" />
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="notesLabel" runat="server" Text='<%# Eval("notes") %>' />
                <br />
            </ItemTemplate>
        </asp:FormView>

Open in new window

0
 
CerixusAuthor Commented:
Here was the key:



instead of



I'm not sure why the generated code didn't work, but it's working now with the "ControlParameter".
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now