Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > CompositeDataBoundControl doesn't retreive it's state information.

Reply
Thread Tools

CompositeDataBoundControl doesn't retreive it's state information.

 
 
Umut Tezduyar
Guest
Posts: n/a
 
      07-05-2006
I have a control derived from ComposeteDataBoundControl. Control doesn't
retreive it's state information. I am going to frick out! What should I do
more?
I added two codes. One is for Default.aspx to Test the control
"SampleDataBound". When I click to the "Refresh" button here, the data
displayed in the SampleDataBound control become lost.

----------------------------------------

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server" type="text/C#">


protected override void OnLoad(EventArgs e)

{

base.OnLoad(e);

if (!Page.IsPostBack)

{

System.Collections.Generic.List<string> list = new
System.Collections.Generic.List<string>();

list.Add("UMUT");

list.Add("Mehmet");

list.Add("Hasan");

this.d.DataSource = list;

this.d.DataBind();

}

}

</script>

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

<form id="form1" runat="server">

<div>

<Test:SampleDataBound runat="server" ID="d" EnableViewState="true" />

</div>

<asp:Button runat="server" ID="btn" Text="Refresh" />

</form>

</body>

</html>



---------------------------------------

public class SampleDataBound : CompositeDataBoundControl, INamingContainer

{

private Table table;

protected override int
CreateChildControls(System.Collections.IEnumerable dataSource, bool
dataBinding)

{

System.Collections.IEnumerator e = dataSource.GetEnumerator();

table = new Table();

this.Controls.Add(table);

TableRow row = null;

TableCell cell = null;

int count = 0;

while (e.MoveNext())

{

row = new TableRow();

cell = new TableCell();

if (dataBinding)

{

cell.Text = e.Current.ToString();

}

row.Cells.Add(cell);

table.Rows.Add(row);

count++;

}

return count;

}

}






 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      07-05-2006
Hi,

you have lines

row = new TableRow();
cell = new TableCell();
if (dataBinding)
{
cell.Text = e.Current.ToString();
}
row.Cells.Add(cell);
table.Rows.Add(row);

put them in different order

row = new TableRow();
table.Rows.Add(row);
cell = new TableCell();
row.Cells.Add(cell);

if (dataBinding)
{
cell.Text = e.Current.ToString();
}

e.g do databinding after cell is added to the Rows and so on.

Reason is that a ontrol like TableCell starts its lifecycle when it's added
to the Controls collection (even though here it's to Cells, but that's
basically just abstraction) and part of this lifecycle is to start tracking
state.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

"Umut Tezduyar" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I have a control derived from ComposeteDataBoundControl. Control doesn't
> retreive it's state information. I am going to frick out! What should I do
> more?
> I added two codes. One is for Default.aspx to Test the control
> "SampleDataBound". When I click to the "Refresh" button here, the data
> displayed in the SampleDataBound control become lost.
>
> ----------------------------------------
>
> <%@ Page Language="C#" %>
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
>
> <script runat="server" type="text/C#">
>
>
> protected override void OnLoad(EventArgs e)
>
> {
>
> base.OnLoad(e);
>
> if (!Page.IsPostBack)
>
> {
>
> System.Collections.Generic.List<string> list = new
> System.Collections.Generic.List<string>();
>
> list.Add("UMUT");
>
> list.Add("Mehmet");
>
> list.Add("Hasan");
>
> this.d.DataSource = list;
>
> this.d.DataBind();
>
> }
>
> }
>
> </script>
>
> <html xmlns="http://www.w3.org/1999/xhtml">
>
> <head runat="server">
>
> <title>Untitled Page</title>
>
> </head>
>
> <body>
>
> <form id="form1" runat="server">
>
> <div>
>
> <Test:SampleDataBound runat="server" ID="d" EnableViewState="true" />
>
> </div>
>
> <asp:Button runat="server" ID="btn" Text="Refresh" />
>
> </form>
>
> </body>
>
> </html>
>
>
>
> ---------------------------------------
>
> public class SampleDataBound : CompositeDataBoundControl, INamingContainer
>
> {
>
> private Table table;
>
> protected override int
> CreateChildControls(System.Collections.IEnumerable dataSource, bool
> dataBinding)
>
> {
>
> System.Collections.IEnumerator e = dataSource.GetEnumerator();
>
> table = new Table();
>
> this.Controls.Add(table);
>
> TableRow row = null;
>
> TableCell cell = null;
>
> int count = 0;
>
> while (e.MoveNext())
>
> {
>
> row = new TableRow();
>
> cell = new TableCell();
>
> if (dataBinding)
>
> {
>
> cell.Text = e.Current.ToString();
>
> }
>
> row.Cells.Add(cell);
>
> table.Rows.Add(row);
>
> count++;
>
> }
>
> return count;
>
> }
>
> }
>
>
>
>
>
>



 
Reply With Quote
 
 
 
 
Umut Tezduyar
Guest
Posts: n/a
 
      07-06-2006
