.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Dynamically constructing a table of results using Ajax and MVC

Posted By:      Posted Date: September 13, 2010    Points: 0   Category :ASP.Net
I need to implement a search page where a user will be able to specify some search criteria and perform a search. It's a requirement that the results are displayed on the same page, beneath the search criteria.I have a simple prototype that works, but I'd appreciate it if someone can sanity check my idea in case there's a much better or simpler way to do it.Here's the code for the controller class:namespace MvcAjaxTableCreation.Controllers { public class HomeController : Controller { public ActionResult Index() { return View(); } public string GetTableData() { return "<table border=\"1\"><tr><td>Product Category</td><td>Product Name</td></tr><tr><td>Category1</td><td>Product Type A</td></tr><tr><td>Category1</td><td>Product Type B</td></tr><tr><td>Category1</td><td>Product Type C</td></tr></table>"; } } } For simplicity, the table string above is hard coded but would be constructed dynamically in the real code.I also have the following form defined In the body of my html: <% using(Html.BeginForm("GetTableData", "Home")) { %> <input type="submit" value="

View Complete Post

More Related Resource Links

Want to Create Table Dynamically With text Control in WinForm Csharp

Hello To All... from Many Days i m tryng to create a simple table using csharp in WinForm.Which will include textbox in each cell according the Passed No of Col & Row. but not getting the proper result. Actually i want to trace each cell data and want to save each cell data to data base : eg. in cell 11(1col & 1row) i m having Combobox which having some item list and when the user select the list item the data will save to the database. Regards, Praveen    What is the Key of Life ... Its Sharing Your Thought & Knowledge ...

How to dynamically add table rows within update panel ?

Hi, In my webform, i have 3-4 textbox, on there textchange event i have to fetch data from database and put it on the form. I have taken another html table (with runat="server")  below textbox and  and in textchange event created a new <tr>, <td> and simply added contents in <td>, then finally added <tr> in the table. This is done in UpdatePanel. When i enter something in textbox1 data is added in that table,that's fine. But when i enter something in 2nd textbox the previous data is overridden. My requirement is that if 2nd textbox's text changes than another row with appropiate data should be added, i.e., now two rows. Silimarly if 3rd ,4th textbox data changes then subsequently 3 or 4 rows should be displayed. What should i do ?

Dynamically fill query parameters in a table adapter ?

SO I have created an object data source on a page from a table adapter using the various Wizards in Visual Studio.Its meant to query a diary Database by a DateTime parameter called diaryDate. I want to query from a date Now to the next 14 days ahead.I want to display the entries in a Grid View when the page loads.So I'm a bit stuck now as to how to set the two query parameters date1 and date2. I want to set date1 = now() and date2 = now() + 14 days.How do I set those parameters when the page loads ?Should I have used the adapter Wizard approach of do I have to write all the code in the code behind page ??This is my datasource code'<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" InsertMethod="Insert" OldValuesParameterFormatString="original_{0}" SelectMethod="GET_nextTwoWeeks" TypeName="query_getNextTwoWeeksTableAdapters.diaryDatesTableAdapter"> <SelectParameters> <asp:FormParameter DefaultValue="" FormField="date1" Name="date1" Type="DateTime" /> <asp:FormParameter DefaultValue="" FormField="date2" Name="date2" Type="DateTime" /> </SelectParameters> <InsertParameters>

Create table dynamically in SQL Server


hi all,

i want to create temparory table dynamically in sql server,

well, it depends on the fields that are passed from front end as comma seprated value..

and that table shoud contain only that fields that are passed  from front end,

help me on this if it is possible,


Thanx in advance,

Sagar Joshi

InfoPath Forms : Adding rows dynamically from a SQL table along with a 'Delete' button per row


My requirement is something like this:

In a Task Approval form, I want to have a view which shows all the rows in a particular SQL table (in a infopath repeating table?). Along with each row, there should also be a button, on clicking which the row should disappear from the infopath view table. Do you think InfoPath can handle all this? :) 

To summarize:

1. How do I add rows to a table dynamically?

2. Per row, how do I create a button dynamically?

3. How do I remove the row from the view when the button is clicked?

Unable to create table dynamically in database


I am able to create database through script generated by SQL Server 2008 but unable to create tables from generated script. Please indicate if any step is missing.


************* Code *******************

 public bool CreateAppTables(string DatabaseName, string ConnectionString)
        string DatabaseScript;
        DatabaseScript = Activity.readTextFile(HttpContext.Current.Server.MapPath(".") + "/functionalscripts/CreateTablesonly.sql");
        DatabaseScript = DatabaseScript.Replace("DatabaseNametoChange", DatabaseName);
        return ActionQueryDB(DatabaseScript, ConnectionString);


 public bool ActionQueryDB(string SQLStatement, string ConnectionString)
        //  SqlConnection cn;

        OleDbConnection cn = new OleDbConnection();

        cn.ConnectionString = ConnectionString;
            OleDbCommand cmd = new OleDbCommand();
            cmd.CommandText = SQLStatement;
            cmd.Connection = cn;

            return true;
        catch (Exception ex)

            return false;


****************** Contents of text file appe

How to create a Table of content in .rdl design in BIDS dynamically according to the Page no wise..?



well i am able to create the TOC statically by using the Document Map properties as describe in my older post issue 

