Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Problem with dinamically created controls

Reply
Thread Tools

Problem with dinamically created controls

 
 
Rafi
Guest
Posts: n/a
 
      12-01-2003
Hi,

In my database I have table category where I store diffrent categories and
subcategories. I decied to create LinkButtons dinamically with assigned name
of category and its id. I also implemented an event onClick which task is to
create LinkButton subcategories.

When the page is loaded main categories are displayed, when I click on any
of that buttons a subcategories will appear on the screen.

The problem is, when I click on subcategory LinkButton.
All subcategories disappear and only LinkButtons with main categories remain
on the page.

What is wrong?

private void Page_Load(object sender, System.EventArgs e)
{
SqlDataReader dr;

KategorieGlowneProc.Connection.Open(); // stored procedure to get main
categories
dr = KategorieGlowneProc.ExecuteReader();
while ( dr.Read() )
{
LinkButton button = new LinkButton();
button.Attributes.Add("runat","server");
button.ID = dr.GetValue(0).ToString();
button.Text = dr.GetValue(2).ToString();
button.Click += new System.EventHandler(podkategoria);
Page.Controls[1].Controls.Add(button);
Page.Controls[1].Controls.Add(new LiteralControl("<br>"));
}

dr.Close();
KategorieGlowneProc.Connection.Close();
}

private void podkategoria(object sender, System.EventArgs e)
{
LinkButton przycisk = (LinkButton)sender;
SqlDataReader dr;
PodkategorieProc.Parameters["@id_kategorii"].Value = przycisk.ID; //
stored procedure to retrive subcategories
PodkategorieProc.Connection.Open();
dr = PodkategorieProc.ExecuteReader();
while( dr.Read() )
{
LinkButton button = new LinkButton();
button.Attributes.Add("runat","server");
button.ID = dr.GetValue(0).ToString();
button.Text = dr.GetValue(2).ToString();
button.Click += new System.EventHandler(podkategoria);
Page.Controls[1].Controls.Add(new LiteralControl("<br>"));
Page.Controls[1].Controls.Add(button);
}

dr.Close();
PodkategorieProc.Connection.Close();
}


Thanks for help

Rafi


 
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
Dinamically created webcontrol does not fire events =?Utf-8?B?Sm9yZ2UgUmliZWlybw==?= ASP .Net 2 05-25-2007 11:00 AM
dinamically-created checkbox doesn't load it's state Michael.Karn.Ivanov@gmail.com ASP .Net Web Controls 0 08-22-2006 02:53 PM
Why IE doesn't detect events on dinamically created elements? equalium@gmail.com Javascript 2 04-04-2006 07:54 AM
How to read listbox values created dinamically Fabiano ASP .Net Web Controls 0 06-25-2004 06:33 PM
How to align right a table based on another table created dinamically? Leonardo Gangemi ASP .Net 0 04-07-2004 01:11 PM



Advertisments