Hello I'm developing a asp. Net page where I want to populate many tables in the ui
But I want it to be dynamic.
Eg: If I retrieve only 2 rows as per search criteria then I want to display only 2 tables.
I tried dynamic table creation using string builder but I got a null reference because the table Id was not being read . Is there any other way where I can create tables dynamically in the html page or should I do it in the code behind itself , then get the Id using flow control and then populate the table. Please help!!!
The problem of creatig tables dynamically has been rectified but now i cannot retrive their ids so that i can print values retrived from the datatbase in it using id.text command.
this is my code
StringBuilder htmlTable = new StringBuilder();
htmlTable.AppendLine("<table>");
htmlTable.AppendLine("<tr>");
htmlTable.AppendLine("<th>colum1</th>");
htmlTable.AppendLine("<th>colum2</th>");
htmlTable.AppendLine("<th>colum3</th>");
htmlTable.AppendLine("</tr>");
htmlTable.AppendLine("<tr>");
htmlTable.AppendLine("<td><asp:Label runat='server' id='lblt0'></asp:Label></td>");
htmlTable.AppendLine("<td>colum2data</td>");
htmlTable.AppendLine("<td>colum3data</td>");
htmlTable.AppendLine("</tr>");
htmlTable.AppendLine("</table>");
litTable.Text = htmlTable.ToString();
//litTable is the id of my asp:literal tag
You cannot create a table with a runat=server tag in this manner. Adding items to a literal control can only create client side markup not server side controls.
Your best route is to use a GridView as suggested or an HtmlTable
GridView: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview(v=vs.110).aspx
HtmlTable: http://msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmltable(v=vs.110).aspx
If your example really is as trivial as the one you provided an HtmlTable might be the easiest route. Though if you want to populate your table from a database or some other data source a GridView is your best option.
Related
I am trying to create a page where a list of doctors will appear from my database. But without using the Gridview. I want to display the informations as in the image below. Please help me.image
If you use vb.net...you must use repeater. Other way is iterate data with a for.
Doc for repeater:
https://learn.microsoft.com/en-us/aspnet/web-forms/overview/data-access/displaying-data-with-the-datalist-and-repeater/displaying-data-with-the-datalist-and-repeater-controls-vb
Doc for iterate lists:
https://learn.microsoft.com/es-es/dotnet/visual-basic/language-reference/statements/for-each-next-statement
I have two stored procedures which gives Daily swipe data and another gives Temporary Swipe details.
I got an requirement to populate gridview, Based on the date the temporary card details must get displayed in between Daily swipe data.
Please anyone give me idea how to populate two result sets into gridview
Iam using Sql server 2008 R2 and Visualstudio 2010
Lets assume we consume this ResultSet which has two DataTables "Agent" and "RealEstateProperty". The task is to display, what properties belongs to which agent, in a GridView.
There are different ways to accomplish this task-
Method 1: Bind DataTables to a single GridView
To bind these multiple DataTables to a single GridView control, we can quickly create a new temporary DataTable, with the required fields and populate the Rows and then bind the new DataTable Rows to the GridView.
The above code is self explanatory, where I have created a temporary DataTable, populated its rows by iterating through the original DataTables and then binded the Grid to the new DataTable.Rows. The interesting piece of code to note here is the row.GetChildRows(), which respects the relationship and automatically returns the related child rows. The aspx part looks like the following, where we have a GridView with three columns.
and the RowDataBound code is
Method 2: Bind DataTables to a nested GridView
If we want to avoid creating temporary dummy DataTable as described in method 1, we can use the technique of nested list control. Now we can do this by using
two GridView, or
two DataList, or
two Repeaters or
a combination of Repeater and GridView, or
a combination of Repeater and DataList, or
a combination of GridView and DataList.
We are going to look at a combination of 2 GridViews here, where one GridView is nested inside another, you can do any of the above combinations. For this case the the aspx code is-
Notice the parent and nested GridViews has different onrowdatabound methods. In this technique the parent grid is binded to the the Agent DataTable Rows and the nested GridView is binded to the child RealEstateProperty DataTable Rows. Here is the code.
Method 3: Convert the DataSet to Objects and then bind to GridView
We can generate csharp class from the dataset schema using Xsd.exe and then bind the GridViews to the objects. I have discussed similar technique in one of my previous blog post, where you will find how we can use the Xsd.exe that ships with the .NET Framework.
Example
C:\temp>xsd propertyDataSet.xsd /l:cs /c
Microsoft (R) Xml Schemas/DataTypes support utility
[Microsoft (R) .NET Framework, Version 2.0.50727.42]
Copyright (C) Microsoft Corporation. All rights reserved.
Writing file 'C:\temp\propertydatasetclass.cs'.
I also demonstrated a handy DataTableToT() method to assist in converting DataTable to strongly typed object. And when we have the DataTable converted to a stronglytyped object/list/collection it is very easy to bind to the bind to the GridView.
1.Call your Second stored procedure within first stored procedure.
2.Pass your outcome to dataset.
3.From dataset u can fetch it using ds.table[0],ds.table[1],etc..
you can find from here, Merging DataSet Contents
http://msdn.microsoft.com/en-us/library/aszytsd8.aspx
[Thanks to Filburt and Devjosh. I have restructured the post and included my attempt approach. ]
I have a table on my SQL DB call ReportList which is a list of report. I need to go through that list and interrogate the reportserver, eport by report, to populate a table called ReportParameters. The ReportParameters table has a column for ReportOwnerID which needs to contains the ReportID value of the corresponding (owner) report as listed in the ReportList table.
This is in VB.NET 2005 ASP2.0 and I have ended up with a mess. Please help me with the cleanest approach to doing this.
It needs to work so:- I have a listbox of the reports as per REportList and a GridView that list all the parameters (uniquely - most of the parameters are common to many reports) the idea being that the parameters get set once and the report can be kicked off by selecting them in the ReportList CheckListBox and clicking on Execute.
I would like it that as I click on a particular report in the ListView, the relevant parameters in the Gridview get a green background and those that do not apply are red. The leftmost column in the gridview contains tha Parameter NAME (not editable) and the next column must be editable to populate the value.
DONE SO FAR:
I have tried on clicking the EXECUTE button , to build a parameters string in a testbox and call that with the Javascript OpenReportWin() function when I open the report in a new window. This works fine, but my biggest issue it interrogating the reportserver reports to get back a list of parameters and dooping them into a table. I have triend to use a hidden DataGrid bound to a ds onto the reportParamaters table; I have tried to poulate it using a datalist but I cannot get the hang of these thionsg and its looking messy. Ther must be a simple clean way of gettting the .GetParameters resultset back from the report server and populating the table without having to create a reportviewer object and cycling through the list of reports - it then has to render each report before you can get that list out.
Thanks
I will withdraw this for now. I will submit a solution when I am comfortable that I have reahced a clean solution.
Mac
PLEASE CLOSE!!!
I am new in .Net and I had a question regarding creating dynamic tables.
I am creating a page that adds a new row to a table (First Name, Last Name, Address, etc...) when a user clicks on a button. I have been reading that every time you do a postback to a dynamic table you have to re-create the rows. That is what I am doing.
I have been testing this and about 40 rows have being added already, when I click to add a new row, it runs completely slower and I can only imagine how long it would take to add 100 rows. I am assuming that it is because re-creating the rows takes time.
My questions is there a better approach or another way to accomplish task?
'***Edits Here what im currently doing
This is my table and button control:
Code when button is clicked, which creates the dynamic table:
Dim tblrow As TableRow
Dim tblcell As TableCell
Dim inputText As TextBox
tblrow = New TableHeaderRow
tblcell = New TableHeaderCell
tblcell.Text = tableCount 'variable used to count rows in the table
tblcell.HorizontalAlign = HorizontalAlign.Left
tblrow.Cells.Add(tblcell)
tblcell = New TableCell
inputText = New TextBox
inputText.ID = "txt_" & tableCount
tblcell.Controls.Add(inputText)
tblrow.Cells.Add(tblcell)
table1.rows.add(tblrow)
Now from what I learned and tested so far, everytime I do a postback I have to rebuild this table in order to keep all of the contents I entered into the table.
The next question is why dont you add another row using jquery so that you don't have to do postbacks. I have tried this approach and it worked well UNTIL I needed to put the information entered into the table into a database which required a postback. So I was back at my original problem.
Note, if there is a better way to approach this im all ears. Like I said before I am new to this language and im just trying to learn.
My suggestion for you will be to use the JqGrid it is a free open source jquery plugin but also available commercially. It is fast in data loading and have lots of dynamic features
If you know javascript and jquery then this will be easy for you to use, it comes as Asp.Net, mvc and php component
Are you using windows forms? If you are, use the ListView control and change the view (I believe thats what it's called...) to details. Then you can use one of the many tutorials like this to populate the list:
If not using Windows Forums sorry, I saw the VB.net part and assumed.
asp.net is a server side web technology which means that you are working with a stateless technology (basically). That is why you have to rebuild everything on every postback.
There are several ways of dealing with this:
using the asp.net ViewState and check for Page.IsPostback on PageLoad
using jQuery and clientside Templates like Pure and fetch the Data through webservices
I on your behalf would avoid creating a table manually like you showed above, but instead use templated controls and specify the behavior declaratively.
When you create a DataGrid for example and are using ViewState, you do not have to explicitly recreate the DataGrid, since asp.net is taking care of it when used correctly.
How do I display information in my page (take it from DB) in asp.net 2008
Currently I use GridView, but it display the information in a TABLE. I want to display it in a normal line.
for example:
I have this table in my DB
http://www.rofof.com/img2/4jpqfn26.gif
alt text http://www.rofof.com/img2/4jpqfn26.gif
I want to print an information in my page as:
You are A and your ID is: 1
without using GridView.
How are you getting your data from the database to your gridview? Also do you want to display only a single record or would you display multiple records?
The Repeater is a great control if you want to display all the records. You can bind it the same way your binding the grid then define your template to render the html however you want.
If you only want to display a single record you could just do this in the code behind of the page. For example:
Page_Load()
{
if (!IsPostBack) //Make sure this only runs first time we call page
{
//Get your data from the DB, can't help here unless
//you provide more details.
MyData data=....
myLabel.Text="You are " + data["name"].ToString() ....
}
}
If you update your question with more details about your data source (are you using a data table custom objects etc...). I can update my answer with a better exampkle