God Bless you Teemu Keiski. I can't explain how I am happy now.

"Teemu Keiski" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> you have lines
>
> row = new TableRow();
> cell = new TableCell();
> if (dataBinding)
> {
> cell.Text = e.Current.ToString();
> }
> row.Cells.Add(cell);
> table.Rows.Add(row);
>
> put them in different order
>
> row = new TableRow();
> table.Rows.Add(row);
> cell = new TableCell();
> row.Cells.Add(cell);
>
> if (dataBinding)
> {
> cell.Text = e.Current.ToString();
> }
>
> e.g do databinding after cell is added to the Rows and so on.
>
> Reason is that a ontrol like TableCell starts its lifecycle when it's
> added to the Controls collection (even though here it's to Cells, but
> that's basically just abstraction) and part of this lifecycle is to start
> tracking state.
>
> --
> Teemu Keiski
> ASP.NET MVP, AspInsider
> Finland, EU
> http://blogs.aspadvice.com/joteke
>
> "Umut Tezduyar" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>I have a control derived from ComposeteDataBoundControl. Control doesn't
>> retreive it's state information. I am going to frick out! What should I
>> do
>> more?
>> I added two codes. One is for Default.aspx to Test the control
>> "SampleDataBound". When I click to the "Refresh" button here, the data
>> displayed in the SampleDataBound control become lost.
>>
>> ----------------------------------------
>>
>> <%@ Page Language="C#" %>
>>
>> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
>> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
>>
>> <script runat="server" type="text/C#">
>>
>>
>> protected override void OnLoad(EventArgs e)
>>
>> {
>>
>> base.OnLoad(e);
>>
>> if (!Page.IsPostBack)
>>
>> {
>>
>> System.Collections.Generic.List<string> list = new
>> System.Collections.Generic.List<string>();
>>
>> list.Add("UMUT");
>>
>> list.Add("Mehmet");
>>
>> list.Add("Hasan");
>>
>> this.d.DataSource = list;
>>
>> this.d.DataBind();
>>
>> }
>>
>> }
>>
>> </script>
>>
>> <html xmlns="http://www.w3.org/1999/xhtml">
>>
>> <head runat="server">
>>
>> <title>Untitled Page</title>
>>
>> </head>
>>
>> <body>
>>
>> <form id="form1" runat="server">
>>
>> <div>
>>
>> <Test:SampleDataBound runat="server" ID="d" EnableViewState="true" />
>>
>> </div>
>>
>> <asp:Button runat="server" ID="btn" Text="Refresh" />
>>
>> </form>
>>
>> </body>
>>
>> </html>
>>
>>
>>
>> ---------------------------------------
>>
>> public class SampleDataBound : CompositeDataBoundControl,
>> INamingContainer
>>
>> {
>>
>> private Table table;
>>
>> protected override int
>> CreateChildControls(System.Collections.IEnumerable dataSource, bool
>> dataBinding)
>>
>> {
>>
>> System.Collections.IEnumerator e = dataSource.GetEnumerator();
>>
>> table = new Table();
>>
>> this.Controls.Add(table);
>>
>> TableRow row = null;
>>
>> TableCell cell = null;
>>
>> int count = 0;
>>
>> while (e.MoveNext())
>>
>> {
>>
>> row = new TableRow();
>>
>> cell = new TableCell();
>>
>> if (dataBinding)
>>
>> {
>>
>> cell.Text = e.Current.ToString();
>>
>> }
>>
>> row.Cells.Add(cell);
>>
>> table.Rows.Add(row);
>>
>> count++;
>>
>> }
>>
>> return count;
>>
>> }
>>
>> }
>>
>>
>>
>>
>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CompositeControl & CompositeDataBoundControl question Griff ASP .Net 1 10-12-2006 04:35 PM
control inheriting from CompositeDataBoundControl doesn't retreive it's state information. Umut Tezduyar ASP .Net 0 07-02-2006 03:01 AM
control inheriting from CompositeDataBoundControl doesn't retreive it's state information. Umut Tezduyar ASP .Net 0 06-29-2006 08:11 PM
Asp.net2 How can I create my custom CompositeDataBoundControl Dédé ASP .Net Building Controls 2 03-29-2006 07:30 AM
ASP.NET 2.0: problem with CompositeDataboundControl and GetSampleDataSource Jos ASP .Net Building Controls 1 08-17-2005 11:56 AM



Advertisments