• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Asp.net2.0(C#)图片存储到数据库和从数据库读取显示

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

最近捣鼓了一下,效果就是这样:
图1:


图2:


ImageFileUpload.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ImageFileUpload.aspx.cs" Inherits="ImageFileUpload" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    
<title>图片保存和显示</title>
</head>
<body>
    
<form id="Form2" enctype="multipart/form-data" runat="server">

            
<asp:Table ID="Table1" Runat="server" Width="39%" BorderWidth="1" BackColor="Beige">

                        
<asp:TableRow runat="server">

                                    
<asp:TableCell ColumnSpan="2" BackColor="Red" runat="server">

                                    
<asp:Label ID="Label1" Font-size="12px" ForeColor="White" font-bold="True" Runat="server" Text="添加" Font-Names="verdana" />

                                    
</asp:TableCell>

                        
</asp:TableRow>

                        
<asp:TableRow runat="server">

                                    
<asp:TableCell HorizontalAlign="Right" runat="server"><asp:Label ID="Label2" Font-size="12px"  Runat="server" Text="名字" Font-Names="verdana" /></asp:TableCell>

                                    
<asp:TableCell runat="server"><asp:TextBox id="txtPersonName" Runat="server" /></asp:TableCell>

                        
</asp:TableRow>

                        
<asp:TableRow runat="server">

                                    
<asp:TableCell HorizontalAlign="Right" runat="server"><asp:Label ID="Label3" Font-size="12px"  Runat="server" Text="Email" Font-Names="verdana" /></asp:TableCell>

                                    
<asp:TableCell runat="server"><asp:TextBox id="txtPersonEmail" Runat="server" /></asp:TableCell>

                        
</asp:TableRow>

                        
<asp:TableRow runat="server">

                                    
<asp:TableCell HorizontalAlign="Right" runat="server"><asp:Label ID="Label4" Font-size="12px"  Runat="server" Text="性别" Font-Names="verdana" /></asp:TableCell>

                                    
<asp:TableCell runat="server">

                                                
<asp:RadioButton GroupName="sex"  Font-Size="12px" Text="男性" ID="sexMale" Runat="server"   Checked="true" />

                                                
<asp:RadioButton GroupName="sex"  Font-Size="12px" Text="女性" ID="sexFeMale" Runat="server" />

                                    
</asp:TableCell>

                        
</asp:TableRow>

                        
<asp:TableRow runat="server">

                                    
<asp:TableCell HorizontalAlign="Right" runat="server"><asp:Label ID="Label5" Font-size="12px"  Runat="server" Text="生日" Font-Names="verdana" /></asp:TableCell>

                                    
<asp:TableCell runat="server"><asp:TextBox id="txtPersonDob" runat="server" /></asp:TableCell>

                        
</asp:TableRow>

                        
<asp:TableRow runat="server">

                                    
<asp:TableCell HorizontalAlign="Right" runat="server"><asp:Label ID="Label6" Font-size="12px"  Runat="server" Text="图片" Font-Names="verdana" /></asp:TableCell>

                                    
<asp:TableCell runat="server"><input type="file" id="PersonImage" runat="server" /></asp:TableCell>

                        
</asp:TableRow>

                        
<asp:TableRow runat="server">

                                    
<asp:TableCell ColumnSpan="2" HorizontalAlign="Center" runat="server">

                                    
<asp:Button ID="Button1" Text="添加" OnClick="AddPerson" runat="server" />

                                    
</asp:TableCell>

                        
</asp:TableRow>

            
</asp:Table>
        
<br />
        
<table>
            
<tr>
                
<td align="left" valign="top" style="width: 181px">
                    
<asp:Label ID="Label_Message" runat="server" Font-Size="10pt"></asp:Label></td>
                
<td style="width: 7px">
                
</td>
                
<td align="left" style="width: 18px" valign="top">
                
</td>
            
</tr>
            
<tr>
                
<td style="width: 181px;" align="left" valign="top">
                    
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="PersonID" DataSourceID="SqlDataSource_SelectImage" ForeColor="#333333" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" Font-Size="10pt" Width="200px" BackColor="#FFE0C0">
                        
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                        
<Columns>
                            
<asp:TemplateField HeaderText="序号" InsertVisible="False" SortExpression="PersonID">
                                
<EditItemTemplate>
                                    
<asp:Label ID="Label1" runat="server" Text='<%# Eval("PersonID") %>'></asp:Label>
                                
</EditItemTemplate>
                                
<ItemTemplate>
                                    
<asp:Label ID="Label1" runat="server" Text='<%# Bind("PersonID") %>'></asp:Label>
                                
</ItemTemplate>
                                
<HeaderStyle Width="35px" />
                            
</asp:TemplateField>
                            
<asp:BoundField DataField="PersonName" HeaderText="名字" SortExpression="PersonName" />
                            
<asp:BoundField DataField="PersonImageType" HeaderText="图片类型" SortExpression="PersonImageType" />
                            
<asp:CommandField ShowSelectButton="True" >
                                
<ItemStyle Width="30px" />
                            
</asp:CommandField>
                        
</Columns>
                        
<RowStyle BackColor="#EFF3FB" />
                        
<EditRowStyle BackColor="#2461BF" />
                        
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                        
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                        
<HeaderStyle BackColor="Red" Font-Bold="True" ForeColor="White" />
                        
<AlternatingRowStyle BackColor="White" />
                    
</asp:GridView>
                
</td>
                
<td style="width: 7px; height: 180px;">
                
</td>
                
<td align="left" style="width: 18px; height: 180px;" valign="top">
                    
<asp:Image ID="Image_Show" runat="server" /></td>
            
</tr>
            
<tr>
                
<td style="width: 181px">

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C#XML操作类XmlHelper发布时间:2022-07-14
下一篇:
c# SqlBulkCopy实现批量从数据集中把数据导入到数据库中发布时间:2022-07-14
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap