Dynamic control not displayed

P

Peter Wu

Hello Group,

I create a class that inherits from the
System.Web.UI.WebControls.DataGrid class. Basically, what I want to do
is to dynamically add a Table that contains some numbers for paging.
Something like paging indexes but I want to do it manually as I don't
want the DataGrid to cache the entire DataSet.

OK. Here is what I have done.

In the user control, when the Load event, I call a function that add
that Table control to the user control. In the Table control, there
are several LinkButton controls, each of them is bound to a Click
Event. Sample code below:

<code>
TableRow r = new TableRow();

for (int i = 1; i <= n; i++) {
TableCell c = new TableCell();

LinkButton button = new LinkButton();
button.Text = i.ToString();
button.EnableViewState = true;
button.Click += new EventHandler(PageIndex_Click);

c.Controls.Add(button);

r.Cells.Add(c);
}

_table.Rows.Add(r);
</code>

I also defined an event in the class, which is:

<code>
public event EventHandler CustomPageIndexChanged;
</code>

When the PageIndex_Click is fired, I will raise the
CustomPageIndexChanged event to the hosting control, which is a test
WebForm page.

<code>
private void PageIndex_Click(object sender, EventArgs e) {
int PageIndex = Convert.ToInt32(((LinkButton) sender).Text, 10);

for (int i = 0; i < 10; i++) {
LinkButton button = (LinkButton)
_table.Rows[0].Cells.Controls[0];
if (i == PageIndex - 1) {
button.Enabled = false;
}
else {
button.Enabled = true;
}
}

CustomPageIndexChanged(sender, e);
}

</code>

The Event raising is good and the WebForm can receive the
CustomPageIndexChanged event. But the problem is that the Table
disappears.

If I simply comment out the
CustomPageIndexChanged(sender, e); line in the PageIndex_Click(), the
Table object can display well. But of course, the WebForm cannot be
notified.

Does anyone know why and how to fix this problem? Any input will be
highly appreciated. Thanks!!



- Peter
 

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,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top