Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC How to create dynamic DataTable?
    primarykey
    data
    text
    <pre><code>public string DefString { set; private get; } private string path = "http://someuri.org/search?Par1=15&amp;Par2=55"; public string GetAnswer() { WebRequest myRequest = WebRequest.Create(path); WebResponse myResponse = myRequest.GetResponse(); StreamReader sr = new StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.Default); return sr.ReadToEnd(); } </code></pre> <p>My function GetAnswer() returns string like this:</p> <pre><code>(function(){if (typeof samo === "undefined") { samo = {}; }samo.ROOT_URL = '/search_tour?';samo.jQuery(samo.controls.resultset).html('&lt;table class=\"res\"&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;DATAColum1&lt;/th&gt;&lt;th&gt;DATAColum2&lt;/th&gt;&lt;th class=\"c\"&gt;DATAColum3&lt;/th&gt;&lt;th&gt;DATAColum4&lt;/th&gt;&lt;th class=\"c\"&gt;DATAColum4&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr class=\"red_row\" samo:TOWNFROMINC=\"557\"&gt;&lt;td nowrap&gt;DATA1&lt;/td&gt;&lt;td&gt;DATA2&lt;/td&gt;&lt;td class=\"c\"&gt;7&lt;/td&gt;&lt;td&gt;DATA3&lt;/td&gt;&lt;td class=\"c\"&gt;DATA4&lt;/td&gt;&lt;/tr&lt;span class=\"fr_place_l N\"&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;');})(); </code></pre> <p>What shall I do? I have two ways to build the table. First is to create some function that enable to convert this string to object DataTable, then I have to do something like this:</p> <pre><code> &lt;% foreach (System.Data.DataRow row in Model.Rows) { %&gt; &lt;%= row["column"].ToString(); %&gt; &lt;%}%&gt; </code></pre> <p>But It's no good way. </p> <p>Second solution is to convert AnswerString into simple html table and then send it to ViewUserControl. But this way not so good as I want. </p> <p>I have to use some component like <a href="http://datatables.net" rel="nofollow noreferrer">DataTable</a> , but I can not find any examples how to use it(C# MVC). Could you give me example how to use it?</p> <p>For Example you have database NorthWind.mdf, DataTable control and some DropDown. If you change something in DropDown, Data table have to get new data. Please don't use DataSourses like:</p> <pre><code> &lt;asp:SqlDataSource ID="TourDataSource" runat="server" ConnectionString="&lt;%$ ConnectionStrings:ApplicationServices %&gt;" SelectCommand="SELECT [ID], [Name] FROM [TABLE]"&gt; &lt;/asp:SqlDataSource&gt; </code></pre> <p>Could you give me good advice What should I do with AnswerString?</p> <p>Thank for your solutions and advices=) </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload