client side add to a table

  • Thread starter Thread starter John Smith
  • Start date Start date
J

John Smith

ASP.NET SQL C#
I would like to get data from sql server and display it in a web page table
and be able to edit add delete rows without having to do server pulls.
When the user is finished the user pushes commit button and the data is
transferred back to the sql server.
I would appreciate being pointed at an example of how to do this.
thank you
mark
 
Well Datagrid has the Edit,Delete,Add capabilities..
Look for examples on the Net to get started!
 
Are you referring to disconnected model
where Datasets are stored locally via
write xml and later updates the database
in 1 shot?
 
Datagrid is a server component from what I read. If you know how to do these
things on the client with no server trips I would appreciate being shown
how.

Mark
 
Hi Mark,

This is how I do it, it is a little complicated but once you get used it
you'll have no problems:

var tblMyTable = document.getElementById('tblNames');
var Rows = tblMyTable.getElementsByTagName('tr');
var NewRow;
var NewCell;

NewRow = tblMyTable.insertRow(Rows.length);
NewCell = NewRow.insertCell(0);
NewCell.innerHTML = "John";
NewCell = NewRow.insertCell(1);
NewCell.innerHTML = "Smith";

Now you have a table with 1 row and 2 columns. I recommend putting:
debugger; after the NewCell = NewRow.insertCell(0) line. Then looking at
NewCell in the watch pane. There you will see the huge number of properties
(i.e. NewCell.bgColor, NewCell.width, and etc.) that you can manipulate.
You can do the same for NewRow and tblMyTable and you'll get a feel for
everything you can do. Good luck! Ken.
 
Then you'll have to do that client side using JavaScript and handling the
whole "table" model. Weight carefully first if it's worth...

Patrice



--
 
Hi Mark,

If you are putting input controls (i.e. <input type='text' ....>) in your
table, then create a global variable in the <head> section of your page. I
use Counter. Every time I add a row I use the same ID for the controls but
append an incremented Counter (txtName1, txtName2). Then when you submit
your form assign Counter to a hidden input field that you have set to
runat="server":

<input id="hidNumberOfLines" type="hidden" name="hidNumberOfLines"
runat="server">

In your server side code check the value of this hidden control. If it is
greater than 0 then loop and get all your values:

intNumberOfLineItems = CInt(hidNumberOfLines.Value)

For intCounter = 1 To intNumberOfLineItems
strFirstName = CStr(Request("txtFirstName" + CStr(intCounter)))
strLastName = CStr(Request("txtLastName" + CStr(intCounter)))
strAge = CInt(Request("txtAge" + CStr(intCounter)))
 
Back
Top