I Love Tiananmen, Beijing
Sun rises on Tiananmen
Great leader Chairman Mao
Guide us forward
<P class = "msonormal" style = "margin: 0 cm 0 cm 0pt; text-indent: 21pt"> <font size = "4"> <span style = "font-family:; MSO-ascii-font-family: 'times new Roman '; MSO-Hansi-font-family: 'times new Roman '"> generally, </span> <SPAN lang =" en "> Web </span> <span style =" font-family:
MSO; MSO-ascii-font-family: 'times new Roman '; MSO-Hansi-font-family: 'times new Roman' "> control, for example, </span> <SPAN lang = "en"> dorpdownlist </span> <span style = "font-family:; MSO-ascii-font-family: 'times new Roman '; MSO-Hansi-font-family: 'times new Roman' "> controls, </span> <Span
Lang = "en"> checkboxlist </span> <span style = "font-family:; MSO-ascii-font-family: 'times new Roman '; MSO-Hansi-font-family: 'times new Roman '"> controls and so on, all contain five attributes: </span> <SPAN lang = "en"> datasource </span> <span style = "font-family:; MSO-ascii-font-family: 'times new
Roman '; MSO-Hansi-font-family: 'times new Roman '">, </span> <SPAN lang =" en "> datamember </span> <span style =" font-family:; MSO-ascii-font-family: 'times new Roman '; MSO-Hansi-font-family: 'times new Roman' ">, </span> <SPAN lang = "en"> datatextfield </span> <span style = "font-family:
; MSO-ascii-font-family: 'times new Roman '; MSO-Hansi-font-family: 'times new Roman '">, </span> <SPAN lang =" en "> datavaluefield </span> <span style =" font-family:; MSO-ascii-font-family: 'times new Roman '; MSO-Hansi-font-family: 'times new Roman' "> and </span> <Span
Lang = "en"> datatextformatstring </span> <span style = "font-family:; MSO-ascii-font-family: 'times new Roman '; MSO-Hansi-font-family: 'times new Roman '">. </Span> <SPAN lang = "en"> datasource </span> <span style = "font-family:; MSO-ascii-font-family: 'times new
Roman '; MSO-Hansi-font-family: 'times new Roman' "> used to obtain the data source, that is, to obtain the set containing data. The other four attributes are used to obtain a field value in the data source. However, generally, you want to bind multiple field values in these data sources to an attribute, which cannot be directly implemented. The following two methods are used to implement this function. </Span> </font> </P> <P class = "msonormal" style = "margin: 0 cm 0 cm 0pt; text-indent: 21pt "> <font size =" 4 "> <Span
Style = "font-family:; MSO-ascii-font-family: 'times new Roman '; MSO-Hansi-font-family: 'times new Roman '"> the preceding restriction is that you cannot bind multiple field values to one of the four attributes; however, </span> <SPAN lang = "en"> SQL </span> <span style = "font-family:; MSO-ascii-font-family: 'times new Roman '; MSO-Hansi-font-family:
'Times new Roman '"> the statement has no such restriction. Therefore, the first method is to use </span> <SPAN lang = "en"> SQL </span> <span style = "font-family:; MSO-ascii-font-family: 'times new Roman '; MSO-Hansi-font-family: 'times new Roman '"> the statement binds two or more Field Values in the source table, use </span> <SPAN lang = "en"> as </span> <span style = "font-family:
MSO; MSO-ascii-font-family: 'times new Roman '; MSO-Hansi-font-family: 'times new Roman' "> the sub-statement is passed to another field, in this way, a field contains multiple field values. A field contains the values of multiple fields, we assign a value to </span> <SPAN lang = "en"> Web </span> <span style = "font-family:; MSO-ascii-font-family: 'times new Roman '; MSO-Hansi-font-family:
'Times new Roman '"> you do not need to consider the four properties of the control. We can refer to the following statements to see the advantages of this method: </span> </font> </P> <Div align = "center"> <Table class = "msotablegrid" style = "border-Right: Medium none; border-top: Medium none; Background: # f3f3f3; border-left: Medium none; border-bottom: Medium
None; border-collapse: collapse; MSO-border-alt: solid windowtext. 5pt; MSO-yfti-tbllook: 480; MSO-padding-alt: 0 cm 5.4pt 0 cm 5.4pt; MSO-border-insideh :. 5pt solid windowtext; MSO-border-insidev :. 5pt solid windowtext "cellspacing =" 0 "cellpadding =" 0 "border =" 1 ">
<Tbody> <tr style = "MSO-yfti-irow: 0; MSO-yfti-firstrow: Yes; MSO-yfti-lastrow: yes "> <TD style =" border-Right: windowtext 1pt solid; padding-Right: 5.4pt; border-top: windowtext 1pt solid; padding-left: 5.4pt; padding-bottom: 0 cm; border-left: windowtext 1pt
Solid; width: 392.4pt; padding-top: 0 cm; border-bottom: windowtext 1pt solid; Background-color: transparent; MSO-border-alt: solid windowtext. 5pt "valign =" TOP "width =" 523 "> <P class =" msonormal "style =" margin: 0 cm 0 cm 0pt "> <SPAN lang =" en "style =" font-size:
9pt; font-family: New; MSO-Hansi-font-family: 'times new Roman '; MSO-font-kerning: 0pt "> <font size =" 4 "> strcmd =" select employeeid, lastname + ',' + firstname as 'ployeename' from employees "; </font> </span> </P> </TD> </tr> </tbody> </table> </div> <P class = "msonormal"
Style = "margin: 0 cm 0 cm 0pt; text-indent: 21pt"> <font size = "4"> <span style = "font-family:; MSO-ascii-font-family: 'times new Roman '; MSO-Hansi-font-family: 'times new Roman' "> this method is very simple, it is also the most direct method, but there is a problem of insufficient efficiency, and duplicate data may be generated. Next we will introduce another method. We can populate the source table with a dataset </span> <Span
Lang = "en"> dataset </span> <span style = "font-family:; MSO-ascii-font-family: 'times new Roman '; MSO-Hansi-font-family: 'times new Roman '"> medium, then place the dataset data into a data table </span> <SPAN lang = "en"> datatable </span> <span style = "font-family:; MSO-ascii-font-family: 'times
New Roman '; MSO-Hansi-font-family: 'times new Roman' ">, and then create a new column for the table, this column is composed of two or more fields in the source table, so that we can bind multiple field values. The following statement describes the implementation of this method: </span> </font> </P> <Div align = "center"> <Table class = "msotablegrid" style = "border-Right: Medium none; border-top: Medium none; Background:
# F3f3f3; border-left: Medium none; border-bottom: Medium none; border-collapse: collapse; MSO-border-alt: solid windowtext. 5pt; MSO-yfti-tbllook: 480; MSO-padding-alt: 0 cm 5.4pt 0 cm 5.4pt; MSO-border-insideh :. 5pt solid windowtext; MSO-border-insidev :. 5pt
Solid windowtext "cellspacing =" 0 "cellpadding =" 0 "border =" 1 "> <tbody> <tr style =" MSO-yfti-irow: 0; MSO-yfti-firstrow: Yes; MSO-yfti-lastrow: yes "> <TD style =" border-Right: windowtext 1pt solid; padding-Right: 5.4pt; border-top: windowtext 1pt solid; padding-left:
5.4pt; padding-bottom: 0 cm; border-left: windowtext 1pt solid; width: 389.05pt; padding-top: 0 cm; border-bottom: windowtext 1pt solid; Background-color: transparent; MSO-border-alt: solid windowtext. 5pt "valign =" TOP "width =" 519 "> <P class =" msonormal "style =" margin:
0 cm 0 cm 0pt "> <SPAN lang =" en "> <font size =" 4 "> DT. columns. add ("employeename", typeod (string), "lastname + ',' + firstname "); </font> </span> </P> </TD> </tr> </tbody> </table> </div> <P class = "msonormal" Style = "margin: 0 cm 0 cm 0pt; text-indent: 21pt "> <span style =" font-family:
; MSO-ascii-font-family: 'times new Roman '; MSO-Hansi-font-family: 'times new Roman '"> <font size =" 4 "> the disadvantage of the latter method is the overhead of creating new columns. However, this method is clear and does not produce duplicate data. We recommend that you use this method. </Font> </span> </P> <P class = "msonormal" style = "margin: 0 cm 0 cm 0pt; text-indent: 21pt "> <span style =" font-family:
; MSO-ascii-font-family: 'times new Roman '; MSO-Hansi-font-family: 'times new Roman '"> <font size =" 4 "> to illustrate the two methods, the following code puts the two methods together for implementation: </font> </span> </P> <Div align = "center"> <Table class = "msotablegrid" style = "border-Right: Medium none; border-top: Medium none;
Background: # f3f3f3; border-left: Medium none; border-bottom: Medium none; border-collapse: collapse; MSO-border-alt: solid windowtext. 5pt; MSO-yfti-tbllook: 480; MSO-padding-alt: 0 cm 5.4pt 0 cm 5.4pt; MSO-border-insideh :. 5pt solid windowtext; MSO-border-insidev:
. 5pt solid windowtext "cellspacing =" 0 "cellpadding =" 0 "border =" 1 "> <tbody> <tr style =" MSO-yfti-irow: 0; MSO-yfti-firstrow: Yes; MSO-yfti-lastrow: yes "> <TD style =" border-Right: windowtext 1pt solid; padding-Right: 5.4pt; border-top: windowtext 1pt solid; padding-left:
5.4pt; padding-bottom: 0 cm; border-left: windowtext 1pt solid; width: 392.4pt; padding-top: 0 cm; border-bottom: windowtext 1pt solid; Background-color: transparent; MSO-border-alt: solid windowtext. 5pt "valign =" TOP "width =" 523 "> <P class =" msonormal "style =" margin:
0 cm 0 cm 0pt; text-align: Left; MSO-layout-grid-align: none "align =" Left "> <font size =" 4 "> <SPAN lang =" en "style =" font-size: 9pt; color: green; font-family: new; MSO-Hansi-font-family: 'times new Roman '; MSO-font-kerning: 0pt "> // </span> <span style =" font-size:
9pt; color: green; font-family: New; MSO-Hansi-font-family: 'times new Roman '; MSO-font-kerning: 0pt "> place user code here to initialize the page <SPAN lang =" en "> <? XML: namespace prefix = o ns = "urn: Schemas-Microsoft-com: Office: office"/> <O: P> </O: p> </span> </font> </P> <P class = "msonormal"
Style = "margin: 0 cm 0 cm 0pt; text-align: Left; MSO-layout-grid-align: none "align =" Left "> <font size =" 4 "> <SPAN lang =" en "style =" font-size: 9pt; color: Blue; font-family: new; MSO-Hansi-font-family: 'times new Roman '; MSO-font-kerning: 0pt "> string </span> <Span
Lang = "en" style = "font-size: 9pt; font-family: New; MSO-Hansi-font-family: 'times new Roman '; MSO-font-kerning: 0pt "> strconn, strcmd; <span style =" color: Green "> <O: P> </O: p> </span> </font> </P> <P class = "msonormal" style = "margin: 0 cm 0 cm 0pt; text-align:
Left; MSO-layout-grid-align: none "align =" Left "> <SPAN lang =" en "style =" font-size: 9pt; font-family: new; MSO-Hansi-font-family: 'times new Roman '; MSO-font-kerning: 0pt "> <font size =" 4 "> strconn =" database = northwind; server = localhost; uid = sa; Pwd = 99133009; "; <O: p> </O: P> </font> </span> </P>
<P class = "msonormal" style = "margin: 0 cm 0 cm 0pt; text-align: Left; MSO-layout-grid-align: none "align =" Left "> <font size =" 4 "> <SPAN lang =" en "style =" font-size: 9pt; color: green; font-family: new; MSO-Hansi-font-family: 'times new Roman '; MSO-font-kerning: 0pt ">/// </span> <Span
Style = "font-size: 9pt; color: green; font-family: New; MSO-Hansi-font-family: 'times new Roman '; MSO-font-kerning: 0pt "> if you need to bind <SPAN lang =" en "> firstname </span> and <SPAN lang =" en "> lastname </span>, they need to be used separately, and the following statement will generate duplicate data. <SPAN lang = "en"> <O: P> </span> </font> </P>
<P class = "msonormal" style = "margin: 0 cm 0 cm 0pt; text-align: Left; MSO-layout-grid-align: none "align =" Left "> <SPAN lang =" en "style =" font-size: 9pt; font-family: New; MSO-Hansi-font-family: 'times new Roman '; MSO-font-kerning: 0pt "> <font size =" 4 "> strcmd =" select
Employeeid, firstname, lastname, lastname + ',' + firstname as 'ployeename' from employees "; <O: P> </O: p> </font> </span> </P> <P class = "msonormal" style = "margin: 0 cm 0 cm 0pt; text-align: left; MSO-layout-grid-align: none "align =" Left "> <SPAN lang =" en "style =" font-size:
9pt; font-family: New; MSO-Hansi-font-family: 'times new Roman '; MSO-font-kerning: 0pt "> <font size =" 4 "> sqldataadapter dsda = <span style =" color: Blue "> New </span> sqldataadapter (strcmd, strconn); <O: p>
Dataset DS = new dataset ();
Dsda. Fill (DS, "employeelist ");
Datatable dt = Ds. Tables ["employeelist"];
// Method 1
// Ddl1 is a dropdownlist control.
Ddl1.datasource = DT. defaultview;
Ddl1.datatextfield = "employeename ";
Ddl1.datavaluefield = "employeeid ";
Ddl1.databind ();
/* Method 2
DT. Columns. Add ("employeename", typeod (string), "lastname + ',' + firstname ");
Ddl1.datatextfield = "employeename ";
Ddl1.databind ();
*/