but now i just want to create the Table of contents dynamically generate using the page no wise..is it possible...how can we do it while designing the .rdl in BIDS..



SSIS 2005 - Dynamically generate create table statement from source



I have a requirement where i had to migrate the table structure and data from ODBC database to SQL Server. I have dynamic source reader that uses sql query from variable to get the data and the next step is to get the create statement and create table and then to insert data. how can i get Create Statement the destination produces and use sql task to create the table and then insert the data using data flow task.

Please suggest



How can i fix width of table cell that is created dynamically?



based on data coming from web method i am creating table row and its corresponding data.But the problem is that cell's width are not fixed.If text is small its good, but if text length is larger alignment is disordered, it overflows the assigned area.I tried several method to resolve this problem but failes.

Table's rows and cells, and its text's are filled through JavaScript. 

ajax form, add textbox dynamically


Having FooTable1: id, name, lastname and FooTable2: idfromtable1, address... How can I make a view insert where i can have a button (ajax one) to add a textbox relative to FooTable2.address? I want it to work so people could add as many adresses as they want, jsut by clicking the button again to add a new field. I'd like to do so without using JQuery

How to get the backcolor of dynamically created table cell?



I am unable to reterive dynamically created table cells back color which has been changed by the click event of the cell.

I am adding table cells dynamically on asp.net page and also setting cells back color. So when the page is loaded, table has number of cells with different colors.Table cells back color can be changed by clicking on it through java script. 

On page post back event, i am jutst getting those colors which were set before the click event.

For example:

When the page is loaded, cell1= red and cell2=red.

If i click on cell2 then it will change to blue so now cell1= red and cell2 = blue

but on post back i am getting cell1= red and cell2 = red.

Table is recreated on post back event.

Any ideas?


Selecting from table where value is in results from a sproc


I'm stuck again! I cannot get the following to work - hopefully it will be self-explanatory on what I am trying to achieve. Any suggestions please? Smile

select * from TABLE where [Value] in (execute dbo.spProcedure 'param')

Full Text search join runs really slowly when inserting results into a table.


We have a problem when inserting the results of a join on a full-text search into a table. I have had to anomalyse the query but the bottom line is that the insert into a table is the factor that makes the query run really slow.

The join itself works fine and returns the result set (2 rows in this case) in approx 100 ms:

    tablea WITH (NOLOCK) 
INNER JOIN CONTAINSTABLE (indexedviewa,*,'nnnn') AS kwsearch
    ON kwsearch.[key] = dbo.tablea.aaaa 
WHERE p = 1
AND q = 2
AND r = 0
AND s NOT IN (8,9)
AND t = 'zzzzz'

However, when the results of the join (2 rows in this case) are taken and inserted into a table (whether it be #temp or a permanent table), the query takes approx. 3500 ms:

    propertyId  int,
    agentId     int);

    tablea WITH (NOLOCK) 
INNER JOIN CONTAINSTABLE (indexedviewa,*,'nnnn') AS kwsearch
    ON kwsearch.[key] = dbo.tablea.aaaa
WHERE p = 1
AND q = 2
AND r = 0
AND s NOT IN (8,9)

Dynamically added table rows disappear on return



I am adding table rows dynamically, after I return from a post back, these rows disappear.

Is there a way to preserve these rows and add them back on page load?

Add rows dynamically to a table and poulate data in cascading dropdowns

hi,I am using ASP.NET3.5,
I want to Add rows dynamically to a table.I am using masterpage in my .aspx pages.
I have written the following code code.This code is working fine.
but I need to load data in dropdownlist2 dynamically based on another dropdownlist1.and i need to do few calculations based on table data.
but how can I do using  javascript/jquery/Ajax ??
can i do all my calculations using these html controls?

1  dynamically Add rows to table.(which doesnt give burden to server)
2  need to use cascading dropdowns (like Country,States,villages )
3  Have to do some calculations (like Tax calculations based on table data)
4  Have to enable/disable few controls base on input data of dropdowns and textboxes.

    <TITLE> Add/Remove dynamic rows in HTML table </TITLE>
    <SCRIPT language

How to remove duplicates from query results caused by table joins


It's been a while since I used SQL and I'm coming across a problem where by the database design is adding a lot of useless output to a query I need to run and I'm not very clever so don't know how to remove the crap I don't need.

This is what I'm up against:

Create Table #Planning(Assy nvarchar(255), PartNo nvarchar(255))
Create Table #PlanningCosts(Assy nvarchar(255), MaterialCost float, LabourHours float, LabourCost float)
Create Table #PlanningLabour(Assy nvarchar(255), OpNo Nvarchar(255), OpDesc nvarchar(255), OpTime float)
Create Table #PlanningMaterial(Assy nvarchar(255), Material nvarchar(255), MaterialQty float)

Query a Table with Japanese Characters returns always 0 results


Hi all, I wonder if you could give me a hand on this please...

I've a table (lets say with 2 columns: ID int, Vendor Name nvarchar(255)) with some records with Japanese Characters. 

When I try to query that table for the specific rows with Japanese string I always get 0 results.


Table example:


ID Vendor Name

1 Bruno Ferreira

2 ??????????


Query Example:

select * from myTbl where [Vendor Name] collate <<collations name>> = '??????????'


Result always nothing...


I've tried with all the possible available collations but with no luck

collations I've tried:











ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend