Este articulo tendrá por objetivo mostrar como trabajar con las columna del tipo ComboBox que se encuentran dentro de una celda del datagridview. Function to get the results in datatable. Next I am using my very own GetData function to get the desired data from the database which is given below. MDRSESCO – Software for the Masses. The software described herein, except where otherwise noted, was designed and implemented by MARK DANA ROCKMAN Email. Distinct method returns distinct elements from a sequence. If you take a look on its implementation with Reflector, you'll see that it creates DistinctIterator for. Display Data. Table in HTML Table in ASP. Net using C# and VB. Net. In this article I will explain how to display data of Data. Table as HTML Table in ASP. Net using C# and VB. Net. Database. I have made use of the following table Customers with the schema as follows. I have already inserted few records in the table. Note: The SQL for creating the database table is provided in the attached sample code. HTML Markup. The HTML Markup consists of a Place. Holder within which the HTML Table will be displayed.< asp: Place. Holder ID="Place. Holder. 1"runat="server"/> Namespaces. You will need to import the following namespaces. C#using System. Data; using System. Text; using System. Configuration; using System. Data. Sql. Client; VB. Net. Imports System. Data. Imports System. Text. Imports System. Configuration. Imports System. Data. Sql. Client. Displaying data of Data. Table as HTML Table using C# and VB. Net. Inside the Page Load event of the ASP. Net Page, first the Data. Table is populated with the records from the Customers table. Then using the String. Builder class, a string consisting of an HTML Table is generated by iterating through the columns and the rows of the Data. Table. Finally the HTML string is displayed on the page by adding the Literal control to the Place. Holder. C#protectedvoid Page_Load(object sender, Event. Args e){ if (! Is. Post. Back) { //Populating a Data. ![]() Table from database. Data. Table dt = this. Get. Data(); //Building an HTML string. String. Builder html = new. String. Builder(); //Table start. html. Append("< table border = '1'> "); //Building the Header row. html. Append("< tr> "); foreach (Data. ![]() Column column in dt. Columns) { html. Append("< th> "); html. Append(column. Column. Name); html. Append("< /th> "); } html. Append("< /tr> "); //Building the Data rows. foreach (Data. Row row in dt. Rows) { html. Append("< tr> "); foreach (Data. Column column in dt. Columns) { html. Append("< td> "); html. Append(row[column. Column. Name]); html. Append("< /td> "); } html. Append("< /tr> "); } //Table end. html. Append("< /table> "); //Append the HTML string to Placeholder. Place. Holder. 1. Controls. Add(new. Literal { Text = html. To. String() }); }}private. Data. Table Get. Data(){ string constr = Configuration. Manager. Connection. Strings["constr"]. Connection. String; using (Sql. Connection con = new. Sql. Connection(constr)) { using (Sql. Command cmd = new. Sql. Command("SELECT Customer. Id, Name, Country FROM Customers")) { using (Sql. Data. Adapter sda = new. Sql. Data. Adapter()) { cmd. Connection = con; sda. Select. Command = cmd; using (Data. Table dt = new. Data. Table()) { sda. Fill(dt); return dt; } } } }}VB. Net. Protected. Sub Page_Load(sender As. Object, e As. Event. Args) Handles. Me. Load If. Not. Me. Is. Post. Back Then 'Populating a Data. Table from database. Dim dt As. Data. Table = Me. Get. Data() 'Building an HTML string. Dim html As. New. String. Builder() 'Table start. html. Append("< table border = '1'> ") 'Building the Header row. html. Append("< tr> ") For. Each column As. Data. Column. In dt. Columns html. Append("< th> ") html. Append(column. Column. Name) html. Append("< /th> ") Next html. Append("< /tr> ") 'Building the Data rows. For. Each row As. Data. Row. In dt. Rows html. Append("< tr> ") For. Each column As. Data. Column. In dt. Columns html. Append("< td> ") html. Append(row(column. Column. Name)) html. Append("< /td> ") Next html. Append("< /tr> ") Next 'Table end. html. Append("< /table> ") 'Append the HTML string to Placeholder. Place. Holder. 1. Controls. Add(New. Literal() With { _ . Text = html. To. String() _ }) End. If. End. Sub. Private. Function Get. Data() As. Data. Table Dim constr As. String = Configuration. Manager. Connection. Strings("constr"). Connection. String Using con As. New. Sql. Connection(constr) Using cmd As. New. Sql. Command("SELECT Customer. Id, Name, Country FROM Customers") Using sda As. New. Sql. Data. Adapter() cmd. Connection = con sda. Select. Command = cmd Using dt As. New. Data. Table() sda. Fill(dt) Return dt End. Using End. Using End. Using End. Using. End. Function. Screenshots. HTML table as displayed on the page. HTML Table as seen on the source of the page.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
November 2017
Categories |