Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm working on a dynamic data website with linqtosql dbml file. Could anyone please help in giving some examples on how to update records displayed in a formview that allows paging? The formview exists in the "Edit.aspx" page with DefaultMode="Edit" and DataSourceID="DetailsDataSource" where "DetailsDataSource" is a LinqDataSource with EnableUpdate="true". The bottomrow of the formview contains a LinkButton with CommandName="Update" to perform the update operation. Once I change some info in the bounddatafieds and then click on the linkbutton, the formview loads with empty datafields and no updates are saved to the database.

Any help will be much appreciated.

Thank you.
Posted
Comments
TryAndSucceed 5-Sep-13 17:27pm    
Some code sharing would be appreciated.
marounmm 5-Sep-13 17:49pm    
Edit.aspx File:
-----------------
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<contenttemplate>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" EnableClientScript="true"
HeaderText="<%$ Resources:globalresources, validationerrors %>" CssClass="DDValidator" />
<asp:DynamicValidator runat="server" ID="DetailsViewValidator" ControlToValidate="FormView1"
Display="None" CssClass="DDValidator" />
<asp:FormView runat="server" ID="FormView1" DataSourceID="DetailsDataSource" DefaultMode="Edit"
OnItemUpdated="FormView1_ItemUpdated" OnPreRender="FormView1_PreRender"
RenderOuterTable="false" AllowPaging="true">
<edititemtemplate>
<table>
<asp:DynamicEntity runat="server" Mode="Edit" />
<tr class="td">
<td colspan="8" style="border-top: 1px solid #ffffff">
<asp:LinkButton ID="submitButton" runat="server" CommandName="Update"
Text="Update" />
</td>
</tr>
</table>


<asp:LinqDataSource ID="DetailsDataSource" runat="server" EnableUpdate="true">




CodeBehind (Edit.aspx.cs):
--------------------------

public partial class Edit : Page
{
protected MetaTable table;

protected override void OnInit(EventArgs e)
{
base.OnInit(e);
table = DynamicDataRouteHandler.GetRequestMetaTable(Context);
FormView1.SetMetaTable(table);
DetailsDataSource.EntityTypeName = table.EntityType.AssemblyQualifiedName;
}

protected void FormView1_PreRender(object sender, EventArgs e)
{
if (!IsPostBack && Request.QueryString.Count > 0 && Request.QueryString["itidx"] != null)
{
int idx = Convert.ToInt32(Request.QueryString["itidx"]);
if (idx != FormView1.PageIndex) FormView1.PageIndex = idx;
}
}

protected void FormView1_ItemUpdated(object sender, FormViewUpdatedEventArgs e)
{
e.KeepInEditMode = true;
}
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900