Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 14th, 2004, 09:08 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dynamically displaying textboxes and label

Hi
How to display textboxes and labels inside the table dynamically in C#.
I have to pass the textbox id and text in the stored procedure for storing into the database.
I written like this :

TextBox TempTextBox = (TextBox)PlaceHolder1.FindControl("textBox1");

With the help of this initialisation, I am unable to pass the text box value and id and I dont know how to display inside the table.
I hope this time I ll get my answer.


Lily

 
Old December 15th, 2004, 06:59 PM
Authorized User
 
Join Date: Jan 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to rathbird
Default

I'm not too clear about what you're asking. Say you have a table with the ID myTable, a row with the ID myTableRow, and a cell myTableCell, and on some event you want to create a textbox with a value and an id, here's how you would do it:

private void Page_Load(object sender, System.EventArgs e)
{
  //I assume you're getting your values correctly from SQL
  // also assuming that you've passed your values into variables
  // which i'll name myTextBoxID and myTextBoxValue

  //Create a textbox control

  TextBox _tb = new TextBox();

  //Set the id of the textbox

  _tb.ID = myTextBoxID;

  //Set the value of the textbox

  _tb.Text = myTextBoxValue;

  //Add the control to your table cell

  myTableCellID.Controls.Add(_tb);

}

Now I put the code to build the textbox in the page_load event handler, but you would probably make it a separate function call. Also, remember that dynamic content must be built every time you post the page; for some reason it disappears on postback if you don't call it again.

Also, it is very easy to create Tables, rows, and cells dynamically, and if you need the code to do this as well, please send me an email. I hope this helps.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Regular Expression Validator displaying a label thomaswharmanjr26 C# 0 January 25th, 2008 03:38 PM
Dynamically populate a label MaxGay2 VB.NET 2002/2003 Basics 27 November 15th, 2006 04:17 PM
Dynamically generated textboxes and their values Frode ASP.NET 2.0 Basics 1 April 17th, 2006 03:46 PM
Dynamically Generating Textboxes Maxood PHP How-To 6 March 9th, 2006 09:14 AM
Using the IDs of dynamically created textboxes mahulda ASP.NET 1.0 and 1.1 Basics 3 February 17th, 2004 05:05 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.