Issue referencing data on update

3 replies. Last post: November 11, 2010 12:29 AM by Frank Bruce
Tags :
  • (None)
  • New Discussion
  • New Question
  • New Product Feedback
Eric HanigMember

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.

<ISWebGrid:WebGrid id="WebGrid2" runat="server" Width="880px" HorizontalAlign="NotSet" ViewStateItems="All" UseDefaultStyle="false" > <LayoutSettings InProgressUIBehavior="ChangeCursorToHourGlass" HeaderClickAction="SortMulti" AlwaysShowHelpButton="False" NewRowLostFocusAction="AlwaysUpdate" TreeLines="False" AllowSorting="Yes" RowHeightDefault="20px" RowLostFocusAction="AlwaysUpdate" GridLines="Vertical" HideColumnsWhenGrouped="No" CellPaddingDefault="2" AutoFitColumns="True" EditOnClick="true" AlternatingColors="True" VirtualLoadMode="LargeData" GridLineStyle="Solid" PagingMode="VirtualLoad" GridLineColor="221, 236, 254" AllowEdit="Yes" AllowAddNew="No" AllowDelete="No"> </LayoutSettings> <RootTable GridLineStyle="NotSet"> </RootTable> </ISWebGrid:WebGrid>

 

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 { }
        }
    }

}
All times are GMT -5. The time now is 4:42 AM.
Previous Next