Dim SQL = "Select * From 成绩单" Adpt = New OleDbDataAdapter( SQL, Conn ) Ds = New Dataset() Adpt.Fill(Ds, "成绩单") MyDataList.DataSource = Ds.Tables( "成绩单" ).DefaultView MyDataList.DataBind() Conn.Close() End Sub Sub Page_Load(sender As Object, e As EventArgs) If Not IsPostBack Then OpenDatabase_and_LinkToDataList() End If End Sub Sub DataList_ItemCommand(sender As Object, e As DataListCommandEventArgs) If e.CommandSource.Text = "成绩查询" Then MyDataList.SelectedIndex = e.Item.ItemIndex ElseIf e.CommandSource.Text = "关闭查询" Then MyDataList.SelectedIndex = -1 End If OpenDatabase_and_LinkToDataList() End Sub</script>
-----------------------------------------------------------
<script language="javascript">
function ShowDetailPage(object)
{
window.showModalDialog("../FeedBackMS/ShowDetailLotInfo.aspx?LotID="+object.name,"","scrollbars=yes;resizable=no;help=no;status=no;dialogTop=150;dialogLeft=200;dialogWidth=660px;dialogHeight=430px");
return;
}
</script>
<asp:TemplateColumn SortExpression="Lot" HeaderText="LotID">
<HeaderStyle HorizontalAlign="Center" ForeColor="White" VerticalAlign="Middle" BackColor="#999999"
CssClass="TR-Bar1"></HeaderStyle>
<ItemStyle HorizontalAlign="left"></ItemStyle>
<ItemTemplate>
<a href="javascript:void(null)" style="CURSOR: hand; TEXT-DECORATION: underline" title="点击显示此 LotID 的详细信息" onclick="ShowDetailPage(this);return;" name='<%# DataBinder.Eval(Container.DataItem, "Lot")%>'>
<%# DataBinder.Eval(Container.DataItem, "Lot")%>
</a>
</ItemTemplate>
</asp:TemplateColumn>
<asp:ButtonColumn DataTextField="ConSN" HeaderText="ConID" CommandName="ShowConInfo">
<HeaderStyle Width="18%"></HeaderStyle>
</asp:ButtonColumn>
后台:
private void DataGrid1_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if(e.CommandName=="ShowConInfo")
Response.Redirect("Newpage.aspx?ConID="+e.Item.Cells[0].Text);
}
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %><Html>
<Body BgColor="White">
<H3>DList6.aspx -- 设定 SelectedItemTemplate (被选项样版)<HR></H3>
<Blockquote>
<Form runat="server"><asp:DataList id="MyDataList" runat="server"
Border="1" BorderColor="Black"
CellPadding="2" CellSpacing="0"
HeaderStyle-BackColor="#aaaadd"
AlternatingItemStyle-BackColor="lightgray"
SelectedItemStyle-BackColor="yellow"
OnItemCommand="DataList_ItemCommand" ><HeaderTemplate>
姓名(学号)
</HeaderTemplate><ItemTemplate>
<%# Container.DataItem("姓名")%>
(<%# Container.DataItem("学号")%>)
<asp:LinkButton id="Detail" runat="server" Text="成绩查询"/>
</ItemTemplate><SelectedItemTemplate>
姓名: <%# Container.DataItem("姓名")%><BR>
学号: <%# Container.DataItem("学号")%><BR>
语文: <%# Container.DataItem("语文")%><BR>
英文: <%# Container.DataItem("英文")%><BR>
数学: <%# Container.DataItem("数学")%><BR>
<asp:LinkButton id="Title" runat="server" Text="关闭查询"/>
</SelectedItemTemplate></asp:DataList></Form>
<p></Blockquote>
<HR></Body>
</Html><script Language="VB" runat="server"> Sub OpenDatabase_and_LinkToDataList()
Dim Conn As OleDbConnection
Dim Adpt As OleDbDataAdapter
Dim Ds As DataSet Dim Provider = "Provider=Microsoft.Jet.OLEDB.4.0"
Dim Database = "Data Source=" & Server.MapPath( "Sample.mdb" )
Conn = New OleDbConnection( Provider & ";" & DataBase )
Conn.Open()
Dim SQL = "Select * From 成绩单"
Adpt = New OleDbDataAdapter( SQL, Conn ) Ds = New Dataset()
Adpt.Fill(Ds, "成绩单") MyDataList.DataSource = Ds.Tables( "成绩单" ).DefaultView
MyDataList.DataBind() Conn.Close()
End Sub Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
OpenDatabase_and_LinkToDataList()
End If
End Sub Sub DataList_ItemCommand(sender As Object, e As DataListCommandEventArgs)
If e.CommandSource.Text = "成绩查询" Then
MyDataList.SelectedIndex = e.Item.ItemIndex
ElseIf e.CommandSource.Text = "关闭查询" Then
MyDataList.SelectedIndex = -1
End If
OpenDatabase_and_LinkToDataList()
End Sub</script>
{
e.Item.Attributes.Add("onclick","window.open('WebForm2.aspx?ZoneNo="+e.Item.Cells[1].Text+"')");
e.Item.Attributes.Add("onMouseOver","this.style.backgroundColor='#000000'; this.style.cursor='hand';");
e.Item.Attributes.Add("onMouseOut","this.style.backgroundColor='#ffffff';");
}