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") %>' />
<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") %>' />
<asp:Label runat="server"
CssClass="bodytext" ID="lblfvcountry" Text='<%# Eval("country") %>' />
<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>
</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") %>' />
<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") %>' />
<asp:textbox runat="server"
ID="txtCountryfv" CssClass="bodytext" Text='<%# Bind("country") %>' />
<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" />
<asp:ImageButton
ImageUrl="~/images/cancel.jpg" CommandName="Cancel" runat="server"
ID="btnFormviewCancel" />
</td>
<td>
</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>
<asparameter Name="phone" Type="String" />
<asparameter Name="country" Type="String" />
<asparameter Name="state" Type="String" />
<asparameter Name="postcode" Type="String" />
<asparameter Name="company" Type="String" />
<asparameter Name="title" Type="String" />
<asp:ControlParameter ControlID="txtLID" Name="LoginID"
PropertyName="Text" />
</UpdateParameters>
</asp:SqlDataSource>
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") %>' />
<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") %>' />
<asp:Label runat="server"
CssClass="bodytext" ID="lblfvcountry" Text='<%# Eval("country") %>' />
<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>
</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") %>' />
<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") %>' />
<asp:textbox runat="server"
ID="txtCountryfv" CssClass="bodytext" Text='<%# Bind("country") %>' />
<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" />
<asp:ImageButton
ImageUrl="~/images/cancel.jpg" CommandName="Cancel" runat="server"
ID="btnFormviewCancel" />
</td>
<td>
</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>
<asparameter Name="phone" Type="String" />
<asparameter Name="country" Type="String" />
<asparameter Name="state" Type="String" />
<asparameter Name="postcode" Type="String" />
<asparameter Name="company" Type="String" />
<asparameter Name="title" Type="String" />
<asp:ControlParameter ControlID="txtLID" Name="LoginID"
PropertyName="Text" />
</UpdateParameters>
</asp:SqlDataSource>