This message was discovered on ASPFriends.com 'aspngcontrolscs' list.
| Ray Houston |
Hi, I've created an editable grid which allows the users to add new rows (using a Postback) on the the fly and save this information back to the database. I pretty much have my control like the one in the Docs for Creating a DataBound Templated control.
Here is how I would like things to work: 1. The user adds new rows (this works) 2. They hit save and the information is stored to the database (works too) 3. The information is then rebinded to the control (this doesn't work). I want to reflect the values in the database without completely reloading the page. It seems there is viewstate data that is conflicting with what is being rendered in the controls of the individual rows.
I don't want to have to reload the page from scratch. How can I do this? ******************************************************** ******************************************************** Here is some of my code for the main control:
private ArrayList _Items = new ArrayList(); public ICollection Items { get { return ((ICollection)this._Items); } }
public int ItemCount { get { if (ViewState["ItemCount"] == null) return -1; else return (int)ViewState["ItemCount"]; } set { ViewState["ItemCount"] = value; } }
protected void AddRow_Command(Object Src, CommandEventArgs E) { NumberOfRowsToAdd = 1; } protected override void OnPreRender(EventArgs E) { base.OnPreRender(E); for (int i=0;i<NumberOfRowsToAdd;i++) CreateItem(null);
ItemCount += NumberOfRowsToAdd; } protected override void OnDataBinding(EventArgs E) { base.OnDataBinding(E); if (this.DataSource != null) { Controls.Clear(); ClearChildViewState();
CreateControlHierarchy(true); ChildControlsCreated = true;
TrackViewState(); } } protected override void CreateChildControls() { if (ItemCount != -1) CreateControlHierarchy(false); } private void CreateControlHierarchy(bool useDataSource) { this.Controls.Add(Details);
//Add Header Row string[] Headings = {"Delete","Date From","Date To","Percent","Months"}; this.Details.Rows.Add(new TableRow()); for (int i=0;i<Headings.GetLength(0);i++) { this.Details.Rows[0].Cells.Add(new TableCell()); this.Details.Rows[0].Cells[i].Controls.Add(new LiteralControl(Headings[i])); this.Details.Rows[0].Cells[i].CssClass = "EztControlDetailHeader"; }
Add AddRow Button this.Details.Rows.Add(new TableRow()); this.Details.Rows[1].Cells.Add(new TableCell()); this.Details.Rows[1].Cells[0].ColumnSpan = Headings.GetLength(0); this.Details.Rows[1].Cells[0].Controls.Add(AddButton); this.Controls.Add(AddButton);
AddButton.ToolTip = "Add a new Rent Step row"; AddButton.Text = "Add Rent Step"; AddButton.Command += new CommandEventHandler(this.AddRow_Command);
IEnumerable dataSource = null; if (useDataSource == false) { if (ItemCount != -1) dataSource = new DummyDataSource(ItemCount); } else dataSource = this.DataSource.Items;
int count = -1; if (dataSource != null) { count = 0; foreach (object dataItem in dataSource) { CreateItem(dataItem); count++; } }
if (useDataSource) ItemCount = ((dataSource != null) ? count : -1); } private void CreateItem(object dataItem) { EztLeaseRentAbatementDetail myDetail = new EztLeaseRentAbatementDetail(); myDetail.EnsureCreated(); this.Details.Rows.Add(myDetail); this._Items.Add(myDetail); if (dataItem != null) myDetail.DataSource = (LeaseRentAbatementDetailObj)dataItem; } ******************************************************** ******************************************************** And Here's the row control which is based on TableRow:
public EztTextBoxDate BeginDate = new EztTextBoxDate(); public EztTextBoxDate EndDate = new EztTextBoxDate(); public EztTextBoxDecimal AbatementPercent = new EztTextBoxDecimal(); public EztTextBoxInt AbatementMonths = new EztTextBoxInt();
private TableCell myDeleteCell;
private LeaseRentAbatementDetailObj _dataSource = null; public LeaseRentAbatementDetailObj DataSource { get { return this._dataSource; } set { this._dataSource = value; } } protected override void OnDataBinding(EventArgs E) { base.OnDataBinding(E); if (this.DataSource != null) { if (DataSource.BeginDate.CompareTo(DateTime.MinValue) == 0) this.BeginDate.Text = ""; else this.BeginDate.Text = DataSource.BeginDate.ToShortDateString(); if (DataSource.EndDate.CompareTo(DateTime.MinValue) == 0) this.EndDate.Text = ""; else this.EndDate.Text = DataSource.EndDate.ToShortDateString(); this.AbatementPercent.Text = DataSource.AbatementPercent.ToString(); this.AbatementMonths.Text = DataSource.AbatementMonths.ToString(); } }
protected override void CreateChildControls() { this.Cells.Add(new EztControlDetailCell()); this.Cells[0].Controls.Add(new CheckBox()); myDeleteCell = this.Cells[0]; this.Cells[0].Width = Unit.Pixel(50); this.Cells[0].HorizontalAlign = HorizontalAlign.Center;
this.Cells.Add(new EztControlDetailCell()); this.Cells[1].Controls.Add(BeginDate);
this.Cells.Add(new EztControlDetailCell()); this.Cells[2].Controls.Add(EndDate);
this.Cells.Add(new EztControlDetailCell()); this.Cells[3].Controls.Add(AbatementPercent);
this.Cells.Add(new EztControlDetailCell()); this.Cells[4].Controls.Add(AbatementMonths);
BeginDate.MaxLength = 30; BeginDate.Columns = 10;
EndDate.MaxLength = 30; EndDate.Columns = 10;
AbatementPercent.MaxLength = 30; AbatementPercent.Columns = 10;
AbatementMonths.MaxLength = 30; AbatementMonths.Columns = 10; }
|
|
| |
| |
| Ray Houston |
Opps. I forgot to mention that the problems occurs after a postback that happens after the postback which rebinds the data. Like this 1.Save button clicked 2.Postback - Data is saved and rebinded 3.Page is rendered (looks ok) 4.Another button is click that causes a postback (can be any button) 5.Postback 6.Page is rendered but with problems
thanks, -Ray
************************************* Hi, I've created an editable grid which allows the users to add new rows (using a Postback) on the the fly and save this information back to the database. I pretty much have my control like the one in the Docs for Creating a DataBound Templated control.
Here is how I would like things to work: 1. The user adds new rows (this works) 2. They hit save and the information is stored to the database (works too) 3. The information is then rebinded to the control (this doesn't work). I want to reflect the values in the database without completely reloading the page. It seems there is viewstate data that is conflicting with what is being rendered in the controls of the individual rows.
I don't want to have to reload the page from scratch. How can I do this? ******************************************************** ******************************************************** Here is some of my code for the main control:
private ArrayList _Items = new ArrayList(); public ICollection Items { get { return ((ICollection)this._Items); } }
public int ItemCount { get { if (ViewState["ItemCount"] == null) return -1; else return (int)ViewState["ItemCount"]; } set { ViewState["ItemCount"] = value; } }
protected void AddRow_Command(Object Src, CommandEventArgs E) { NumberOfRowsToAdd = 1; } protected override void OnPreRender(EventArgs E) { base.OnPreRender(E); for (int i=0;i<NumberOfRowsToAdd;i++) CreateItem(null);
ItemCount += NumberOfRowsToAdd; } protected override void OnDataBinding(EventArgs E) { base.OnDataBinding(E); if (this.DataSource != null) { Controls.Clear(); ClearChildViewState();
CreateControlHierarchy(true); ChildControlsCreated = true;
TrackViewState(); } } protected override void CreateChildControls() { if (ItemCount != -1) CreateControlHierarchy(false); } private void CreateControlHierarchy(bool useDataSource) { this.Controls.Add(Details);
//Add Header Row string[] Headings = {"Delete","Date From","Date To","Percent","Months"}; this.Details.Rows.Add(new TableRow()); for (int i=0;i<Headings.GetLength(0);i++) { this.Details.Rows[0].Cells.Add(new TableCell()); this.Details.Rows[0].Cells[i].Controls.Add(new LiteralControl(Headings[i])); this.Details.Rows[0].Cells[i].CssClass = "EztControlDetailHeader"; }
Add AddRow Button this.Details.Rows.Add(new TableRow()); this.Details.Rows[1].Cells.Add(new TableCell()); this.Details.Rows[1].Cells[0].ColumnSpan = Headings.GetLength(0); this.Details.Rows[1].Cells[0].Controls.Add(AddButton); this.Controls.Add(AddButton);
AddButton.ToolTip = "Add a new Rent Step row"; AddButton.Text = "Add Rent Step"; AddButton.Command += new CommandEventHandler(this.AddRow_Command);
IEnumerable dataSource = null; if (useDataSource == false) { if (ItemCount != -1) dataSource = new DummyDataSource(ItemCount); } else dataSource = this.DataSource.Items;
int count = -1; if (dataSource != null) { count = 0; foreach (object dataItem in dataSource) { CreateItem(dataItem); count++; } }
if (useDataSource) ItemCount = ((dataSource != null) ? count : -1); } private void CreateItem(object dataItem) { EztLeaseRentAbatementDetail myDetail = new EztLeaseRentAbatementDetail(); myDetail.EnsureCreated(); this.Details.Rows.Add(myDetail); this._Items.Add(myDetail); if (dataItem != null) myDetail.DataSource = (LeaseRentAbatementDetailObj)dataItem; } ******************************************************** ******************************************************** And Here's the row control which is based on TableRow:
public EztTextBoxDate BeginDate = new EztTextBoxDate(); public EztTextBoxDate EndDate = new EztTextBoxDate(); public EztTextBoxDecimal AbatementPercent = new EztTextBoxDecimal(); public EztTextBoxInt AbatementMonths = new EztTextBoxInt();
private TableCell myDeleteCell;
private LeaseRentAbatementDetailObj _dataSource = null; public LeaseRentAbatementDetailObj DataSource { get { return this._dataSource; } set { this._dataSource = value; } } protected override void OnDataBinding(EventArgs E) { base.OnDataBinding(E); if (this.DataSource != null) { if (DataSource.BeginDate.CompareTo(DateTime.MinValue) == 0) this.BeginDate.Text = ""; else this.BeginDate.Text = DataSource.BeginDate.ToShortDateString(); if (DataSource.EndDate.CompareTo(DateTime.MinValue) == 0) this.EndDate.Text = ""; else this.EndDate.Text = DataSource.EndDate.ToShortDateString(); this.AbatementPercent.Text = DataSource.AbatementPercent.ToString(); this.AbatementMonths.Text = DataSource.AbatementMonths.ToString(); } }
protected override void CreateChildControls() { this.Cells.Add(new EztControlDetailCell()); this.Cells[0].Controls.Add(new CheckBox()); myDeleteCell = this.Cells[0]; this.Cells[0].Width = Unit.Pixel(50); this.Cells[0].HorizontalAlign = HorizontalAlign.Center;
this.Cells.Add(new EztControlDetailCell()); this.Cells[1].Controls.Add(BeginDate);
this.Cells.Add(new EztControlDetailCell()); this.Cells[2].Controls.Add(EndDate);
this.Cells.Add(new EztControlDetailCell()); this.Cells[3].Controls.Add(AbatementPercent);
this.Cells.Add(new EztControlDetailCell()); this.Cells[4].Controls.Add(AbatementMonths);
BeginDate.MaxLength = 30; BeginDate.Columns = 10;
EndDate.MaxLength = 30; EndDate.Columns = 10;
AbatementPercent.MaxLength = 30; AbatementPercent.Columns = 10;
AbatementMonths.MaxLength = 30; AbatementMonths.Columns = 10; }
|
|
| |
|
| |
| Carlos Magalhaes |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> <HTML> <HEAD> <META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; = charset=3Dus-ascii"> <META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version = 5.5.2652.35"> <TITLE>RE: [aspngcontrolscs] Building a databound Control with = rows</TITLE> </HEAD> <BODY>
<P><FONT SIZE=3D2>OK wow that would help , do you have one in VB = pls?</FONT> </P>
<P><FONT SIZE=3D2>Thank you </FONT> </P>
<P><FONT SIZE=3D2>Carlos</FONT> </P>
<P><FONT SIZE=3D2>-----Original Message-----</FONT> <BR><FONT SIZE=3D2>From: Ray Houston [<A = HREF=3D"mailto:Click here to reveal e-mail address">mailto:Click here to reveal e-mail address</A>] </FONT> <BR><FONT SIZE=3D2>Sent: Thursday, April 18, 2002 8:29 PM</FONT> <BR><FONT SIZE=3D2>To: aspngcontrolscs</FONT> <BR><FONT SIZE=3D2>Subject: [aspngcontrolscs] Building a databound = Control with rows</FONT> </P>
<P><FONT SIZE=3D2>Hi,</FONT> <BR><FONT SIZE=3D2>I've created an editable grid which allows the users = to add new rows (using</FONT> <BR><FONT SIZE=3D2>a Postback) on the the fly and save this = information back to the database.</FONT> <BR><FONT SIZE=3D2>I pretty much have my control like the one in the = Docs for Creating a</FONT> <BR><FONT SIZE=3D2>DataBound Templated control.</FONT> </P>
<P><FONT SIZE=3D2>Here is how I would like things to work:</FONT> <BR><FONT SIZE=3D2>1. The user adds new rows (this works)</FONT> <BR><FONT SIZE=3D2>2. They hit save and the information is stored to = the database (works too)</FONT> <BR><FONT SIZE=3D2>3. The information is then rebinded to the control = (this doesn't work). I</FONT> <BR><FONT SIZE=3D2>want to reflect the values in the database without = completely reloading the</FONT> <BR><FONT SIZE=3D2>page. It seems there is viewstate data that is = conflicting with what is</FONT> <BR><FONT SIZE=3D2>being rendered in the controls of the individual = rows.</FONT> </P>
<P><FONT SIZE=3D2>I don't want to have to reload the page from = scratch. How can I do this?</FONT> <BR><FONT = SIZE=3D2>********************************************************</FONT>=
<BR><FONT = SIZE=3D2>********************************************************</FONT>=
<BR><FONT SIZE=3D2>Here is some of my code for the main control:</FONT> </P>
<P><FONT SIZE=3D2>private ArrayList _Items =3D new ArrayList();</FONT> <BR><FONT SIZE=3D2>public ICollection Items</FONT> <BR><FONT SIZE=3D2>{</FONT> <BR> <FONT = SIZE=3D2>get</FONT> <BR> <FONT SIZE=3D2>{</FONT> <BR> = <FONT SIZE=3D2>return = ((ICollection)this._Items);</FONT> <BR> <FONT SIZE=3D2>}</FONT> <BR><FONT SIZE=3D2>}</FONT> </P>
<P><FONT SIZE=3D2>public int ItemCount</FONT> <BR><FONT SIZE=3D2>{</FONT> <BR> <FONT = SIZE=3D2>get</FONT> <BR> <FONT SIZE=3D2>{</FONT> <BR> = <FONT SIZE=3D2>if = (ViewState["ItemCount"] =3D=3D null)</FONT> <BR> = = <FONT SIZE=3D2>return = -1;</FONT> <BR> = <FONT SIZE=3D2>else</FONT> <BR> = = <FONT SIZE=3D2>return = (int)ViewState["ItemCount"];</FONT> <BR> <FONT SIZE=3D2>}</FONT> <BR> <FONT = SIZE=3D2>set</FONT> <BR> <FONT SIZE=3D2>{</FONT> <BR> = <FONT = SIZE=3D2>ViewState["ItemCount"] =3D value;</FONT> <BR> <FONT SIZE=3D2>}</FONT> <BR><FONT SIZE=3D2>}</FONT> </P>
<P><FONT SIZE=3D2>protected void AddRow_Command(Object Src, = CommandEventArgs E)</FONT> <BR><FONT SIZE=3D2>{</FONT> <BR> <FONT = SIZE=3D2>NumberOfRowsToAdd =3D 1;</FONT> <BR><FONT SIZE=3D2>}</FONT> <BR><FONT SIZE=3D2>protected override void OnPreRender(EventArgs = E)</FONT> <BR><FONT SIZE=3D2>{</FONT> <BR> <FONT = SIZE=3D2>base.OnPreRender(E);</FONT> <BR> <FONT SIZE=3D2>for (int = i=3D0;i<NumberOfRowsToAdd;i++)</FONT> <BR> = <FONT = SIZE=3D2>CreateItem(null);</FONT> </P>
<P> <FONT SIZE=3D2>ItemCount = +=3D NumberOfRowsToAdd;</FONT> <BR><FONT SIZE=3D2>}</FONT> <BR><FONT SIZE=3D2>protected override void OnDataBinding(EventArgs = E)</FONT> <BR><FONT SIZE=3D2>{</FONT> <BR> <FONT = SIZE=3D2>base.OnDataBinding(E);</FONT> <BR> <FONT SIZE=3D2>if = (this.DataSource !=3D null)</FONT> <BR> <FONT SIZE=3D2>{</FONT> <BR> = <FONT = SIZE=3D2>Controls.Clear();</FONT> <BR> = <FONT = SIZE=3D2>ClearChildViewState();</FONT> </P>
<P> = <FONT = SIZE=3D2>CreateControlHierarchy(true);</FONT> <BR> = <FONT = SIZE=3D2>ChildControlsCreated =3D true;</FONT> </P>
<P> = <FONT = SIZE=3D2>TrackViewState();</FONT> <BR> <FONT SIZE=3D2>}</FONT> <BR><FONT SIZE=3D2>}</FONT> <BR><FONT SIZE=3D2>protected override void CreateChildControls()</FONT> <BR><FONT SIZE=3D2>{</FONT> <BR> <FONT SIZE=3D2>if = (ItemCount !=3D -1)</FONT> <BR> = <FONT = SIZE=3D2>CreateControlHierarchy(false);</FONT> <BR><FONT SIZE=3D2>}</FONT> <BR><FONT SIZE=3D2>private void CreateControlHierarchy(bool = useDataSource)</FONT> <BR><FONT SIZE=3D2>{</FONT> <BR> <FONT = SIZE=3D2>this.Controls.Add(Details);</FONT> </P>
<P> <FONT SIZE=3D2>//Add = Header Row</FONT> <BR> <FONT SIZE=3D2>string[] = Headings =3D {"Delete","Date From","Date = To","Percent","Months"};</FONT> <BR> <FONT = SIZE=3D2>this.Details.Rows.Add(new TableRow());</FONT> <BR> <FONT SIZE=3D2>for (int = i=3D0;i<Headings.GetLength(0);i++)</FONT> <BR> <FONT SIZE=3D2>{</FONT> <BR> = <FONT = SIZE=3D2>this.Details.Rows[0].Cells.Add(new TableCell());</FONT> <BR> = <FONT = SIZE=3D2>this.Details.Rows[0].Cells[i].Controls.Add(new</FONT> <BR><FONT SIZE=3D2>LiteralControl(Headings[i]));</FONT> <BR> = <FONT = SIZE=3D2>this.Details.Rows[0].Cells[i].CssClass =3D = "EztControlDetailHeader";</FONT> <BR> <FONT SIZE=3D2>}</FONT> </P> <BR>
<P> = = <FONT SIZE=3D2>Add AddRow = Button</FONT> <BR> = = <FONT = SIZE=3D2>this.Details.Rows.Add(new TableRow());</FONT> <BR> = = <FONT = SIZE=3D2>this.Details.Rows[1].Cells.Add(new TableCell());</FONT> <BR> = = <FONT = SIZE=3D2>this.Details.Rows[1].Cells[0].ColumnSpan =3D = Headings.GetLength(0);</FONT> <BR> = = <FONT = SIZE=3D2>this.Details.Rows[1].Cells[0].Controls.Add(AddButton);</FONT> <BR> = = <FONT = SIZE=3D2>this.Controls.Add(AddButton);</FONT> </P>
<P> = = <FONT = SIZE=3D2>AddButton.ToolTip =3D "Add a new Rent Step = row";</FONT> <BR> = = <FONT = SIZE=3D2>AddButton.Text =3D "Add Rent Step";</FONT> <BR> = = <FONT = SIZE=3D2>AddButton.Command +=3D new = CommandEventHandler(this.AddRow_Command);</FONT> </P> <BR>
<P> <FONT = SIZE=3D2>IEnumerable dataSource =3D null;</FONT> <BR> <FONT SIZE=3D2>if = (useDataSource =3D=3D false)</FONT> <BR> <FONT SIZE=3D2>{</FONT> <BR> = <FONT SIZE=3D2>if (ItemCount = !=3D -1)</FONT> <BR> = = <FONT SIZE=3D2>dataSource = =3D new DummyDataSource(ItemCount);</FONT> <BR> <FONT SIZE=3D2>}</FONT> <BR> <FONT = SIZE=3D2>else</FONT> <BR> = <FONT SIZE=3D2>dataSource = =3D this.DataSource.Items;</FONT> </P>
<P> <FONT SIZE=3D2>int count = =3D -1;</FONT> <BR> <FONT SIZE=3D2>if = (dataSource !=3D null)</FONT> <BR> <FONT SIZE=3D2>{</FONT> <BR> = <FONT SIZE=3D2>count =3D = 0;</FONT> <BR> = <FONT SIZE=3D2>foreach = (object dataItem in dataSource)</FONT> <BR> = <FONT SIZE=3D2>{</FONT> <BR> = = <FONT = SIZE=3D2>CreateItem(dataItem);</FONT> <BR> = = <FONT = SIZE=3D2>count++;</FONT> <BR> = <FONT SIZE=3D2>}</FONT> <BR> <FONT SIZE=3D2>}</FONT> </P>
<P> <FONT SIZE=3D2>if = (useDataSource)</FONT> <BR> = <FONT SIZE=3D2>ItemCount =3D = ((dataSource !=3D null) ? count : -1);</FONT> <BR><FONT SIZE=3D2>}</FONT> <BR><FONT SIZE=3D2>private void CreateItem(object dataItem)</FONT> <BR><FONT SIZE=3D2>{</FONT> <BR> <FONT = SIZE=3D2>EztLeaseRentAbatementDetail myDetail =3D new = EztLeaseRentAbatementDetail();</FONT> <BR> <FONT = SIZE=3D2>myDetail.EnsureCreated();</FONT> <BR> <FONT = SIZE=3D2>this.Details.Rows.Add(myDetail);</FONT> <BR> <FONT = SIZE=3D2>this._Items.Add(myDetail);</FONT> <BR> <FONT SIZE=3D2>if = (dataItem !=3D null)</FONT> <BR> = <FONT = SIZE=3D2>myDetail.DataSource =3D = (LeaseRentAbatementDetailObj)dataItem;</FONT> <BR><FONT SIZE=3D2>}</FONT> <BR><FONT = SIZE=3D2>********************************************************</FONT>=
<BR><FONT = SIZE=3D2>********************************************************</FONT>=
<BR><FONT SIZE=3D2>And Here's the row control which is based on = TableRow:</FONT> </P>
<P><FONT SIZE=3D2>public EztTextBoxDate BeginDate =3D new = EztTextBoxDate();</FONT> <BR><FONT SIZE=3D2>public EztTextBoxDate EndDate =3D new = EztTextBoxDate();</FONT> <BR><FONT SIZE=3D2>public EztTextBoxDecimal AbatementPercent =3D = new EztTextBoxDecimal();</FONT> <BR><FONT SIZE=3D2>public EztTextBoxInt AbatementMonths =3D new = EztTextBoxInt();</FONT> </P>
<P><FONT SIZE=3D2>private TableCell myDeleteCell;</FONT> </P>
<P><FONT SIZE=3D2>private LeaseRentAbatementDetailObj _dataSource =3D = null;</FONT> <BR><FONT SIZE=3D2>public LeaseRentAbatementDetailObj DataSource</FONT> <BR><FONT SIZE=3D2>{</FONT> <BR> <FONT = SIZE=3D2>get</FONT> <BR> <FONT SIZE=3D2>{</FONT> <BR> = <FONT SIZE=3D2>return = this._dataSource;</FONT> <BR> <FONT SIZE=3D2>}</FONT> <BR> <FONT = SIZE=3D2>set</FONT> <BR> <FONT SIZE=3D2>{</FONT> <BR> = <FONT = SIZE=3D2>this._dataSource =3D value;</FONT> <BR> <FONT SIZE=3D2>}</FONT> <BR><FONT SIZE=3D2>}</FONT> <BR><FONT SIZE=3D2>protected override void OnDataBinding(EventArgs = E)</FONT> <BR><FONT SIZE=3D2>{</FONT> <BR> <FONT = SIZE=3D2>base.OnDataBinding(E);</FONT> <BR> <FONT SIZE=3D2>if = (this.DataSource !=3D null)</FONT> <BR> <FONT SIZE=3D2>{</FONT> <BR> = <FONT SIZE=3D2>if = (DataSource.BeginDate.CompareTo(DateTime.MinValue) =3D=3D 0)</FONT> <BR> = = <FONT = SIZE=3D2>this.BeginDate.Text =3D "";</FONT> <BR> = <FONT SIZE=3D2>else</FONT> <BR> = = <FONT = SIZE=3D2>this.BeginDate.Text =3D = DataSource.BeginDate.ToShortDateString();</FONT> <BR> = <FONT SIZE=3D2>if = (DataSource.EndDate.CompareTo(DateTime.MinValue) =3D=3D 0)</FONT> <BR> = = <FONT = SIZE=3D2>this.EndDate.Text =3D "";</FONT> <BR> = <FONT SIZE=3D2>else</FONT> <BR> = = <FONT SIZE=3D2>this.EndDate.T= ext =3D DataSource.EndDate.ToShortDateString();</FONT> <BR> = <FONT = SIZE=3D2>this.AbatementPercent.Text =3D = DataSource.AbatementPercent.ToString();</FONT> <BR> = <FONT = SIZE=3D2>this.AbatementMonths.Text =3D = DataSource.AbatementMonths.ToString();</FONT> <BR> <FONT SIZE=3D2>}</FONT> <BR><FONT SIZE=3D2>}</FONT> </P> <BR>
<P><FONT SIZE=3D2>protected override void CreateChildControls()</FONT> <BR><FONT SIZE=3D2>{</FONT> <BR> <FONT = SIZE=3D2>this.Cells.Add(new EztControlDetailCell());</FONT> <BR> <FONT = SIZE=3D2>this.Cells[0].Controls.Add(new CheckBox());</FONT> <BR> <FONT = SIZE=3D2>myDeleteCell =3D this.Cells[0];</FONT> <BR> <FONT = SIZE=3D2>this.Cells[0].Width =3D Unit.Pixel(50);</FONT> <BR> <FONT = SIZE=3D2>this.Cells[0].HorizontalAlign =3D = HorizontalAlign.Center;</FONT> </P>
<P> <FONT = SIZE=3D2>this.Cells.Add(new EztControlDetailCell());</FONT> <BR> <FONT = SIZE=3D2>this.Cells[1].Controls.Add(BeginDate);</FONT> </P>
<P> <FONT = SIZE=3D2>this.Cells.Add(new EztControlDetailCell());</FONT> <BR> <FONT = SIZE=3D2>this.Cells[2].Controls.Add(EndDate);</FONT> </P>
<P> <FONT = SIZE=3D2>this.Cells.Add(new EztControlDetailCell());</FONT> <BR> <FONT = SIZE=3D2>this.Cells[3].Controls.Add(AbatementPercent);</FONT> </P>
<P> <FONT = SIZE=3D2>this.Cells.Add(new EztControlDetailCell());</FONT> <BR> <FONT = SIZE=3D2>this.Cells[4].Controls.Add(AbatementMonths);</FONT> </P>
<P> <FONT = SIZE=3D2>BeginDate.MaxLength =3D 30;</FONT> <BR> <FONT = SIZE=3D2>BeginDate.Columns =3D 10;</FONT> </P>
<P> <FONT = SIZE=3D2>EndDate.MaxLength =3D 30;</FONT> <BR> <FONT = SIZE=3D2>EndDate.Columns =3D 10;</FONT> </P>
<P> <FONT = SIZE=3D2>AbatementPercent.MaxLength =3D 30;</FONT> <BR> <FONT = SIZE=3D2>AbatementPercent.Columns =3D 10;</FONT> </P>
<P> <FONT = SIZE=3D2>AbatementMonths.MaxLength =3D 30;</FONT> <BR> <FONT = SIZE=3D2>AbatementMonths.Columns =3D 10;</FONT> <BR><FONT SIZE=3D2>}</FONT> </P> <BR>
<P><FONT SIZE=3D2>| [aspngcontrolscs] member Click here to reveal e-mail address =3D = YOUR ID</FONT> <BR><FONT SIZE=3D2>| <A = HREF=3D"http://www.asplists.com/asplists/aspngcontrolscs.asp" = TARGET=3D"_blank">http://www.asplists.com/asplists/aspngcontrolscs.asp</= A> =3D JOIN/QUIT</FONT> <BR><FONT SIZE=3D2>| <A HREF=3D"http://www.asplists.com/search"" target="_blank">http://www.asplists.com/search" = TARGET=3D"_blank">http://www.asplists.com/search</A> =3D SEARCH = Archives</FONT> </P>
</BODY> </HTML>
------------------------------------------------------------- This email and any files transmitted are confidential and intended solely for the use of the individual or entity to which they are addressed, whose privacy should be respected. Any views or opinions are solely those of the author and do not necessarily represent those of the Trencor Group, or any of its representatives, unless specifically stated.
Email transmission cannot be guaranteed to be secure, error free or without virus contamination. The sender therefore accepts no liability for any errors or omissions in the contents of this message, nor for any virus infection that might result from opening this message. Trencor is not responsible in the event of any third party interception of this email.
If you have received this email in error please notify Click here to reveal e-mail address For more information about Trencor, visit www.trencor.net <http://www.trencor.net>
|
|
| |
|
| |
| Dennis West |
RE: [aspngcontrolscs] Building a databound Control with rowsCarlos here are C# to VB translaters:
http://aspalliance.com/dotnetsolutions/GetSolution.aspx?ID=1154
http://aspalliance.com/dotnetsolutions/GetSolution.aspx?ID=11323
http://aspalliance.com/dotnetsolutions/GetSolution.aspx?ID=11324
To: aspngcontrolscs Sent: Thursday, April 18, 2002 12:15 PM Subject: [aspngcontrolscs] RE: Building a databound Control with rows
OK wow that would help , do you have one in VB pls?
Thank you
Carlos
-----Original Message----- From: Ray Houston [mailto:Click here to reveal e-mail address] Sent: Thursday, April 18, 2002 8:29 PM To: aspngcontrolscs Subject: [aspngcontrolscs] Building a databound Control with rows
Hi, I've created an editable grid which allows the users to add new rows (using a Postback) on the the fly and save this information back to the database. I pretty much have my control like the one in the Docs for Creating a DataBound Templated control.
Here is how I would like things to work: 1. The user adds new rows (this works) 2. They hit save and the information is stored to the database (works too) 3. The information is then rebinded to the control (this doesn't work). I want to reflect the values in the database without completely reloading the page. It seems there is viewstate data that is conflicting with what is being rendered in the controls of the individual rows.
I don't want to have to reload the page from scratch. How can I do this? ******************************************************** ******************************************************** Here is some of my code for the main control:
private ArrayList _Items = new ArrayList(); public ICollection Items { get { return ((ICollection)this._Items); } }
public int ItemCount { get { if (ViewState["ItemCount"] == null) return -1; else return (int)ViewState["ItemCount"]; } set { ViewState["ItemCount"] = value; } }
protected void AddRow_Command(Object Src, CommandEventArgs E) { NumberOfRowsToAdd = 1; } protected override void OnPreRender(EventArgs E) { base.OnPreRender(E); for (int i=0;i<NumberOfRowsToAdd;i++) CreateItem(null);
ItemCount += NumberOfRowsToAdd; } protected override void OnDataBinding(EventArgs E) { base.OnDataBinding(E); if (this.DataSource != null) { Controls.Clear(); ClearChildViewState();
CreateControlHierarchy(true); ChildControlsCreated = true;
TrackViewState(); } } protected override void CreateChildControls() { if (ItemCount != -1) CreateControlHierarchy(false); } private void CreateControlHierarchy(bool useDataSource) { this.Controls.Add(Details);
//Add Header Row string[] Headings = {"Delete","Date From","Date To","Percent","Months"}; this.Details.Rows.Add(new TableRow()); for (int i=0;i<Headings.GetLength(0);i++) { this.Details.Rows[0].Cells.Add(new TableCell()); this.Details.Rows[0].Cells[i].Controls.Add(new LiteralControl(Headings[i])); this.Details.Rows[0].Cells[i].CssClass = "EztControlDetailHeader"; }
Add AddRow Button this.Details.Rows.Add(new TableRow()); this.Details.Rows[1].Cells.Add(new TableCell()); this.Details.Rows[1].Cells[0].ColumnSpan = Headings.GetLength(0); this.Details.Rows[1].Cells[0].Controls.Add(AddButton); this.Controls.Add(AddButton);
AddButton.ToolTip = "Add a new Rent Step row"; AddButton.Text = "Add Rent Step"; AddButton.Command += new CommandEventHandler(this.AddRow_Command);
IEnumerable dataSource = null; if (useDataSource == false) { if (ItemCount != -1) dataSource = new DummyDataSource(ItemCount); } else dataSource = this.DataSource.Items;
int count = -1; if (dataSource != null) { count = 0; foreach (object dataItem in dataSource) { CreateItem(dataItem); count++; } }
if (useDataSource) ItemCount = ((dataSource != null) ? count : -1); } private void CreateItem(object dataItem) { EztLeaseRentAbatementDetail myDetail = new EztLeaseRentAbatementDetail(); myDetail.EnsureCreated(); this.Details.Rows.Add(myDetail); this._Items.Add(myDetail); if (dataItem != null) myDetail.DataSource = (LeaseRentAbatementDetailObj)dataItem; } ******************************************************** ******************************************************** And Here's the row control which is based on TableRow:
public EztTextBoxDate BeginDate = new EztTextBoxDate(); public EztTextBoxDate EndDate = new EztTextBoxDate(); public EztTextBoxDecimal AbatementPercent = new EztTextBoxDecimal(); public EztTextBoxInt AbatementMonths = new EztTextBoxInt();
private TableCell myDeleteCell;
private LeaseRentAbatementDetailObj _dataSource = null; public LeaseRentAbatementDetailObj DataSource { get { return this._dataSource; } set { this._dataSource = value; } } protected override void OnDataBinding(EventArgs E) { base.OnDataBinding(E); if (this.DataSource != null) { if (DataSource.BeginDate.CompareTo(DateTime.MinValue) == 0) this.BeginDate.Text = ""; else this.BeginDate.Text = DataSource.BeginDate.ToShortDateString(); if (DataSource.EndDate.CompareTo(DateTime.MinValue) == 0) this.EndDate.Text = ""; else this.EndDate.Text = DataSource.EndDate.ToShortDateString(); this.AbatementPercent.Text = DataSource.AbatementPercent.ToString(); this.AbatementMonths.Text = DataSource.AbatementMonths.ToString(); } }
protected override void CreateChildControls() { this.Cells.Add(new EztControlDetailCell()); this.Cells[0].Controls.Add(new CheckBox()); myDeleteCell = this.Cells[0]; this.Cells[0].Width = Unit.Pixel(50); this.Cells[0].HorizontalAlign = HorizontalAlign.Center;
this.Cells.Add(new EztControlDetailCell()); this.Cells[1].Controls.Add(BeginDate);
this.Cells.Add(new EztControlDetailCell()); this.Cells[2].Controls.Add(EndDate);
this.Cells.Add(new EztControlDetailCell()); this.Cells[3].Controls.Add(AbatementPercent);
this.Cells.Add(new EztControlDetailCell()); this.Cells[4].Controls.Add(AbatementMonths);
BeginDate.MaxLength = 30; BeginDate.Columns = 10;
EndDate.MaxLength = 30; EndDate.Columns = 10;
AbatementPercent.MaxLength = 30; AbatementPercent.Columns = 10;
AbatementMonths.MaxLength = 30; AbatementMonths.Columns = 10; }
| [aspngcontrolscs] member Click here to reveal e-mail address = YOUR ID | http://www.asplists.com/asplists/aspngcontrolscs.asp = JOIN/QUIT | http://www.asplists.com/search = SEARCH Archives
| [aspngcontrolscs] member Click here to reveal e-mail address = YOUR ID | http://www.asplists.com/asplists/aspngcontrolscs.asp = JOIN/QUIT | http://www.asplists.com/search = SEARCH Archives ------------------------------------------------------------- This email and any files transmitted are confidential and intended solely for the use of the individual or entity to which they are addressed, whose privacy should be respected. Any views or opinions are solely those of the author and do not necessarily represent those of the Trencor Group, or any of its representatives, unless specifically stated. Email transmission cannot be guaranteed to be secure, error free or without virus contamination. The sender therefore accepts no liability for any errors or omissions in the contents of this message, nor for any virus infection that might result from opening this message. Trencor is not responsible in the event of any third party interception of this email. If you have received this email in error please notify Click here to reveal e-mail address For more information about Trencor, visit www.trencor.net
|
|
| |
|
| |
| Ray Houston |
Does anyone have any ideas on re DataBinding? I'm desperate for some help on this.
thanks, p.s. Sorry, I don't have a VB version. I also didn't post the complete code, but I think the important parts are there.
*************************************
Opps. I forgot to mention that the problems occurs after a postback that happens after the postback which rebinds the data. Like this 1.Save button clicked 2.Postback - Data is saved and rebinded 3.Page is rendered (looks ok) 4.Another button is click that causes a postback (can be any button) 5.Postback 6.Page is rendered but with problems
thanks, -Ray
************************************* Hi, I've created an editable grid which allows the users to add new rows (using a Postback) on the the fly and save this information back to the database. I pretty much have my control like the one in the Docs for Creating a DataBound Templated control.
Here is how I would like things to work: 1. The user adds new rows (this works) 2. They hit save and the information is stored to the database (works too) 3. The information is then rebinded to the control (this doesn't work). I want to reflect the values in the database without completely reloading the page. It seems there is viewstate data that is conflicting with what is being rendered in the controls of the individual rows.
I don't want to have to reload the page from scratch. How can I do this? ******************************************************** ******************************************************** Here is some of my code for the main control:
private ArrayList _Items = new ArrayList(); public ICollection Items { get { return ((ICollection)this._Items); } }
public int ItemCount { get { if (ViewState["ItemCount"] == null) return -1; else return (int)ViewState["ItemCount"]; } set { ViewState["ItemCount"] = value; } }
protected void AddRow_Command(Object Src, CommandEventArgs E) { NumberOfRowsToAdd = 1; } protected override void OnPreRender(EventArgs E) { base.OnPreRender(E); for (int i=0;i<NumberOfRowsToAdd;i++) CreateItem(null);
ItemCount += NumberOfRowsToAdd; } protected override void OnDataBinding(EventArgs E) { base.OnDataBinding(E); if (this.DataSource != null) { Controls.Clear(); ClearChildViewState();
CreateControlHierarchy(true); ChildControlsCreated = true;
TrackViewState(); } } protected override void CreateChildControls() { if (ItemCount != -1) CreateControlHierarchy(false); } private void CreateControlHierarchy(bool useDataSource) { this.Controls.Add(Details);
//Add Header Row string[] Headings = {"Delete","Date From","Date To","Percent","Months"}; this.Details.Rows.Add(new TableRow()); for (int i=0;i<Headings.GetLength(0);i++) { this.Details.Rows[0].Cells.Add(new TableCell()); this.Details.Rows[0].Cells[i].Controls.Add(new LiteralControl(Headings[i])); this.Details.Rows[0].Cells[i].CssClass = "EztControlDetailHeader"; }
Add AddRow Button this.Details.Rows.Add(new TableRow()); this.Details.Rows[1].Cells.Add(new TableCell()); this.Details.Rows[1].Cells[0].ColumnSpan = Headings.GetLength(0); this.Details.Rows[1].Cells[0].Controls.Add(AddButton); this.Controls.Add(AddButton);
AddButton.ToolTip = "Add a new Rent Step row"; AddButton.Text = "Add Rent Step"; AddButton.Command += new CommandEventHandler(this.AddRow_Command);
IEnumerable dataSource = null; if (useDataSource == false) { if (ItemCount != -1) dataSource = new DummyDataSource(ItemCount); } else dataSource = this.DataSource.Items;
int count = -1; if (dataSource != null) { count = 0; foreach (object dataItem in dataSource) { CreateItem(dataItem); count++; } }
if (useDataSource) ItemCount = ((dataSource != null) ? count : -1); } private void CreateItem(object dataItem) { EztLeaseRentAbatementDetail myDetail = new EztLeaseRentAbatementDetail(); myDetail.EnsureCreated(); this.Details.Rows.Add(myDetail); this._Items.Add(myDetail); if (dataItem != null) myDetail.DataSource = (LeaseRentAbatementDetailObj)dataItem; } ******************************************************** ******************************************************** And Here's the row control which is based on TableRow:
public EztTextBoxDate BeginDate = new EztTextBoxDate(); public EztTextBoxDate EndDate = new EztTextBoxDate(); public EztTextBoxDecimal AbatementPercent = new EztTextBoxDecimal(); public EztTextBoxInt AbatementMonths = new EztTextBoxInt();
private TableCell myDeleteCell;
private LeaseRentAbatementDetailObj _dataSource = null; public LeaseRentAbatementDetailObj DataSource { get { return this._dataSource; } set { this._dataSource = value; } } protected override void OnDataBinding(EventArgs E) { base.OnDataBinding(E); if (this.DataSource != null) { if (DataSource.BeginDate.CompareTo(DateTime.MinValue) == 0) this.BeginDate.Text = ""; else this.BeginDate.Text = DataSource.BeginDate.ToShortDateString(); if (DataSource.EndDate.CompareTo(DateTime.MinValue) == 0) this.EndDate.Text = ""; else this.EndDate.Text = DataSource.EndDate.ToShortDateString(); this.AbatementPercent.Text = DataSource.AbatementPercent.ToString(); this.AbatementMonths.Text = DataSource.AbatementMonths.ToString(); } }
protected override void CreateChildControls() { this.Cells.Add(new EztControlDetailCell()); this.Cells[0].Controls.Add(new CheckBox()); myDeleteCell = this.Cells[0]; this.Cells[0].Width = Unit.Pixel(50); this.Cells[0].HorizontalAlign = HorizontalAlign.Center;
this.Cells.Add(new EztControlDetailCell()); this.Cells[1].Controls.Add(BeginDate);
this.Cells.Add(new EztControlDetailCell()); this.Cells[2].Controls.Add(EndDate);
this.Cells.Add(new EztControlDetailCell()); this.Cells[3].Controls.Add(AbatementPercent);
this.Cells.Add(new EztControlDetailCell()); this.Cells[4].Controls.Add(AbatementMonths);
BeginDate.MaxLength = 30; BeginDate.Columns = 10;
EndDate.MaxLength = 30; EndDate.Columns = 10;
AbatementPercent.MaxLength = 30; AbatementPercent.Columns = 10;
AbatementMonths.MaxLength = 30; AbatementMonths.Columns = 10; }
| [aspngcontrolscs] member Click here to reveal e-mail address = YOUR ID | http://www.asplists.com/asplists/aspngcontrolscs.asp = JOIN/QUIT | http://www.asplists.com/search = SEARCH Archives
|
|
| |
|
| |
| Ray Houston |
I just noticed I didn't include the OnPreRender method in the first control. Here it is:
protected override void OnPreRender(EventArgs E) { base.OnPreRender(E); for (int i=0;i<NumberOfRowsToAdd;i++) CreateItem(null); ItemCount += NumberOfRowsToAdd; }
-----Original Message----- From: Ray Houston [mailto:Click here to reveal e-mail address] Sent: Thursday, April 18, 2002 1:49 PM To: aspngcontrolscs Subject: [aspngcontrolscs] Building a databound Control with rows
Opps. I forgot to mention that the problems occurs after a postback that happens after the postback which rebinds the data. Like this 1.Save button clicked 2.Postback - Data is saved and rebinded 3.Page is rendered (looks ok) 4.Another button is click that causes a postback (can be any button) 5.Postback 6.Page is rendered but with problems
thanks, -Ray
************************************* Hi, I've created an editable grid which allows the users to add new rows (using a Postback) on the the fly and save this information back to the database. I pretty much have my control like the one in the Docs for Creating a DataBound Templated control.
Here is how I would like things to work: 1. The user adds new rows (this works) 2. They hit save and the information is stored to the database (works too) 3. The information is then rebinded to the control (this doesn't work). I want to reflect the values in the database without completely reloading the page. It seems there is viewstate data that is conflicting with what is being rendered in the controls of the individual rows.
I don't want to have to reload the page from scratch. How can I do this? ******************************************************** ******************************************************** Here is some of my code for the main control:
private ArrayList _Items = new ArrayList(); public ICollection Items { get { return ((ICollection)this._Items); } }
public int ItemCount { get { if (ViewState["ItemCount"] == null) return -1; else return (int)ViewState["ItemCount"]; } set { ViewState["ItemCount"] = value; } }
protected void AddRow_Command(Object Src, CommandEventArgs E) { NumberOfRowsToAdd = 1; } protected override void OnPreRender(EventArgs E) { base.OnPreRender(E); for (int i=0;i<NumberOfRowsToAdd;i++) CreateItem(null);
ItemCount += NumberOfRowsToAdd; } protected override void OnDataBinding(EventArgs E) { base.OnDataBinding(E); if (this.DataSource != null) { Controls.Clear(); ClearChildViewState();
CreateControlHierarchy(true); ChildControlsCreated = true;
TrackViewState(); } } protected override void CreateChildControls() { if (ItemCount != -1) CreateControlHierarchy(false); } private void CreateControlHierarchy(bool useDataSource) { this.Controls.Add(Details);
//Add Header Row string[] Headings = {"Delete","Date From","Date To","Percent","Months"}; this.Details.Rows.Add(new TableRow()); for (int i=0;i<Headings.GetLength(0);i++) { this.Details.Rows[0].Cells.Add(new TableCell()); this.Details.Rows[0].Cells[i].Controls.Add(new LiteralControl(Headings[i])); this.Details.Rows[0].Cells[i].CssClass = "EztControlDetailHeader"; }
Add AddRow Button this.Details.Rows.Add(new TableRow()); this.Details.Rows[1].Cells.Add(new TableCell()); this.Details.Rows[1].Cells[0].ColumnSpan = Headings.GetLength(0); this.Details.Rows[1].Cells[0].Controls.Add(AddButton); this.Controls.Add(AddButton);
AddButton.ToolTip = "Add a new Rent Step row"; AddButton.Text = "Add Rent Step"; AddButton.Command += new CommandEventHandler(this.AddRow_Command);
IEnumerable dataSource = null; if (useDataSource == false) { if (ItemCount != -1) dataSource = new DummyDataSource(ItemCount); } else dataSource = this.DataSource.Items;
int count = -1; if (dataSource != null) { count = 0; foreach (object dataItem in dataSource) { CreateItem(dataItem); count++; } }
if (useDataSource) ItemCount = ((dataSource != null) ? count : -1); } private void CreateItem(object dataItem) { EztLeaseRentAbatementDetail myDetail = new EztLeaseRentAbatementDetail(); myDetail.EnsureCreated(); this.Details.Rows.Add(myDetail); this._Items.Add(myDetail); if (dataItem != null) myDetail.DataSource = (LeaseRentAbatementDetailObj)dataItem; } ******************************************************** ******************************************************** And Here's the row control which is based on TableRow:
public EztTextBoxDate BeginDate = new EztTextBoxDate(); public EztTextBoxDate EndDate = new EztTextBoxDate(); public EztTextBoxDecimal AbatementPercent = new EztTextBoxDecimal(); public EztTextBoxInt AbatementMonths = new EztTextBoxInt();
private TableCell myDeleteCell;
private LeaseRentAbatementDetailObj _dataSource = null; public LeaseRentAbatementDetailObj DataSource { get { return this._dataSource; } set { this._dataSource = value; } } protected override void OnDataBinding(EventArgs E) { base.OnDataBinding(E); if (this.DataSource != null) { if (DataSource.BeginDate.CompareTo(DateTime.MinValue) == 0) this.BeginDate.Text = ""; else this.BeginDate.Text = DataSource.BeginDate.ToShortDateString(); if (DataSource.EndDate.CompareTo(DateTime.MinValue) == 0) this.EndDate.Text = ""; else this.EndDate.Text = DataSource.EndDate.ToShortDateString(); this.AbatementPercent.Text = DataSource.AbatementPercent.ToString(); this.AbatementMonths.Text = DataSource.AbatementMonths.ToString(); } }
protected override void CreateChildControls() { this.Cells.Add(new EztControlDetailCell()); this.Cells[0].Controls.Add(new CheckBox()); myDeleteCell = this.Cells[0]; this.Cells[0].Width = Unit.Pixel(50); this.Cells[0].HorizontalAlign = HorizontalAlign.Center;
this.Cells.Add(new EztControlDetailCell()); this.Cells[1].Controls.Add(BeginDate);
this.Cells.Add(new EztControlDetailCell()); this.Cells[2].Controls.Add(EndDate);
this.Cells.Add(new EztControlDetailCell()); this.Cells[3].Controls.Add(AbatementPercent);
this.Cells.Add(new EztControlDetailCell()); this.Cells[4].Controls.Add(AbatementMonths);
BeginDate.MaxLength = 30; BeginDate.Columns = 10;
EndDate.MaxLength = 30; EndDate.Columns = 10;
AbatementPercent.MaxLength = 30; AbatementPercent.Columns = 10;
AbatementMonths.MaxLength = 30; AbatementMonths.Columns = 10; }
| [aspngcontrolscs] member Click here to reveal e-mail address = YOUR ID | http://www.asplists.com/asplists/aspngcontrolscs.asp = JOIN/QUIT | http://www.asplists.com/search = SEARCH Archives
|
|
| |
|
| |
| Deyan Petrov |
I am doing the same thing. My Grid however uses clientside javascript to add new rows or delete/modify existing. On Postback I update the database and after that using the posted back values recreate the Grid. I use the AddSubParsedObject override in TemplateItem class and SetDataBoundString(index,value). Still not finished it though, because have no free time to work on it.
Regards, Deyan Petrov
----- Original Message ----- From: "Ray Houston" <Click here to reveal e-mail address> To: "aspngcontrolscs" <Click here to reveal e-mail address> Sent: Friday, April 19, 2002 4:19 AM Subject: [aspngcontrolscs] RE: Building a databound Control with rows
[Original message clipped]
|
|
| |
|
| |
| Ray Houston |
I fixed the problem without fully understanding the answer. I had two controls defined at the class level like so: private LinkButton AddButton = new LinkButton();
so to fix the problem I put this in OnDataBinding: this.AddButton = new LinkButton();
I guess the main control needs a new instance of the child controls to clear everything out? Can someone explain this to me?
thanks,
-----Original Message----- From: Ray Houston [mailto:Click here to reveal e-mail address] Sent: Thursday, April 18, 2002 9:24 PM To: aspngcontrolscs Subject: [aspngcontrolscs] RE: Building a databound Control with rows
I just noticed I didn't include the OnPreRender method in the first control. Here it is:
protected override void OnPreRender(EventArgs E) { base.OnPreRender(E); for (int i=0;i<NumberOfRowsToAdd;i++) CreateItem(null); ItemCount += NumberOfRowsToAdd; }
-----Original Message----- From: Ray Houston [mailto:Click here to reveal e-mail address] Sent: Thursday, April 18, 2002 1:49 PM To: aspngcontrolscs Subject: [aspngcontrolscs] Building a databound Control with rows
Opps. I forgot to mention that the problems occurs after a postback that happens after the postback which rebinds the data. Like this 1.Save button clicked 2.Postback - Data is saved and rebinded 3.Page is rendered (looks ok) 4.Another button is click that causes a postback (can be any button) 5.Postback 6.Page is rendered but with problems
thanks, -Ray
************************************* Hi, I've created an editable grid which allows the users to add new rows (using a Postback) on the the fly and save this information back to the database. I pretty much have my control like the one in the Docs for Creating a DataBound Templated control.
Here is how I would like things to work: 1. The user adds new rows (this works) 2. They hit save and the information is stored to the database (works too) 3. The information is then rebinded to the control (this doesn't work). I want to reflect the values in the database without completely reloading the page. It seems there is viewstate data that is conflicting with what is being rendered in the controls of the individual rows.
I don't want to have to reload the page from scratch. How can I do this? ******************************************************** ******************************************************** Here is some of my code for the main control:
private ArrayList _Items = new ArrayList(); public ICollection Items { get { return ((ICollection)this._Items); } }
public int ItemCount { get { if (ViewState["ItemCount"] == null) return -1; else return (int)ViewState["ItemCount"]; } set { ViewState["ItemCount"] = value; } }
protected void AddRow_Command(Object Src, CommandEventArgs E) { NumberOfRowsToAdd = 1; } protected override void OnPreRender(EventArgs E) { base.OnPreRender(E); for (int i=0;i<NumberOfRowsToAdd;i++) CreateItem(null);
ItemCount += NumberOfRowsToAdd; } protected override void OnDataBinding(EventArgs E) { base.OnDataBinding(E); if (this.DataSource != null) { Controls.Clear(); ClearChildViewState();
CreateControlHierarchy(true); ChildControlsCreated = true;
TrackViewState(); } } protected override void CreateChildControls() { if (ItemCount != -1) CreateControlHierarchy(false); } private void CreateControlHierarchy(bool useDataSource) { this.Controls.Add(Details);
//Add Header Row string[] Headings = {"Delete","Date From","Date To","Percent","Months"}; this.Details.Rows.Add(new TableRow()); for (int i=0;i<Headings.GetLength(0);i++) { this.Details.Rows[0].Cells.Add(new TableCell()); this.Details.Rows[0].Cells[i].Controls.Add(new LiteralControl(Headings[i])); this.Details.Rows[0].Cells[i].CssClass = "EztControlDetailHeader"; }
Add AddRow Button this.Details.Rows.Add(new TableRow()); this.Details.Rows[1].Cells.Add(new TableCell()); this.Details.Rows[1].Cells[0].ColumnSpan = Headings.GetLength(0); this.Details.Rows[1].Cells[0].Controls.Add(AddButton); this.Controls.Add(AddButton);
AddButton.ToolTip = "Add a new Rent Step row"; AddButton.Text = "Add Rent Step"; AddButton.Command += new CommandEventHandler(this.AddRow_Command);
IEnumerable dataSource = null; if (useDataSource == false) { if (ItemCount != -1) dataSource = new DummyDataSource(ItemCount); } else dataSource = this.DataSource.Items;
int count = -1; if (dataSource != null) { count = 0; foreach (object dataItem in dataSource) { CreateItem(dataItem); count++; } }
if (useDataSource) ItemCount = ((dataSource != null) ? count : -1); } private void CreateItem(object dataItem) { EztLeaseRentAbatementDetail myDetail = new EztLeaseRentAbatementDetail(); myDetail.EnsureCreated(); this.Details.Rows.Add(myDetail); this._Items.Add(myDetail); if (dataItem != null) myDetail.DataSource = (LeaseRentAbatementDetailObj)dataItem; } ******************************************************** ******************************************************** And Here's the row control which is based on TableRow:
public EztTextBoxDate BeginDate = new EztTextBoxDate(); public EztTextBoxDate EndDate = new EztTextBoxDate(); public EztTextBoxDecimal AbatementPercent = new EztTextBoxDecimal(); public EztTextBoxInt AbatementMonths = new EztTextBoxInt();
private TableCell myDeleteCell;
private LeaseRentAbatementDetailObj _dataSource = null; public LeaseRentAbatementDetailObj DataSource { get { return this._dataSource; } set { this._dataSource = value; } } protected override void OnDataBinding(EventArgs E) { base.OnDataBinding(E); if (this.DataSource != null) { if (DataSource.BeginDate.CompareTo(DateTime.MinValue) == 0) this.BeginDate.Text = ""; else this.BeginDate.Text = DataSource.BeginDate.ToShortDateString(); if (DataSource.EndDate.CompareTo(DateTime.MinValue) == 0) this.EndDate.Text = ""; else this.EndDate.Text = DataSource.EndDate.ToShortDateString(); this.AbatementPercent.Text = DataSource.AbatementPercent.ToString(); this.AbatementMonths.Text = DataSource.AbatementMonths.ToString(); } }
protected override void CreateChildControls() { this.Cells.Add(new EztControlDetailCell()); this.Cells[0].Controls.Add(new CheckBox()); myDeleteCell = this.Cells[0]; this.Cells[0].Width = Unit.Pixel(50); this.Cells[0].HorizontalAlign = HorizontalAlign.Center;
this.Cells.Add(new EztControlDetailCell()); this.Cells[1].Controls.Add(BeginDate);
this.Cells.Add(new EztControlDetailCell()); this.Cells[2].Controls.Add(EndDate);
this.Cells.Add(new EztControlDetailCell()); this.Cells[3].Controls.Add(AbatementPercent);
this.Cells.Add(new EztControlDetailCell()); this.Cells[4].Controls.Add(AbatementMonths);
BeginDate.MaxLength = 30; BeginDate.Columns = 10;
EndDate.MaxLength = 30; EndDate.Columns = 10;
AbatementPercent.MaxLength = 30; AbatementPercent.Columns = 10;
AbatementMonths.MaxLength = 30; AbatementMonths.Columns = 10; }
| [aspngcontrolscs] member Click here to reveal e-mail address = YOUR ID | http://www.asplists.com/asplists/aspngcontrolscs.asp = JOIN/QUIT | http://www.asplists.com/search = SEARCH Archives
| [aspngcontrolscs] member Click here to reveal e-mail address = YOUR ID | http://www.asplists.com/asplists/aspngcontrolscs.asp = JOIN/QUIT | http://www.asplists.com/search = SEARCH Archives
|
|
| |
|
|
|
|
|