DataGrid set DataGrid: method

xiaoxiao2021-03-06  91

http://dev.9cbs.net/Article/21/21328.shtm In creating the web, there are many places to involve the display of hierarchical data. The most common is to be with a shopping site, one item is usually Contains many related information: price, presentation, pictures, etc., this is data with hierarchical relationship. The theme of this article is to describe how to use ASP.NET (VB) to display hierarchical data in this article, will be divided into two parts:

Related knowledge nested data controls to be understood display hierarchical data

Related knowledge 1, create a DataSet with multiple tables, this article is taken as an example of SQL Server2000 as an example: import system.dataimport system.data.sqlclientdim objconn AS New SqlConnection ("Data Source = localhost; data = Pubs; user id = sa; password = sa ") objConn.Open () dim strSql as string =" Select * from jobs; Select * from employee "dim objAdapter as new SqlDataAdapter (strSql, objConn) dim objDs as new DataSet ( ) objadapter.fill (objds) Objconn.close () Set the name of the two tables objds.tables (1) .talbename = "jobs" objds.tables (0) .tablename = "employee" here has been created There is no relationship between two tables, but there is no relationship between the two tables, now we need to create a relationship for it 'to add relationships to these two tables Dim Parent as datacolumn = objds.tables ("jobs" ) .Columns ("job_id") DIM Child as datacolumn = objds.tables ("Employee"). Column ("job_id") objds.reletions.add ("ratename", parent, child) 2, navigation table relationship, Simple format output hierarchical data outputs the above two tables into the following format: Job1: Employee1emPloyeE2 ... Job2: Employee1emPloye 12 ....... [vb] Dim ParentColumndim ChildColumnFor Each ParentColumn in Objds.tables ("jobs" ) .RowsResponse.write (PARENTCOLUMN ("Job_Desc") & ":") for Each ChildColumn in ParentColumn.GetChildrows (Relation Name) Response.write ("LName" & "& ChildColumn (" FNAME "&") The data of the example output of NextNext is already a hierarchical relationship, but this is not the purpose of this article. When doing development of Web, we can't embed the logic code in HTML, separate code and HTML separation is an important difference between ASP.NET and ASP. In the next section, we will combine the knowledge learned to use ASP.NET. Powerful data control REPEATER, DATALIST, DATAGRID in display hierarchical data

Nested Data Controls Realize hierarchical data. Now you can use Repeater nested DataList, or Datalist nested Repeater, in short, you can use REPEATER, DATALIST, DATAGRID to nested any combination of these three controls. In this article, It will use the relatively simple Repeater nested Repeater as an example, which is easy to understand, please add the following two data binding code: ParentrePeater.DataSource = Objds.tables ("jobs"). DefaultViewParentRepeater.DatabaseD () then Add the following code in HTML: position: <% # databinder.eval (container.DataItem, "job_desc")%>

'<% # Ctype (container.DataItem, DataRowView) .createchildview ("ratename")%>>>>>

Staff: <% # DataBinder.eval (Container.DataItem, "Lname")%>

<% # DataBinder.eval (Container.DataItem, "FName")%>

This article is designed to throw bricks, as for the application of DataList nested DataGrid, the principle is small, needed to try a different combination of multiple points, you can even try to create DataSet with more data tables, nesting more (layer) The above data controls.

转载请注明原文地址:https://www.9cbs.com/read-95308.html

New Post(0)