iSeller Commerce
iSeller POS Retail
iSeller POS F&B
iSeller POS Express
Crosslight
WebUI
ClientUI
What's New
Download Trial
Web Solution
Mobile Solution
Enterprise Solution
Custom Development
Blog
Community
Latest Development Blogs
ForumPostTopic
Browse By Tag
Hi,
We have a grid that is not behaving as it should. We are doing similar or the same things on grids in other places in our system, but this one is not working.
We do not bind this to a SQL or object, but we add the data dynamically. So when we are done (when a user hits the update button), we call an UpdateInfo method to add the new data typed in.
however, this doesnt work, as when we reference cells that show in the grid, they have no entries on the server side.
I have enclosed the code, and its below too.
using System; using System.Data; using System.Configuration; using System.Collections; using System.Data.SqlClient; using System.Web.UI.WebControls; using ISNet.WebUI.WebGrid; using System.Net; using Microsoft.ApplicationBlocks.Data; using ExtendASP.EPS.Framework.EntitiesFramework; public partial class PlanLanguage : System.Web.UI.UserControl { private SupportedLanguages theLanguages = SupportedLanguages.GetSupportedLanguages(); private static string connectionString = ConfigurationManager.ConnectionStrings["HostingConnectionString"].ConnectionString; protected void Page_Load(object sender, EventArgs e) { if (SessionSettings.UserRoles[SessionSettings.LoggedInUser.UserRoleKey].AccessLevel < (int)EPSConstants.UserLevels.HostingAdmin) Response.Redirect("Admin.aspx", false); if (!IsPostBack) { this.lblPlanLanguageInfo.Text = Resources.AdminText.MSG_PlanLanguageInfo; WebGrid2.LoadLayoutFromFile(Server.MapPath("~/App_Themes/" + this.Page.Theme + "/GridLayout.isl")); } } private DataSet LoadData(bool postback) { System.Data.DataSet theDS = null; if (!postback && (WebGrid2.GetTableByName("PlanLanguage") == null)) { theDS = new DataSet(); theDS.Tables.Add("PlanLanguage"); theDS.Tables[0].Columns.Add("Language", typeof(string)); theDS.Tables[0].Columns.Add("PlanName", typeof(string)); theDS.Tables[0].Columns.Add("PlanDescription", typeof(string)); } return theDS; } protected void WebGrid2_PrepareDataBinding(object sender, ISNet.WebUI.WebGrid.DataSourceEventArgs e) { if (!IsPostBack) { WebGrid2.RetrieveStructure(); WebGridTable theTable = WebGrid2.GetTableByName("PlanLanguage"); if (theTable != null) { theTable.Columns[0].EditType = EditType.NoEdit; theTable.Columns[0].Caption = Resources.AdminText.MSG_Language; theTable.Columns[1].Caption = Resources.AdminText.MSG_PlanName; theTable.Columns[2].Caption = Resources.AdminText.MSG_PlanDescription; } } } protected void WebGrid2_InitializeDataSource(object sender, ISNet.WebUI.WebGrid.DataSourceEventArgs e) { //e.DataSource = LoadData(IsPostBack); } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // base.OnInit(e); InitializeComponent(); } /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.WebGrid2.InitializeDataSource += new ISNet.WebUI.WebGrid.DataSourceEventHandler(this.WebGrid2_InitializeDataSource); this.WebGrid2.PrepareDataBinding += new ISNet.WebUI.WebGrid.DataSourceEventHandler(this.WebGrid2_PrepareDataBinding); this.WebGrid2.InitializeRow += new ISNet.WebUI.WebGrid.RowEventHandler(this.WebGrid2_InitializeRow); this.Load += new System.EventHandler(this.Page_Load); } #endregion public void SetInfo(ServicePlan thePlan) { System.Data.DataSet theDS = LoadData(false); if (WebGrid2.GetTableByName("PlanLanguage") == null) { EntityLanguageTranslations theTranslations = thePlan.GetLanguageTranslations(); SupportedLanguages theLanguages = SupportedLanguages.GetSupportedLanguages(); foreach (SupportedLanguage theLanguage in theLanguages) { if (theLanguage.UseInSystem) { if (theTranslations[theLanguage.CultureCode] != null) theDS.Tables[0].Rows.Add(theLanguage.CultureCode, theTranslations[theLanguage.CultureCode].DisplayName, theTranslations[theLanguage.CultureCode].Description); else theDS.Tables[0].Rows.Add(theLanguage.CultureCode, string.Empty, string.Empty); } } theDS.AcceptChanges(); WebGrid2.ClearCachedDataSource(); WebGrid2.RebindDataSource(); WebGrid2.DataSource = theDS; WebGrid2.DataBind(); } } public void UpdateInfo(ServicePlan thePlan) { EntityLanguageTranslations theTranslations = thePlan.GetLanguageTranslations(); for (int i = 0; i < WebGrid2.RootTable.Rows.Count; i++) { string theCulture = WebGrid2.RootTable.Rows[i].Cells[0].ToString(); string theDisplayName = WebGrid2.RootTable.Rows[i].Cells[1].Value.ToString(); string theDescription = WebGrid2.RootTable.Rows[i].Cells[2].Value.ToString(); if (theTranslations[theCulture] != null) { EntityLanguageTranslation theTranslation = theTranslations[theCulture]; theTranslation.DisplayName = theDisplayName; theTranslation.Description = theDescription; theTranslation.Update(); } else { EntityLanguageTranslation theTranslation = EntityLanguageTranslation.CreateTranslation(thePlan.EntityId, theCulture, theDisplayName, theDescription); } } } protected void WebGrid2_InitializeRow(object sender, ISNet.WebUI.WebGrid.RowEventArgs e) { if (e.Row.Type == RowType.Record) { try { string theLanguage = e.Row.Cells.GetNamedItem("Language").Text; string theTranslation = Resources.LocalizedText.ResourceManager.GetString(theLanguages[theLanguage].LanguageName, System.Threading.Thread.CurrentThread.CurrentCulture); e.Row.Cells.GetNamedItem("Language").Text = theTranslation; } catch { } } } }
Do you mind providing a simple runnable sample of the scenario? That way I could see the application flow and debug the process to analyse the issue further.
<ISWebGrid:WebGrid ID="WebGrid1" DataCacheStorage="PageCache" DefaultStyleMode="Win7" runat="server" Height="148px" UseDefaultStyle="True" Width="329px" oninitializedatasource="WebGrid1_InitializeDataSource" onpreparedatabinding="WebGrid1_PrepareDataBinding" onaddrow="WebGrid1_AddRow" ondeleterow="WebGrid1_DeleteRow" onupdaterow="WebGrid1_UpdateRow" oninitializepostback="WebGrid1_InitializePostBack" > <LayoutSettings NewRowLostFocusAction="AlwaysUpdate" AllowEdit="Yes" AllowDelete="Yes" PagingMode="VirtualLoad" VirtualPageSize="13"> <ClientSideEvents OnEditKeyDown="WebGrid1_OnEditKeyDown" /> </LayoutSettings> </ISWebGrid:WebGrid>
public partial class insertRowToSql : System.Web.UI.Page{ string sqlcon = System.Configuration.ConfigurationManager.ConnectionStrings["loginConnectionString2"].ToString(); SqlConnection conn; SqlDataAdapter da; DataSet sqlds; SqlCommandBuilder builder; protected void Page_Load(object sender, EventArgs e) { Cache["temp"] = "false"; conn= new SqlConnection(sqlcon); da = new SqlDataAdapter("SELECT id ,name ,pwd FROM logintbl;", conn); builder= new SqlCommandBuilder(da); }protected void WebGrid1_PrepareDataBinding(object sender, ISNet.WebUI.WebGrid. DataSourceEventArgs e) { WebGrid1.RootTable.DataKeyField = "id"; //set primary key WebGrid1.RetrieveStructure(); WebGrid1.RootTable.DataKeyField = "id"; } //insert protected void WebGrid1_AddRow(object sender, RowEventArgs e){DataSet ds = (DataSet)WebGrid1.DataSource; da.InsertCommand = builder.GetInsertCommand(); da.Update(ds); e.ReturnValue = false; WebGrid1.ClientAction.Refresh(); } //update protected void WebGrid1_UpdateRow(object sender, RowEventArgs e) { DataSet dt = (DataSet)WebGrid1.GetCachedDataSource(); DataSet changeDT = (DataSet)dt.GetChanges(); da.UpdateCommand = builder.GetUpdateCommand(); da.Update(changeDT); e.ReturnValue = false; } //deleteprotected void WebGrid1_DeleteRow(object sender, RowEventArgs e) { DataSet ds = (DataSet)WebGrid1.DataSource; da.DeleteCommand = builder.GetDeleteCommand(); ((DataRowView)e.Row.DataRow).Row.Delete(); da.Update(ds); e.ReturnValue = false; WebGrid1.ClientAction.Refresh(); }
or
Choose this if you're already a member of Intersoft Community Forum. You can link your OpenID account to your existing Intersoft Social ID.
Choose this if you don't have an Intersoft account yet. Your authenticated OpenID will be automatically linked to your new Intersoft account.
Enter your Wordpress Blogname