Post back edit data from a SuperForm to a GridView

gabpakhyday

New Member
I have an Obout SuperForm nested inside of an Obout GridView, and I'm trying to have insert/edit data posted back to the GridView, but I can't get this to work . I have a DAL with repository methods which perform insert/delete/update/select functions of the database (I am using entites), and then a code behind file for the web page which gets individual Records from GridRecordEventArgs, creates the necessary entity object with them, and then passes that object to the desired method in the repository class. Main page:\[code\]<asp:ObjectDataSource ID="AwardsObjectDataSource" runat="server" TypeName="OboutTest.DAL.AwardRepository" DataObjectTypeName="OboutTest.DAL.tblAward" SelectMethod="GetAwards" UpdateMethod="AddAward" DeleteMethod="DeleteAward" InsertMethod="AddAward"></asp:ObjectDataSource><obout:Grid ID="AwardsOboutGrid" runat="server" Serialize="true" AutoGenerateColumns="false" OnInsertCommand="InsertRecordGrid" OnDeleteCommand="DeleteRecordGrid" OnUpdateCommand="UpdateRecordGrid" PageSize="50" AutoGenerateRows="false" AutoGenerateEditButton="false" AutoGenerateDeleteButton="true" OnCallBack="true" DataSourceID="AwardsObjectDataSource" > <Columns> <obout:Column AllowEdit="true" AllowDelete="true" HeaderText="Edit" Width="100"/> <obout:Column ID="ID" DataField="ID" ReadOnly="true" Visible="false" runat="server"> <TemplateSettings RowEditTemplateControlID="ID" RowEditTemplateControlPropertyName="value" /> </obout:Column> <obout:Column ID="OrgName" DataField="OrgName" HeaderText="Organization Name" Width="250" runat="server"> <TemplateSettings RowEditTemplateControlId="SuperForm_OrgName" RowEditTemplateControlPropertyName="value" /> </obout:Column> <obout:Column ID="AwardName" DataField="AwardName" HeaderText="Award" runat="server"> <TemplateSettings RowEditTemplateControlId="SuperForm_AwardName" RowEditTemplateControlPropertyName="value" /> </obout:Column> <obout:Column ID="Date" DataField="Date" HeaderText="Date Due" HtmlEncodeFormatString="True" HtmlEncode="True" runat="server"> <TemplateSettings RowEditTemplateControlId="SuperForm_Date" RowEditTemplateControlPropertyName="value" /> </obout:Column> <obout:Column ID="Link" DataField="Link" HeaderText="Link" Width="222" runat="server"> <TemplateSettings RowEditTemplateControlId="SuperForm_Link" RowEditTemplateControlPropertyName="value" /> </obout:Column> </Columns> <TemplateSettings RowEditTemplateId="AwardsTplRowEdit" /> <Templates> <obout:GridTemplate runat="server" ID="AwardsTplRowEdit"> <Template> <input type="hidden" id="ID" /> <obout:SuperForm ID="AwardsSuperForm" runat="server" DataSourceID="AwardsObjectDataSource" AutoGenerateRows="false" AutoGenerateInsertButton="True" AutoGenerateEditButton="True" AutoGenerateDeleteButton="false" DataKeyNames="ID" DefaultMode="Edit" Width="99%"> <Fields> <obout:BoundField DataField="OrgName" HeaderText="Organization Name" FieldSetID="FieldSet1" /> <obout:BoundField DataField="AwardName" HeaderText="Award Name" FieldSetID="FieldSet1" /> <obout:DateField DataField="Date" HeaderText="Date Due" FieldSetID="FieldSet2" DataFormatString="{0:MM/dd/yyyy}" ApplyFormatInEditMode="true"/> <obout:BoundField DataField="Link" HeaderText="Link" FieldSetID="FieldSet2" /> </Fields> <FieldSets> <obout:FieldSetRow> <obout:FieldSet ID="FieldSet1" Title="Award Information" /> <obout:FieldSet ID="FieldSet2" Title="Date Information" /> </obout:FieldSetRow> <obout:FieldSetRow> <obout:FieldSet ID="FieldSet3" ColumnSpan="3" /> </obout:FieldSetRow> </FieldSets> </obout:SuperForm> </Template> </obout:GridTemplate> </Templates></obout:Grid>\[/code\]Code behind:\[code\]using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Data;using System.Data.Objects;using System.Data.OleDb;using OboutTest.DAL;using Obout.Grid;using Obout.SuperForm;using Obout.Interface;namespace OboutTest{ public partial class Awards : System.Web.UI.Page { private AwardEntities context = new AwardEntities(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //CreateGrid(); } } // Here we just create a bare-bones tblAward object to pass to // our code respository protected tblAward createAwardObj(string orgName, string awardName, DateTime date, string link) { tblAward a = new tblAward(); a.OrgName = orgName; a.AwardName = awardName; a.Date = date; a.Link = link; return a; } protected tblAward createAwardObj(string orgName, string awardName, DateTime date, string link, Int32 id) { tblAward a = new tblAward(); a.OrgName = orgName; a.AwardName = awardName; a.Date = date; a.Link = link; a.ID = id; return a; } protected void InsertRecordGrid(object sender, GridRecordEventArgs e) { AwardRepository obj = new AwardRepository(); // We simply call InsertAward from the Repository class and pass is createAwardObj from this // class obj.AddAward(createAwardObj(e.Record["OrgName"].ToString(), e.Record["AwardName"].ToString(), Convert.ToDateTime(e.Record["Date"]), e.Record["Link"].ToString())); } protected void DeleteRecordGrid(object sender, GridRecordEventArgs e) { AwardRepository obj = new AwardRepository(); // Same obj.DeleteAward(createAwardObj(e.Record["OrgName"].ToString(), e.Record["AwardName"].ToString(), Convert.ToDateTime(e.Record["Date"]), e.Record["Link"].ToString(), Convert.ToInt32(e.Record["ID"]))); } protected void UpdateRecordGrid(object sender, GridRecordEventArgs e) { AwardRepository obj = new AwardRepository(); // Same obj.AddAward(createAwardObj(e.Record["OrgName"].ToString(), e.Record["AwardName"].ToString(), Convert.ToDateTime(e.Record["Date"]), e.Record["Link"].ToString())); //CreateGrid(); } }}\[/code\]Repository:\[code\]using System;using System.Collections.Generic;using System.Linq;using OboutTest.DAL;namespace OboutTest.DAL{ public class AwardRepository : IDisposable { private AwardEntities context = new AwardEntities(); public IEnumerable<tblAward> GetAwards() { return context.tblAwards.ToList(); } private bool disposedValue = http://stackoverflow.com/questions/12716707/false; protected virtual void Dispose(bool Disposing) { if (!this.disposedValue) { if (Disposing) { context.Dispose(); } } this.disposedValue = true; } public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } public void AddAward(tblAward award) { try { context.tblAwards.AddObject(award); context.SaveChanges(); } catch (Exception ex) { throw ex; } } public void DeleteAward(tblAward award) { try { context.tblAwards.Attach(award); context.tblAwards.DeleteObject(award); context.SaveChanges(); } catch (Exception ex) { throw ex; } } }}\[/code\]
 
Back
Top