4 Replies - 1963 Views - Last Post: 22 October 2007 - 01:53 AM Rate Topic: -----

#1 phannon666  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 12-October 07

Help adding controls dynamically

Posted 12 October 2007 - 03:36 AM

Hi there, I have a similar issue. I'm attempting to load some SQL data to a dynamic table, all the data loads fine, the problem is formatting the layout of two particular cells. I understand whats going on, but cannot find a solution. What i'm attempting to do is for each text item in this particular db (loaded into an array) list the text, and beneath each item, display a button. The problem is it will only do this correct format for the last item, as it is getting overwritten. So I think what I need to be doing is appending to this cell somehow, thanks in advance for any further help. As you will see its not the best of code atm but its been mashed and mixed so many times, any questions about my code will be quickly responded to.

Pete.

for (int i = 0; i < 4; i++)
			{
				TableRow tr = new TableRow();
				tr.BorderWidth = 1;
				TableRow r = new TableRow();
				r.BorderWidth = 1;
				TableCell tc = new TableCell();
				tc.BorderWidth = 1;
				TableCell tc2 = new TableCell();
				tc2.BorderWidth = 1;
				TableCell tcb = new TableCell();
				tcb.BorderWidth = 1;
				tc2.Width = 400;
				Label l = new Label();
				l.Font.Bold = true;
				Label l2 = new Label();			   

				if (!(cemsDescArray[f].Equals(0)))
				{
					if (i.Equals(0))
					{
						l.Text = "CEMS ID: ";
						l2.Text = cemsDescArray[a].ToString();
						a++;
						tc.Controls.Add(l);
						tc2.Controls.Add(l2);
						r.Cells.Add(tc);
						r.Cells.Add(tc2);
					}
					if (i.Equals(1))
					{
						l.Text = "Summary: ";
						String x = (string)descArray[b];
						String newT = x.Replace("##APO##", "\'");
						l2.Text = newT;
						b++;
						tc.Controls.Add(l);
						tc2.Controls.Add(l2);
						r.Cells.Add(tc);
						r.Cells.Add(tc2);
					}
					if (i.Equals(2))
					{
						l.Text = "Description: ";
						String xx = "";
						newX = "";
						tc.Controls.Add(l);
						r.Cells.Add(tc);
						foreach (String str in extDescArray)
						{
							xx += str + "<br/><br/>";
							newX = xx.Replace("##APO##", "\'");
							l2.Text = newX;
							//tc2 = new TableCell();
							editInfo = new Button();
							editInfo.Attributes.Add("AutoPostBack", "true");
							editInfo.Text = "Edit Description";
							editInfo.Click += new EventHandler(editInfo_Click);

							tc2.Controls.Add(l2);
							tc2.Controls.Add(editInfo);
							r.Cells.Add(tc2);
						}											
						c++;
					}
					if (i.Equals(3))
					{					   
						l.Text = "Solution: ";
						String xxx = "";
						newTe = "";
						tc.Controls.Add(l);
						r.Cells.Add(tc);
						foreach (String str in solutionsArray)
						{
							xxx += str + "<br/><br/>";
							newTe = xxx.Replace("##APO##", "\'");
							l2.Text = newTe;
							//tc2 = new TableCell();
							editSolution = new Button();
							editSolution.Attributes.Add("AutoPostBack", "true");
							editSolution.Text = "Edit Solution";
							editSolution.Click += new EventHandler(editSolution_Click);
							
							tc2.Controls.Add(l2);
							tc2.Controls.Add(editSolution);
							r.Cells.Add(tc2);
						}											
						d++;
						f++;
					}

					tc.HorizontalAlign = HorizontalAlign.Left;
					tc.VerticalAlign = VerticalAlign.Top;				  
					//r.Cells.Add(tc);
					//r.Cells.Add(tc2);
					table1.Rows.Add(r);
				}
			}			

			form1.Controls.Add(table1);


Is This A Good Question/Topic? 0
  • +

Replies To: Help adding controls dynamically

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1658
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Help adding controls dynamically

Posted 12 October 2007 - 05:04 AM

@phannon666, I split this into its own topic because
  • Its never nice to take over someone else's thread with your question (even though they may be similar)
  • History shows you'll get a better response if you open your own thread
    • This doesn't count with like this video and song of the day threads and similar here

Once Ive had a chance to drink some coffee Ill look over your code and try to help :)
Was This Post Helpful? 0
  • +
  • -

#3 phannon666  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 12-October 07

Re: Help adding controls dynamically

Posted 12 October 2007 - 05:31 AM

View PostPsychoCoder, on 12 Oct, 2007 - 05:04 AM, said:

@phannon666, I split this into its own topic because
  • Its never nice to take over someone else's thread with your question (even though they may be similar)
  • History shows you'll get a better response if you open your own thread
    • This doesn't count with like this video and song of the day threads and similar here
Once Ive had a chance to drink some coffee Ill look over your code and try to help :)


ty, sorry I'm used to the whole "always better to post in an existing thread than start a new one" but meh, look forward to your response, I'm gonna get a lemsip lol
Was This Post Helpful? 0
  • +
  • -

#4 phannon666  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 12-October 07

Re: Help adding controls dynamically

Posted 16 October 2007 - 07:49 AM

Hey, sorry havn't been around in a few days. Did you manage to have a look at my code?

Cheers
Was This Post Helpful? 0
  • +
  • -

#5 phannon666  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 12-October 07

Re: Help adding controls dynamically

Posted 22 October 2007 - 01:53 AM

hello??
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1