I'm storing my HTML in a database so the page loads the HTML data from the database. I use ViewData in my ASPX page in order to populate the page. The HTML is stored in a NVARCHAR(MAX) column and it's working great for small pages. The problem I'm having is when the HTML is large. It populates 2 thirds of the HTML data but loses the last third. Is there a limit to ViewData?
There is no limit on view data size as far as I am aware of, certainly view data of many megabytes is possible and that should be enough to contain the HTML of even the enormous page.
How much data are you talking about? Are you actually storing the viewdata in the database as part of the page HTML? This feels like a bad idea as the view data of the page should be generated by the asp.net runtime.
Based on the comment "12.0Kb of data." I would assume your problem lies else where.
Check if the data is there before you load it to the view data.
Not sure how you rendering your viewdata. But if you store html file in database table, I am sure you have a column holding FileType. You could implement an actionlink to open an html file using FileContentResult type method. Assuming you have a table name 'HtmlPage', doc and docType as columns.
public FileContentResult GetHtmlFile(int id)
{
HtmlPage htmlPage = _repository.GetPrepAttachmentByID(attachmentID);
return File(htmlPage.doc.ToArray(), htmlPage.docType);
}
Hope this helps...
Related
i have problem in showing my data field that already in html code inside sql. need to show it on asp.net mvc.
below is the command of html in asp.net which i already add html as fieldtype so when it read html or textbox it will show the page in html format. but now for table, i cant properly show the exact table, but only the code.
enter image description here
the sqldata field action details in html table
enter image description here
this is the output, which is not show the exact table
enter image description here
help me out!
#Htm.Raw()
when you want to render html code stored in sql first you need html tag in ef to actually be able to save it from user end then you are subject of milion of hacking attempt which btw all of them fails and then when you want to reder html what you do is just render it with razor which is #Html.Raw(_yourContext.YourTable.FirstOrDefault(q=>q.yourPK == yourVariable).yourHtmlField)
I have googled and seems not to find a perfect answer. Most people make use of a gridview. This is what i'm trying to achieve. I am developing a website. I have about 50 records in my database. I want to display 7 records per paga and then provide a next and back button. i dont want to make use of a gridview because that wont be okay. I want to proper pagination technique where each data will be displayed in a div. I dont known what is used for pagination is a site like this but i want to handle my pagination like this too. Will really appreciate your suggestions and codes. A demo would be really appreciated. Help a rooky please. Please note that i don't want to use tables. Want something like that of php
You can use a Repeater control, and assign to it the data source.
After loading data you get the total count, and divide by 7 to get page count, then create each link that point to the same page with > .aspx?page=X .
On load you use the paging technique in your DB engine to get the proper page and assign to repeater as data source.
Do yourself a favor and look into jQuery Datatables. You can still use a gridview, listview, table, whatever and Datatables sits on top of it. Handles paging, sorting, filtering, search automatically. And on top of that it's free.
The learning curve isn't that steep either, you basically download the scripts, refer to them in your code, and then apply the jquery to your table/grid object.
https://datatables.net/
Following on from the comments you would want to do something like this to get the data
SELECT *
FROM YOURTABLE
ORDER BY SOMECOLUMN
OFFSET x ROWS
FETCH NEXT x ROWS ONLY
-- x represents the number of rows you want to bring back
-- I would recommend you keep that the same as each other
then you would want something in your query string
http://yoursite?Offset=10&Fetch=10
this would be whats passed back to your code behind.
Now depending on your level of competence with .Net you can get the query string in a few ways
var fetch = 0;
var offset = 0
if (string.IsNullOrEmpty(Request.QueryString["Fetch"].ToString()))
{
fetch = Convert.ToInt32(Request.QueryString["Fetch"]);
}
if (string.IsNullOrEmpty(Request.QueryString["Offset"].ToString()))
{
offset = Convert.ToInt32(Request.QueryString["Offset"]);
}
The pass these values into a stored procedure. I am going to assume you know how do this.
Once you have the data back from the stored procedure and have the details in a DataTable unless youre using EF.
Loop through the you can either use a Repeater control as suggested in an earlier answer.
then you can pass the details back to the screen and this is where things will get interesting as I cannot assume that your using MVC or WebForms. So the rest of this journey you're on your own I'm afraid.
I have a word template which has a content control placeholder to hold rich text data. The data comes from a sharepoint list (rich text field) and may also include tables in it.
On checking the data from sharepoint list I found it returns me a HTML formatted data. I wish to place this data in the content placeholder with proper formatting.
For example if the data returned is HTML table ( format) I want a table to be created with data populated. Is there any method available to place the data in content control.
I found that third party tool converter at http://html2openxml.codeplex.com/ which is available for conversion, however this appends data to MainDocumentPart not to content control.
Please guide. Thanks in advance.
You could try to use WordDocGenerator, which uses content controls. Then combine it with html2openxml, as discussed here. However, I find the formatting in some cases becomes terrible after adding the html content into your content control--one example is when inserting lists, the bullet points goes out of view when you open the document. I have not tried adding a whole table into a content control.
I'm using an ASP repeater on my page, and I want it to create a 3 column grid. In my HTML page, I use a class which sets the third column so that it fits. Basically, the first 2 columns have a margin-right of 28px so it spaces them nicely and then the third class removes the margin-right so that the columns fit.
Problem is, when this comes into the repeater, I can't use the third class and I get a 2 column result. Any ideas on how I can overcome this?
Use a <table>. I know, I know, we aren't supposed to use tables anymore, right? If you are displaying tabular data, you should use a table. If it's a "grid", that sounds like tabular data to me. Is it?
I managed to resolve this without the use of a <table>. It turned out that the <form> didn't have enough width, so I amended this and it worked.
I am returning SQL results. First I guess should I be using the reader or the adapter? Second I want to output the results to a table (I cant use a GridView because of other functions going on in the page). So I am wondering How would I go about building my own table and populating with Data from mySQL database. I cant find anything that tells me how to output to what I want. I find textboxes, labels, files etc. but not inline html? I am using ASP.net and C#
Thanks
Reader will be faster than adapter, you will get better performance and your life will get more complicated once you start creating your own grid using html table.
If you don't want to write a lot of code, then use adapter as you will get DataTable which you can easily loop through and build your own html table.
What you are looking for is: System.Web.UI.HtmlControls namespace.
HtmlTable
HtmlTableCell
HtmlTableCellCollection
HtmlTableRow
HtmlTableRowCollection
You can build HtmlTable and render it to page. Take a look at this example: Creating HTML Table...
Also, you may want to look at HtmlGenericControl where you can create any element you want like: new HtmlGenericControl("div");
Another option is to use a repeater control for emitting the data. Clean, easy, and you have full control of the markup generated.
Here's an example: http://www.aspcode.net/ASPNET-Repeater-control-instead-of-grid.aspx