.NET Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgramming.NET Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old February 5th, 2002, 12:45 AM
Steve Schofield Steve Schofield is offline
Contributing User
ASP Free God 20th Plane (14500 - 14999 posts)
 
Join Date: Dec 2002
Posts: 14,578 Steve Schofield User rank is Corporal (100 - 500 Reputation Level)Steve Schofield User rank is Corporal (100 - 500 Reputation Level)Steve Schofield User rank is Corporal (100 - 500 Reputation Level)Steve Schofield User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 22
Dynamically generated button does not work!!!

Originally posted by : Richard (xiao_john@yahoo.com)I am doing an e-learning web site. I need to read data out from the access database and then generate button accordingly. After clicking each button, a function is called, but parameter is different. I generate table dynamically and put the buttons inside, but after clicking nothing happens. Where goes wrong???Thanks!!!My Source Code: public string MyConnString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/elearning.mdb"; int i = 0; public void Page_Load(Object src,EventArgs e) { string strComm1 = "select Name from Personal where Priviledge=1 and Valid='Y'"; string strComm2 = "select Name from Personal where Priviledge=2 and Valid='Y'"; string strComm3 = "select Name from Personal where Priviledge=2 and Valid='?'"; string Label1 = "Registered Students:"; string Label2 = "Registered Teachers:"; string Label3 = "Teachers to be approved:"; Display_Page(strComm1, Label1); Display_Page(strComm2, Label2); Display_Page(strComm3, Label3); } void Display_Page(String strComm, String label_text) { OleDbConnection MyConnection = new OleDbConnection(MyConnString); MyConnection.Open(); OleDbCommand myCommand = new OleDbCommand(strComm, MyConnection); OleDbDataReader myReader; myReader = myCommand.ExecuteReader(); TableRow labelRow = new TableRow(); TableCell labelCell = new TableCell(); labelCell.Text = label_text; labelRow.Cells.Add(labelCell); myTable.Rows.Add(labelRow); if(myReader.Read()) { do { TableRow buttonRow = new TableRow(); TableCell dataCell = new TableCell(); dataCell.Text = myReader.GetString(0); buttonRow.Cells.Add(dataCell); TableCell buttonCell = new TableCell(); Button submitButton = new Button(); // Event handler for the button;submitButton.Click += new System.EventHandler(SubmitBtn_Click); submitButton.Width = 80; submitButton.Height = 25; submitButton.Visible = true; submitButton.CommandArgument = myReader.GetString(0); submitButton.Text = "Kick Out!"; submitButton.Style.Add("runat", "server"); buttonRow.Cells.Add(buttonCell); buttonCell.Controls.Add(submitButton); myTable.Rows.Add(buttonRow); i=i+1; } while(myReader.Read()); } else { // Code used to show alarm } myReader.Close(); MyConnection.Close(); } // Function suppose to act after click button;void SubmitBtn_Click(Object sender, EventArgs e) { Button control = ( Button ) sender //Message.Text = "Hey! Please enter your name in the textbox!"; control.Text="good"; }

Reply With Quote
Reply

Viewing: ASP Free ForumsProgramming.NET Development > Dynamically generated button does not work!!!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway