FormView control wiping data/not updating

J

John Mason

Hi,

I've been trying for most of the day to get a FormView control to work.
I would like to display a single record, based on a unique user id
(loginid), which I am retreiving from a cookie. No paging involved. I
want to give the user the ability to edit their record and update it (no
insert).

I pre-populate the database fields with values, and when I execute the
page, it wipes out the corresponding database field values belonging to
the user with matching loginid (it replaces phone, country, state,
postcode, company, title values with blanks).

If I click the edit button and put values into the fields, then click
update button, this doesn't work either. There are still blanks in the
database fields.

If anyone could please offer a solution I would REALLY appreciate it. I
have looked for hours and cannot see what I am doing wrong.

I'm not using any code in my code behind related to this control. Here
is my code...

<asp:FormView runat="server" ID="FormView1" AllowPaging="false"
DefaultMode="ReadOnly" DataSourceID="SqlDataSource3"
DataKeyNames="LoginID" BorderWidth="0">
<ItemTemplate>
<table runat="server" width="350" border="0"
cellspacing="5"
style="border-top-width: 0px;
border-left-width: 0px; border-bottom-width: 0px; border-collapse:
collapse; border-right-width: 0px; background-color:#F6F6F6"
id="tblFormItem" align="left">
<tr>
<td align="left" colspan="2">
<asp:Label runat="server" CssClass="qtext"
ID="lblfvname" Text='<%# Eval("name") %>' />
<asp:Label runat="server" ID="lblfvlogin"
Text='<%# Eval("LoginID") %>' />
</td>
</tr>
<tr>
<td align="left">
<asp:Label runat="server" CssClass="bodytext"
ID="lblfvco" Text='<%# Eval("company") %>' />
&nbsp;<asp:Label runat="server"
CssClass="bodytext" ID="lblfvtitle" Text='<%# Eval("title") %>' />
</td>
<td align="left">
<asp:Label runat="server" CssClass="bodytext"
ID="lblfvphone" Text='<%# Eval("phone") %>' />
</td>
</tr>
<tr>
<td align="left">
<asp:Label runat="server" CssClass="bodytext"
ID="lblfvstate" Text='<%# Eval("state") %>' />
&nbsp;<asp:Label runat="server"
CssClass="bodytext" ID="lblfvcountry" Text='<%# Eval("country") %>' />
&nbsp;<asp:Label runat="server"
CssClass="bodytext" ID="lblfvpcode" Text='<%# Eval("postcode") %>' />
</td>
<td align="left">
<asp:Label runat="server" CssClass="bodytext"
ID="lblfvemail" Text='<%# Eval("email") %>' />
</td>
</tr>
<tr>
<td align="left">
<asp:ImageButton ImageUrl="~/images/update.jpg"
CommandName="Edit" runat="server" ID="btnFormview1" />
</td>
<td>
&nbsp;
</td>
</tr>
</table>
</ItemTemplate>
<EditItemTemplate>
<table runat="server" width="350" border="0"
cellspacing="5"
style="border-top-width: 0px;
border-left-width: 0px; border-bottom-width: 0px; border-collapse:
collapse; border-right-width: 0px; background-color:#F6F6F6"
id="tblFormEdit" align="left">
<tr>
<td align="left" colspan="2">
<asp:Label runat="server" ID="txtNamefv"
CssClass="qtext" Text='<%# Eval("name") %>' />
<asp:label ID="txtLoginIDfv" runat="server"
Text='<%# Eval("LoginID") %>' />
</td>
</tr>
<tr>
<td align="left">
<asp:textbox runat="server" CssClass="bodytext"
ID="txtCompanyfv" Text='<%# Bind("company") %>' />
&nbsp;<asp:textbox runat="server"
ID="txtTitlefv" CssClass="bodytext" Text='<%# Bind("title") %>' />
</td>
<td align="left">
<asp:textbox runat="server" ID="txtPhonefv"
CssClass="bodytext" Text='<%# Bind("phone") %>' />
</td>
</tr>
<tr>
<td align="left">
<asp:textbox runat="server" ID="txtStatefv"
CssClass="bodytext" Text='<%# Bind("state") %>' />
&nbsp;<asp:textbox runat="server"
ID="txtCountryfv" CssClass="bodytext" Text='<%# Bind("country") %>' />
&nbsp;<asp:textbox runat="server"
ID="txtPostcodefv" CssClass="bodytext" Text='<%# Bind("postcode") %>' />
</td>
<td align="left">
<asp:label runat="server" ID="lblEmailfv"
CssClass="bodytext" Text='<%# Eval("email") %>' />
</td>
</tr>
<tr>
<td align="left">
<asp:ImageButton ImageUrl="~/images/update.jpg"
CausesValidation="false" CommandName="Update" runat="server"
ID="btnFormviewUpdate" />
&nbsp;<asp:ImageButton
ImageUrl="~/images/cancel.jpg" CommandName="Cancel" runat="server"
ID="btnFormviewCancel" />
</td>
<td>
&nbsp;
</td>
</tr>
</table>
</EditItemTemplate>
</asp:FormView>


<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString = "<%$ ConnectionStrings:AdminSqlServer %>"
SelectCommand="SELECT LoginID, Email,[first_name] + ' ' +
[last_name] as
Name,[phone],[country],[state],[postcode],[company],[title] FROM Profile
WHERE LoginID = @LoginID1"
UpdateCommand="UPDATE Profile SET phone = @phone, country =
@country, state = @state, postcode = @postcode, company = @company,
title = @title WHERE LoginID = @LoginID;" >
<SelectParameters>
<asp:ControlParameter ControlID="txtLID" Name="LoginID1"
PropertyName="Text" />
</SelectParameters>
<UpdateParameters>
<asp:parameter Name="phone" Type="String" />
<asp:parameter Name="country" Type="String" />
<asp:parameter Name="state" Type="String" />
<asp:parameter Name="postcode" Type="String" />
<asp:parameter Name="company" Type="String" />
<asp:parameter Name="title" Type="String" />
<asp:ControlParameter ControlID="txtLID" Name="LoginID"
PropertyName="Text" />
</UpdateParameters>
</asp:SqlDataSource>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top