⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dataview-binding.aspx

📁 This is a book about vb.you could learn this from this book
💻 ASPX
字号:
<%@Page Language="VB"%>

<%@Import Namespace="System.Data" %>

<%@ Register TagPrefix="wrox" TagName="connect" Src="..\global\connect-strings.ascx" %>
<%@ Register TagPrefix="wrox" TagName="getdataview" Src="..\global\get-dataview-control.ascx" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<title>Repeated-Value Data Binding to a DataView Object</title>
<style type="text/css">
body, td {font-family:Tahoma,Arial,sans-serif; font-size:10pt}
input {font-family:Tahoma,Arial,sans-serif; font-size:9pt}
.heading {font-family:Tahoma,Arial,sans-serif; font-size:14pt; font-weight:bold}
.subhead {font-family:Tahoma,Arial,sans-serif; font-size:12pt; font-weight:bold; padding-bottom:5px}
.cite {font-family:Tahoma,Arial,sans-serif; font-size:8pt}
</style></head>
<body bgcolor="#ffffff">
<span class="heading">Repeated-Value Data Binding to a DataView Object</span><hr />
<!--------------------------------------------------------------------------->

<%'-- insert connection string script --%>
<wrox:connect id="ctlConnectStrings" runat="server"/>

<%'-- insert the control that creates the DataSet --%>
<wrox:getdataview id="ctlDataView" runat="server"/>


<form runat="server">

HTML <b>&lt;select&gt;</b> elements:<br />
<select id="MySelectList" runat="server" /><p />

<b>&lt;ASP:DropDownList&gt;</b> controls:<br />
<ASP:DropDownList id="MyDropDown" runat="server" /><p />

<b>&lt;ASP:ListBox&gt;</b> controls:<br />
<ASP:ListBox id="MyASPList" runat="server" /><p />

<b>&lt;ASP:DataGrid&gt;</b> control:<br />
<ASP:DataGrid id="MyDataGrid" runat="server" /><p />

<b>&lt;ASP:Repeater&gt;</b> control:<br />
<ASP:Repeater id="MyRepeater" runat="server">
  <ItemTemplate>
    <div>
      <b><%# Container.DataItem("Title") %></b><br />
      ISBN: <%# Container.DataItem("ISBN") %> &nbsp;
      Published: <%# DataBinder.Eval(Container.DataItem, "PublicationDate", "{0:D}") %>
    </div>
  </ItemTemplate>
</ASP:Repeater><p />

<b>&lt;ASP:DataList&gt;</b> control:<br />
<ASP:DataList id="MyDataList" runat="server">
  <ItemTemplate>
      <b><%# Container.DataItem("Title") %></b><br />
      ISBN: <%# Container.DataItem("ISBN") %> &nbsp;
      Published: <%# DataBinder.Eval(Container.DataItem, "PublicationDate", "{0:D}") %>
  </ItemTemplate>
</ASP:DataList><p />

<b>&lt;ASP:CheckBoxList&gt;</b> control:<br />
<ASP:CheckBoxList id="MyCheckList" runat="server" /><p />

<b>&lt;ASP:RadioButtonList&gt;</b> control:<br />
<ASP:RadioButtonList id="MyRadioList" runat="server" /><p />

</form>

<!--------------------------------------------------------------------------->

<script language="vb" runat="server">

Sub Page_Load()

   'get connection string from ..\global\connect-strings.ascx user control
   Dim strConnect As String  = ctlConnectStrings.OLEDBConnectionString

   'create a SQL statement to select some rows from the database
   Dim strSelect As String
   strSelect = "SELECT * FROM BookList WHERE ISBN LIKE '18610029%'"

   'create a variable to hold an instance of a DataView object
   Dim objDataView As DataView

   'get DataView from get-dataview-control.ascx user control
   objDataView = ctlDataView.GetDataView(strConnect, strSelect)

   If IsNothing(objDataView) Then Exit Sub

   'set the DataSource property of the controls

   '<select> list displays values from the Title column
   'and uses the ISBN as the <option> values
   MySelectList.DataSource = objDataView
   MySelectList.DataValueField = "ISBN"
   MySelectList.DataTextField = "Title"

   'do same with ASP: list controls
   MyDropDown.DataSource = objDataView
   MyDropDown.DataValueField = "ISBN"
   MyDropDown.DataTextField = "Title"

   MyASPList.DataSource = objDataView
   MyASPList.DataValueField = "ISBN"
   MyASPList.DataTextField = "Title"

   'a DataGrid can figure out the columns in the DataView
   'by itself, so we just set the DataSource property
   MyDataGrid.DataSource = objDataView

   'the Repeater and DataList require <ItemTemplate> entries
   'that specify the columns - this is done within the element
   'definition earlier in the page
   MyRepeater.DataSource = objDataView
   MyDataList.DataSource = objDataView

   'in the CheckboxList we'll display the Title and
   'use the Value as the control value
   MyCheckList.DataSource = objDataView
   MyCheckList.DataValueField = "ISBN"
   MyCheckList.DataTextField = "Title"

   'in the RadioList we'll display and format the
   'Value and use the Key as the control value
   MyRadioList.DataSource = objDataView
   MyRadioList.DataValueField = "ISBN"
   MyRadioList.DataTextField = "PublicationDate"
   MyRadioList.DataTextFormatString = "Published on {0:dddd, MMMM dd, yyyy}"

   'finally, bind all the controls on the page
   Page.DataBind()

End Sub

</script>

<!--------------------------------------------------------------------------->
<!-- #include file="..\global\foot.inc" -->
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -