Hi
I have a grid with self hierarchy. I am creating the grid and columns programatically in the Page_Init event handler (method createGrid()). I set the AutoGenerateEditColumn property to 'true'. When creating the columns, i created a GridTemplateColumn using my own custom template- 'MyTemplate' and edit template- 'MyEditTemplate'. MyTemplate contains only a Label and MyEditTemplate contains a TextBox (both asp controls). The grid is rendered perfectly but when i click the "edit" link button I'm getting a postBack (no ajax behaviour) and the item is not opened for editing...
i attached some of my code - createGrid() method and the item templates
Why doesn't the edit command work?..
Thank you
tali.
I have a grid with self hierarchy. I am creating the grid and columns programatically in the Page_Init event handler (method createGrid()). I set the AutoGenerateEditColumn property to 'true'. When creating the columns, i created a GridTemplateColumn using my own custom template- 'MyTemplate' and edit template- 'MyEditTemplate'. MyTemplate contains only a Label and MyEditTemplate contains a TextBox (both asp controls). The grid is rendered perfectly but when i click the "edit" link button I'm getting a postBack (no ajax behaviour) and the item is not opened for editing...
i attached some of my code - createGrid() method and the item templates
Why doesn't the edit command work?..
| private void createGrid() | |
| { | |
| grdRuns.ID = "grdRuns"; | |
| grdRuns.ColumnCreated -= new GridColumnCreatedEventHandler(grdRuns_ColumnCreated); | |
| grdRuns.ItemCreated -= new GridItemEventHandler(grdRuns_ItemCreated); | |
| grdRuns.ItemDataBound -= new GridItemEventHandler(grdRuns_ItemDataBound); | |
| grdRuns.AutoGenerateColumns = false; | |
| grdRuns.HorizontalAlign = HorizontalAlign.Right; | |
| grdRuns.MasterTableView.HorizontalAlign = HorizontalAlign.Right; | |
| grdRuns.MasterTableView.Dir = GridTableTextDirection.RTL; | |
| grdRuns.EnableEmbeddedSkins = false; | |
| grdRuns.Skin = "Portal"; | |
| grdRuns.ClientSettings.Scrolling.UseStaticHeaders = true; | |
| grdRuns.ClientSettings.Scrolling.AllowScroll = true; | |
| grdRuns.MasterTableView.HierarchyDefaultExpanded = true; | |
| grdRuns.MasterTableView.TableLayout = GridTableLayout.Fixed; | |
| grdRuns.AutoGenerateEditColumn = true; | |
| grdRuns.AllowAutomaticUpdates = true; | |
| grdRuns.MasterTableView.EditMode = GridEditMode.EditForms; | |
| grdRuns.ColumnCreated += new GridColumnCreatedEventHandler(grdRuns_ColumnCreated); | |
| grdRuns.ItemCreated += new GridItemEventHandler(grdRuns_ItemCreated); | |
| grdRuns.ItemDataBound += new GridItemEventHandler(grdRuns_ItemDataBound); | |
| NostroDataSet.FieldsForGridDataTable dtFields = BLManager.GetFieldsForGrid(int.Parse(ddlRuns.SelectedValue)); | |
| foreach (NostroDataSet.FieldsForGridRow row in dtFields.Rows) | |
| { | |
| if (row.IsEditable) | |
| { | |
| GridTemplateColumn templateColumn = new GridTemplateColumn(); | |
| string templateColumnName = row.FieldName; | |
| templateColumn.ItemTemplate = new MyTemplate(templateColumnName); | |
| templateColumn.EditItemTemplate = new MyEditTemplate(templateColumnName); | |
| templateColumn.HeaderText = row.ScreenName; | |
| templateColumn.Display = row.Display; | |
| templateColumn.HeaderStyle.Width = Unit.Pixel(row.Witdh); | |
| templateColumn.ItemStyle.Width = Unit.Pixel(row.Witdh); | |
| grdRuns.MasterTableView.Columns.Add(templateColumn); | |
| } | |
| else | |
| { | |
| GridBoundColumn clm = new GridBoundColumn(); | |
| clm.DataField = row.FieldName; | |
| clm.HeaderText = row.ScreenName; | |
| clm.UniqueName = row.FieldName; | |
| clm.HeaderStyle.Wrap = false; | |
| clm.ItemStyle.Wrap = false; | |
| clm.HeaderStyle.Width = Unit.Pixel(row.Witdh); | |
| clm.ItemStyle.Width = Unit.Pixel(row.Witdh); | |
| grdRuns.MasterTableView.Columns.Add(clm); | |
| clm.Display = row.Display; | |
| } | |
| } | |
| grdRuns.ClientSettings.AllowExpandCollapse = true; | |
| grdRuns.MasterTableView.HierarchyLoadMode = GridChildLoadMode.Client; | |
| grdRuns.MasterTableView.HierarchyDefaultExpanded = false; | |
| grdRuns.MasterTableView.DataKeyNames = new string[] { "PortfolioID", "ParentID" }; | |
| grdRuns.MasterTableView.SelfHierarchySettings.ParentKeyName = "ParentID"; | |
| grdRuns.MasterTableView.SelfHierarchySettings.KeyName = "PortfolioID"; | |
| grdRuns.EditCommand += new GridCommandEventHandler(grdRuns_EditCommand); | |
| divGrid.Controls.Add(grdRuns); | |
| grdRuns.DataSource = ApproveRunData; | |
| } |
| private class MyTemplate : ITemplate | |
| { | |
| //protected LiteralControl lControl; | |
| protected Label label; | |
| private string colname; | |
| public MyTemplate(string cName) | |
| { | |
| colname = cName; | |
| } | |
| public void InstantiateIn(System.Web.UI.Control container) | |
| { | |
| //lControl = new LiteralControl(); | |
| //lControl.ID = "lControl"; | |
| //lControl.DataBinding += new EventHandler(lControl_DataBinding); | |
| label = new Label(); | |
| label.ID = "templateColumnLabel"; | |
| label.DataBinding += new EventHandler(label_DataBinding); | |
| container.Controls.Add(label); | |
| } | |
| void label_DataBinding(object sender, EventArgs e) | |
| { | |
| Label lbl = (Label)sender; | |
| GridDataItem container = (GridDataItem)lbl.NamingContainer; | |
| string sValue = ((DataRowView)container.DataItem)[colname].ToString(); | |
| double dValue = -1; | |
| if (double.TryParse(sValue, out dValue)) | |
| { | |
| string sTemp = String.Format("{0:n}", dValue); //add commas as thousand separator | |
| lbl.Text = sTemp.Substring(0, sTemp.IndexOf('.')); //don't display digits after decimal point. | |
| lbl.Style.Add("text-align", "left"); //make the minus sign ('-') appear on the left of the number. | |
| } | |
| else lbl.Text = sValue; | |
| if (sValue == "") lbl.Text = " "; | |
| } | |
| public void lControl_DataBinding(object sender, EventArgs e) | |
| { | |
| LiteralControl l = (LiteralControl)sender; | |
| GridDataItem container = (GridDataItem)l.NamingContainer; | |
| string sValue = ((DataRowView)container.DataItem)[colname].ToString(); | |
| double dValue = -1; | |
| if (double.TryParse(sValue, out dValue)) | |
| { | |
| string sTemp = String.Format("{0:n}", dValue); //add commas as thousand separator | |
| l.Text = sTemp.Substring(0, sTemp.IndexOf('.')); //don't display digits after decimal point. | |
| //l.Style.Add("text-align", "left"); //make the minus sign ('-') appear on the left of the number. | |
| } | |
| else l.Text = sValue + "<br/>"; | |
| if (sValue == "") l.Text = " "; | |
| //l.Text = ((DataRowView)container.DataItem)[colname].ToString() + "<br />"; | |
| } | |
| } | |
| private class MyEditTemplate : ITemplate | |
| { | |
| protected LiteralControl lControl; | |
| protected TextBox textBox; | |
| private string colname; | |
| public MyEditTemplate(string cName) | |
| { | |
| colname = cName; | |
| } | |
| public void InstantiateIn(System.Web.UI.Control container) | |
| { | |
| lControl = new LiteralControl(); | |
| lControl.ID = "lControl"; | |
| lControl.DataBinding += new EventHandler(lControl_DataBinding); | |
| textBox = new TextBox(); | |
| textBox.ID = "templateColumnTextBox"; | |
| textBox.CssClass = "fieldUpdatePortal"; | |
| textBox.DataBinding += new EventHandler(textBox_DataBinding); | |
| container.Controls.Add(textBox); | |
| } | |
| void textBox_DataBinding(object sender, EventArgs e) | |
| { | |
| TextBox tBox = (TextBox)sender; | |
| GridDataItem container = (GridDataItem)tBox.NamingContainer; | |
| string sValue = ((DataRowView)container.DataItem)[colname].ToString(); | |
| double dValue = -1; | |
| if (double.TryParse(sValue, out dValue)) | |
| { | |
| string sTemp = String.Format("{0:n}", dValue); //add commas as thousand separator | |
| tBox.Text = sTemp.Substring(0, sTemp.IndexOf('.')); //don't display digits after decimal point. | |
| tBox.Style.Add("direction", "ltr"); //make the minus sign ('-') appear on the left of the number. | |
| } | |
| else tBox.Text = sValue; | |
| } | |
| public void lControl_DataBinding(object sender, EventArgs e) | |
| { | |
| LiteralControl l = (LiteralControl)sender; | |
| GridDataItem container = (GridDataItem)l.NamingContainer; | |
| l.Text = ((DataRowView)container.DataItem)[colname].ToString() + "<br />"; | |
| } | |
| } | |
Thank you
tali.