Dynamic HTML table with textboxes

S

stephen.clancy

I have created a Table on the fly with embedded textboxes. I need to
update a database based on the input to these textboxes. What's the
best approach?

Sample of setup;

Table table = new Table();
table.CellPadding = 5;
table.ID = "Results";
cell = new TableCell();
TextBox tb = new TextBox();
tb.ID = "pass1";
cell.Controls.Add(tb);
row.Cells.Add(cell);
table.Rows.Add(row);
 
O

Onwuka Emeka

Just make sure you are are building the table and adding the controls in the
OnInit of your webform.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Why are you doing this?

Unless you have a very strong reason I suggest you to use a declared table
in HTML.
 
S

stephen.clancy

Even if I define the table in html and then add rows, I still have the
same issues. Other posts I've seen claim that I can do this all with
server side controls. Is that true?
 
I

Ignacio Machin \( .NET/ C# MVP \)

You can use a Repeater and inside you can create your controls.

Just remember that you need to recreate the controls you originally created
dynamicaly.
 
M

Michael Nemtsev

Hello (e-mail address removed),
Even if I define the table in html and then add rows, I still have the
same issues. Other posts I've seen claim that I can do this all with
server side controls. Is that true?

What's the problem? Why not to read table cells either in javaScript or in
serverSide and update DB table? I can't understand what hampers u?

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
G

Guest

To update the database all you need to do is have an update button. This
causes a postback event and in the Button_Click event handler, you get the
value in each of the textbox controls, add it to a parameter of your Sql
statement or stored procedure, and update the database with it.

Is this what you are looking for? There are easier ways than creating
everything dynamically / programmatically (e.g. Databinding to a Repeater or
DataGrid), but you can also bind columns from a query to individual controls
on a page and use a DataAdapter to perform your update.
Peter
 
S

stephen.clancy

I was just trying to create a simple HTML table with textboxes that
update my db on the 'OnFocusOut' event. But I'm open to other methods.
 
G

Guest

onfocusout is a CLIENT SIDE event, so you would need to use javascript to
either make an XMLHTTP Remote Scripting ("AJAX", if you prefer) call, or
otherwise request a page with the info on the querystring which page performs
your database update on the server.
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

Top