control inheriting from CompositeDataBoundControl doesn't retreive it's state information.

U

Umut Tezduyar

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;

}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top