|
发表于 2020-10-16 15:00:01
|
显示全部楼层
<%@ Page Language="vb" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script language="VB" runat="server">
dim MyConnection As OleDbConnection
Sub Page_Load(s As Object, E As EventArgs)
MyConnection = New OleDbConnection( "Provider=Microsoft.Jet.OLEDB.4.0; Data Source =" + Server.MapPath(".")+"/db/kk.mdb")
If Not (IsPostBack) then
BindDataGrid()
End If
End Sub
Sub BindDataGrid()
dim dadTitles as OleDbDataAdapter
dim dstTitles as DataSet
dadTitles=new OleDbDataAdapter("select * from [imgs] order by id desc",MyConnection)
dstTitles=new DataSet
dadTitles.fill(dstTitles)
MyDataGrid.DataSource=dstTitles
MyDataGrid.DataBind()
End Sub
Sub Mydatagrid_PageIndexChanged(s as object,e as DataGridPageChangedEventargs)
MyDataGrid.CurrentPageIndex=e.newPageIndex
BindDataGrid()
End Sub
Function FormatURL(strArgument) as String
Return ("RetrieveImgByDataGrid_SelectImg.aspx?id=" & strArgument)
End Function
</script>
<html>
<head><title>DataGrid_CheckBox.aspx</title></head>
<body>
<B><A HREF="insertimgtodatabase.aspx">Insert Img To DataBase</A></B>
<form runat="server">
<asp:DataGrid id="MyDataGrid"
width="300"
Runat="server"
AllowPaging="true"
pageSize="5"
OnPageIndexChanged="Mydatagrid_PageIndexChanged"
cellPadding="3"
AutoGenerateColumns="false"
HeaderStyle-BackColor="#ff0000"
HeaderStyle-Font-Bold="True"
HeaderStyle-Font-Name="Verdana"
HeaderStyle-Font-Size="13px"
HeaderStyle-ForeColor="#ffffff"
ItemStyle-BackColor=Beige
ItemStyle-Font-Name="verdana"
ItemStyle-Font-Size="13px"
>
<PagerStyle Mode="NumericPages"
Font-Bold="true"
BackColor="#FFCC99"
HorizontalAlign="right"
>
</PagerStyle>
<Columns>
<asp:TemplateColumn HeaderText="ID">
<ItemTemplate>
<asp:Label ID="lblID" Text='<%# DataBinder.Eval(Container.DataItem, "id") %>' Runat=server />
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="NAME">
<ItemTemplate>
<asp:Label ID="lblName" Text='<%# DataBinder.Eval(Container.DataItem, "name") %>' Runat=server />
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Image">
<ItemTemplate>
<asp:Image Width="150" Height="125" ImageUrl='<%# FormatURL(DataBinder.Eval(Container.DataItem, "ID")) %>' Runat=server />
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="ShowImage_HyperLink">
<ItemTemplate>
<asp:HyperLink Width="150" Height="125" ImageUrl='<%# FormatURL(DataBinder.Eval(Container.DataItem, "ID")) %>' NavigateUrl='<%# "RetrieveImgByDataGrid_SelectImg.aspx?id=" & DataBinder.Eval(Container.DataItem, "ID")%>' Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
</form>
</body>
</html>
|
|