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 ,
I meet a problem When I use BatchUpdate method . Before I use this method , my webgrid display normal . But After my program execute the BatchUpdate method , the columns of webgrid are huddled , like the pictures in the attchment file .
The following code is the key code of my foreground program .
<ISWebGrid:WebGrid ID="WG1" runat="server" UseDefaultStyle="True" DefaultStyleMode="Win7" Height="100%" OnInitializeDataSource="WG1_InitializeDataSource" OnBatchUpdate="WG1_BatchUpdate" OnInitializeRow="WG1_InitializeRow"> <RootTable GridLineStyle="NotSet" DataKeyField="ModuleGuid"> <Columns> </Columns> </RootTable> <LayoutSettings AllowSorting="Yes" AllowSelectColumns="Yes" AlwaysShowHelpButton="false" AllowEdit="Yes" AllowMultipleSelection="No" AllowColumnFreezing="No" StatusBarVisible="true" AllowBatchUpdate="true" AutoHeight="true" AutoWidth="false" AutoFitColumns="true" AllowGrouping="No" PagingMode="ClassicPaging" PagingLoadMode="Automatic" PagingSize="50"> <ClientSideEvents OnAfterInitialize="WG1_OnAfterInitialize" OnRowContextMenu="WG1_OnRowContextMenu" OnEnterEditMode="WG1_OnEnterEditMode" OnAfterExitEditMode="WG1_OnAfterExitEditMode" /> <TextSettings Language="UseCustom" UseLanguage="zh-CN"> </TextSettings> <HeaderStyle CssClass="WG-Header" /> <RowHeaderStyle CssClass="WG-RH"> </RowHeaderStyle> <RowStyle CssClass="WG-Row"></RowStyle> <AlternatingRowStyle CssClass="WG-AR" /> <SelectedRowStyle CssClass="WG-SR" /> <LostFocusRowStyle CssClass="WG-LFR"> </LostFocusRowStyle> <EditTextboxStyle CssClass="WG7W-ET"> </EditTextboxStyle> <ClientSideEvents OnAfterInitialize="WG1_OnAfterInitialize" OnRowContextMenu="WG1_OnRowContextMenu" OnCheckBoxClick="WG1_OnCheckBoxClick" /> </LayoutSettings> </ISWebGrid:WebGrid>
The following code is the key code of my background program .
protected void WG1_InitializeDataSource(object sender, ISNet.WebUI.WebGrid.DataSourceEventArgs e) { string IsTop = ConfigurationManager.AppSettings["IsTop"]; string ModuleGuidLst = ""; DataView dv_module = ModuleRights.getRolesRightV3(ViewState["ModuleCode"].ToString(), "public", IsTop, dropShowType.SelectedItem.Value, ViewState["RoleFilter"].ToString().Split(';'), out ModuleGuidLst); ViewState["ModuleGuidLst"] = ModuleGuidLst; InitWG(); e.DataSource = dv_module; this.WriteAjaxMessage("InitMenu();"); } private void InitWG() { WG1.RootTable.Columns.Clear(); WebGridColumn wgCol0 = new WebGridColumn(); wgCol0.Name = "ModuleName"; wgCol0.ColumnType = ColumnType.Template; wgCol0.CellTemplate = new CellTemplate(new Control()); wgCol0.Caption = "模块名称"; wgCol0.EditType = EditType.NoEdit; wgCol0.Width = 100; wgCol0.AllowSorting = Sorting.No; WG1.RootTable.Columns.Add(wgCol0); string ChkRoleGuidLst = ""; string ChkRoleNameLst = ""; int RemoveCount = 0; for (int i = 0; i < chkRoleList.Items.Count; i++) { if (!chkRoleList.Items[i].Selected) { RemoveCount++; continue; } ChkRoleNameLst += chkRoleList.Items[i].Text + ";"; ChkRoleGuidLst += chkRoleList.Items[i].Value + ";"; } string[] chkRoleName = ChkRoleNameLst.TrimEnd(';').Split(';'); string[] chkRoleGuid = ChkRoleGuidLst.TrimEnd(';').Split(';'); if (ChkRoleGuidLst != "") { for (int j = 0; j < chkRoleGuid.Length; j++) { wgCol0 = new WebGridColumn(); wgCol0.Caption = chkRoleName[j] + "<input type=\"checkbox\" onclick=\"SelectAllColumn(this)\" name=\"" + j + "_chk_" + chkRoleGuid[j] + "\">"; wgCol0.ColumnType = ColumnType.CheckBox; wgCol0.EditType = EditType.Checkbox; wgCol0.DataType = "System.Boolean"; wgCol0.Width = 120; wgCol0.IsAutoWidth = false; wgCol0.AllowSorting = Sorting.No; wgCol0.DataMember = chkRoleGuid[j]; WG1.RootTable.Columns.Add(wgCol0); } } wgCol0 = new WebGridColumn(); int Index = chkRoleList.Items.Count - RemoveCount; wgCol0.Caption = "完全公开" + "<input type=\"checkbox\" onclick=\"SelectAllColumn(this)\" name=\"" + Index + "_chk_完全公开_" + "\">"; wgCol0.ColumnType = ColumnType.CheckBox; wgCol0.CellStyle.HorizontalAlign = ISNet.WebUI.HorizontalAlign.Center; wgCol0.Name = "完全公开"; wgCol0.EditType = EditType.Checkbox; wgCol0.DataType = "System.Boolean"; wgCol0.Width = 100; wgCol0.IsAutoWidth = false; wgCol0.AllowSorting = Sorting.No; wgCol0.DataMember = "完全公开"; WG1.RootTable.Columns.Add(wgCol0); wgCol0 = new WebGridColumn(); wgCol0.Caption = "高级设置"; wgCol0.Name = "Seeting"; wgCol0.Width = 60; wgCol0.IsAutoWidth = false; wgCol0.HyperlinkDisplayText = " 高级设置"; wgCol0.CellStyle.HorizontalAlign = ISNet.WebUI.HorizontalAlign.Center; wgCol0.ColumnType = ColumnType.HyperLink; wgCol0.HyperlinkTarget = HyperlinkTarget.Custom; wgCol0.HyperlinkFormatString = "javascript:doSelectRightPage('Pages/DlgRight/Setting_AllowTo_All.aspx?baseOuGuid=&setType=module&argsGuid=');"; WG1.RootTable.Columns.Add(wgCol0); } protected void WG1_BatchUpdate(object sender, BatchUpdateEventArgs e) { string ModuleGuid = ""; foreach (WebGridRowChanges rowChanges in e.PendingChanges) { if (rowChanges.RowState == RowState.Modified) { ModuleGuid = rowChanges.KeyValue.ToString(); string IsTop = ConfigurationManager.AppSettings["IsTop"]; string ModuleGuidLst = ViewState["ModuleGuidLst"].ToString(); DataView dv_module = ModuleRights.getRolesRightV3("public", IsTop, ViewState["RoleFilter"].ToString().Split(';'), out ModuleGuidLst); dv_module.RowFilter = "ModuleGuid='" + ModuleGuid + "'"; AppRole OldAppRole = new AppRole(ModuleGuid, dv_module[0]["完全公开"].ToString()); AppRole NewAppRole = getChangeValue(rowChanges.Data, ModuleGuid); if ((OldAppRole.AllGK.ToLower() == "true" && NewAppRole.AllGK == "NoEdit") || (OldAppRole.AllGK.ToLower() == "false" && NewAppRole.AllGK.ToLower() == "true")) { ModuleRights.ModuleRight_Delete(ModuleGuid, "Role"); ModuleRights.ModuleRight_Insert(ModuleGuid, "All", "Role"); } else { ModuleRights.ModuleRight_Delete(ModuleGuid, "All", "Role"); foreach (WebGridCellData cellData in rowChanges.Data) { if (Convert.ToBoolean(cellData.NewValue) == true) { ModuleRights.ModuleRight_Delete(ModuleGuid, "All", "Role"); ModuleRights.ModuleRight_Insert(ModuleGuid, cellData.Column.DataMember, "Role"); } else { ModuleRights.ModuleRight_Delete(ModuleGuid, cellData.Column.DataMember, "Role"); } } } } } }
Anyone can help me ? Thank you very much !
I tried to reproduce the problem by creating a running simple sample of batch update enabled WebGrid but my efforts were not successful – everything worked smoothly and I was unable to reproduce the misaligned column after invoking the OnBatchUpdate server-side event.
Could you please confirm whether you are using the latest build version of WebGrid 7 and WebUI.NET Framework 3?
Hi Yudi ,
Thank you for your reply ! My latest build version of WebGrid is 7.0.7200.431 and the latest build version of WebUI is 3.0.5000.1 .
Can you give me that running simple sample of batch update ? I will be very grateful !
I enclosed my simple sample as attachment.
Please have the sample tested on your end and let us know if the problem still occurs. Should you find anything that I missed during my attempt to reproduce the issue, please feel free to modify the sample and send it back to us to be investigated further.
For your information, I’m using WebGrid 7 build 432 and WebUI.NET Framework 3.0 build 773.
Hope this helps.
Hello Yudi ,
Thank you for your sample and help . The sample you provided worked smoothly . But I think I do not explain my problem clearly .
In my project , if I create the columns of WebGrid in the foreground program , the problem I said will not appear . However , if I dynamically create the columns in the method named "WG1_InitializeDataSource" , there will be some problems . After invoking the OnBatchUpdate server-side event , it will invoke the method named "WG1_InitializeDataSource" again . Then the misaligned column will occur .
Can you help me to solve this problem ? Thanks a lot !
All codes related to the assignment of data source to the WebGrid component should be placed in the InitializeDataSource server-side event.
After WebGrid has successfully binded its DataSource which defined using e.DataSource. In the PrepareDataBinding server-side event, developers can conveniently populate all the columns structure. There are many cases that developers often forgot to place all "object creation" codes under !IsPostBack condition, so please remember to place WebGrid1.RetrieveStructure() or WebGrid1.RetrieveHierarchicalStructure() under !IsPostBack condition. There are cases such as users has utilized resizing columns, sorting and grouping features and invoked PostBack to the server, but after the PostBack all the features applied are overrided back to the first configuration erasing all features that have been applied.
The snippet code below shows the modified version of BatchUpdate_CustomObjectUpdate.aspx.cs file (the file is attached on my previous post). In the modified version columns are created dynamically in PrepareDataBinding server-side event using following code.
protected void WebGrid1_PrepareDataBinding(object sender, ISNet.WebUI.WebGrid.DataSourceEventArgs e) { if (!IsPostBack) { WebGrid1.RootTable.Columns.Add(new WebGridColumn("CustomerID", "CustomerID", "CustomerID")); WebGrid1.RootTable.Columns.Add(new WebGridColumn("CompanyName", "CompanyName", "CompanyName")); WebGrid1.RootTable.Columns.Add(new WebGridColumn("ContactName", "ContactName", "ContactName")); WebGrid1.RootTable.Columns.Add(new WebGridColumn("ContactTitle", "ContactTitle", "ContactTitle")); WebGrid1.RootTable.Columns.Add(new WebGridColumn("Address", "Address", "Address")); WebGrid1.RootTable.Columns.Add(new WebGridColumn("City", "City", "City")); WebGrid1.RootTable.Columns.Add(new WebGridColumn("Region", "Region", "Region")); WebGrid1.RootTable.Columns.Add(new WebGridColumn("PostalCode", "PostalCode", "PostalCode")); WebGrid1.RootTable.Columns.Add(new WebGridColumn("Country", "Country", "Country")); WebGrid1.RootTable.Columns.Add(new WebGridColumn("Phone", "Phone", "Phone")); WebGrid1.RootTable.Columns.Add(new WebGridColumn("Fax", "Fax", "Fax")); WebGrid1.RootTable.Columns.Add(new WebGridColumn("Orders", "Orders", "Orders")); WebGrid1.RootTable.DataKeyField = "CustomerID"; } }
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