Questions about data binding in nested data controls in VB.NET (original)

zhaozj2021-02-16  140

Questions about data binding in nested data controls in VB.NET

Lanfan [original]

Nested data controls in ASP.NET, such as REPEATER, DATALIST, DATAGRID, and the like. In the nested data control, the form of the parent table and the sub-table is usually used to bind the parent table data to the outermost data control, and the sub-table data is bound to the inner data control. There are many discussions on the online data binding issue, but there are many people with C #, many people have encountered some problems in VB.NET.

I use a relatively simple Repeater nested Repeater as an example, where I borrow the example of KWKLOVER in "ASP.NET's Hierarchical Data Display Technology". The key statement in the data binding is in the following form: staff: <% # databinder.eval (container.DataItem, "[/" lname / "]")%> = <% # databinder.eval (container.dataitem, "[/" fname / "]")%>

We convert this sentence to VB is: staff: <% # databinder.eval (container.DataItem," lname ")%> = <% # databinder.eval (container.dataitem," fname ")%>
< / ASP: REPEATER>

The error that will appear when compiled "DataBinder.eval:" System.Data.DATAROW "Properties of Name LNAME" has been repeatedly tried, and two methods to solve this problem:

First, KWKLOVER is used in "ASP.NET's Hierarchical Data Display Technology", using the CreateChildView method: Complete example is the Import System.Data Import System.Data.sqlClient Dim Objconn AS New SqlConnection ("Data Source = localhost; Database = Pubs; userid = 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" 'for these two tables Add relationship Dim Parent as datacolumn = objds.tables ("jobs"). Column ("job_id") Dim Child as datacolumn = objds.tables ("Employee"). Columns ("job_id") objds.relations.add ("RELATIONNAME ", PARENT, Child) data bind to PARENTREPEATER: PARENTREPEATER.DASOURCE = Objds.tables (" jobs "). DefaultView ParentRepeater.Database is added to the following code in HTML: position: <% # DataBinder.eval (Container.DataItem, "job_desc")%>
staff: Staff: <% # databinder.eval (Container.DataItem, "Lname")%> <% # databinder.eval (Container.DataItem , "FNAME")%>

Second, the <% # DataBinder.eval (Container.DataItem, "LNAME")%> is changed to <% # DataBinder.eval (contact ")")%> ie: staff: <% # databinder.eval (Container.DataItem, "(LNAME)") ")") ")") ")") ")") ")") ")") ")") ")") ")") ")") ")") ")") ")") ")") ")") ")") ")") ")") ")") ")") ")") ")") ")" "" "" "" "" Collection is not a DataTable, the content in the subcourse is DATAROW, DATABINDER.EVAL connects "lname" as DataRow's properties, so "DataBinder.eval:" system.data.DATAROW "does not include the name For the attribute of lname ", when we" change to "(LNAME)", DataBinder.eval is connected to DATAROW ("LNAME") so it can be compiled correctly, change to "[lname]" can. In addition, you can also write directly: <% # container.dataitem ("lname")%>

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

New Post(0)