0

I have a standard dataset that I get from my SQL server 2008 database..

ID       Name
1        Joe
2        Ted

where I use c# to typically handle the data and add it to a table.

I'd like to create a table in javascript on my page, but I'm not sure where to begin.

There is obvioulsy more columns and rows in this table, but I included only a small portion of the data for ease.

           <div id="divWhatIf" runat="server">
                <table id="tblWhatIfByMonth" border="1" cellpadding="0" cellspacing="0" runat="server">
                    <tr id="rowWhatIfHeaderRow" runat="server">
                    </tr>
                </table>
            </div>

My aspx page looks like and I'd like to add each datarow to tblWhatIfByMonth.

6
  • Have you considered using an aspx datagrid? Commented Jul 19, 2012 at 1:56
  • Due to other restrictions, I have to build this as a table. I can't use a datagrid. Commented Jul 19, 2012 at 2:01
  • @mike9182 - I may be able to use a datagrid. The reason I am having to go this route is I am having issues with posting back onto a table. Can I use a datagrid to handle ajax enabled text boxes? and I definitely don't want to have an update button. Updates are handled onkeyup of each textbox. Commented Jul 19, 2012 at 2:22
  • @GrayFox374 - minus 1 as he shouldn't have to explain his architecture, nor should you ridicule it. OnKeyUp seems to work for Gmail, Google docs, etc. Chances are it's more like OnKeyUp, restart the 5 second AJAX queue... but again, that doesn't matter here. Dude just wants to render a table. Commented Jul 19, 2012 at 4:17
  • There's a difference between critique and ridicule. Fixing small problems while overlooking large ones is not helping. That is akin to fixing the splinter in a finger but ignoring the heart attack. I remember my first code reviews, where it was damn near like going before a firing squad. Every aspect of the database, code base, deployment plan, security plan, documentation, etc. was scrutinized. It can be painful, but you know what, it makes you better. You think only helping render a table was due diligence? Go the extra mile. This solution would not fly at Google. Commented Jul 19, 2012 at 5:37

1 Answer 1

2

You can use AJAX to get the content for the table. The response text can be the entire markup for the table (which makes life quite easy) or if only part of the table needs to be replaced, send the data as JSON formatted text.

The JSON is converted to an object that can then be used to create the table, e.g.

[
  {"ID":"1","Name":"Joe"},
  {"ID":"2","Name":"Ted"}
]

or

[
  ["ID","Name"],
  ["1","Joe"],
  ["2","Ted"}
]

You can also send CSV data and parse it (say with a regular expression) and build all or part of a table.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.