Sie sind auf Seite 1von 3

using using using using using using using using

System; System.Collections.Generic; System.Linq; System.Web; System.Web.UI; System.Web.UI.WebControls; System.Data.SqlClient; System.Data;

public partial class upload_page : System.Web.UI.Page { SqlConnection con = new SqlConnection("Data Source=GAUTAM-PC\\GKS;Initial Ca talog=regis;Integrated Security=True"); protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { if (FileUpload1.HasFile) { //save image into database string str = FileUpload1.FileName; FileUpload1.PostedFile.SaveAs(Server.MapPath(".") + "//uploads//" + str); string path = "~//uploads//" + str.ToString(); con.Open(); SqlCommand cmd = new SqlCommand("insert into uploads values('"+TextB ox1.Text+"','"+path+"')",con); cmd.ExecuteNonQuery(); con.Close(); Lb1.Text = "Image upload successfully"; //upload image in grid view SqlDataAdapter da = new SqlDataAdapter("select * from uploads",con); DataTable dt = new DataTable(); da.Fill(dt); GridView1.DataSource = dt; DataBind(); } else { Lb1.Text = "Plz upload ur image"; } } } //css <%@ Page Language="C#" AutoEventWireup="true" CodeFile="upload_page.aspx.cs" Inh erits="upload_page" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or g/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <style type="text/css"> .style1 {

width: 100%; height: 42px; } .style2 { width: 210px; } </style> </head> <body> <form id="form1" runat="server"> <table class="style1"> <tr> <td> <table class="style1"> <tr> <td class="style2"> Name</td> <td> <asp:TextBox ID="TextBox1" runat="server" style="mar gin-left: 90px" Width="215px"></asp:TextBox> </td> </tr> <tr> <td class="style2"> Photo</td> <td> <asp:FileUpload ID="FileUpload1" runat="server" styl e="margin-left: 92px" Width="212px" /> </td> </tr> <tr> <td class="style2"> &nbsp;</td> <td> <asp:Button ID="Button1" runat="server" onclick="But ton1_Click" style="margin-left: 95px" Text="Upload" Width="2 14px" /> </td> </tr> <tr> <td class="style2"> <asp:Label ID="Lb1" runat="server" style="font-weigh t: 700; color: #FF3300" Text="Label"></asp:Label> </td> <td> &nbsp;</td> </tr> <tr> <td class="style2"> <asp:GridView ID="GridView1" runat="server" BackColo r="White" AutoGenerateColumns="false" BorderColor="#CC9966" BorderStyle="None" BorderW idth="1px" CellPadding="4"> <FooterStyle BackColor="#FFFFCC" ForeColor="#330 099" />

<HeaderStyle BackColor="#990000" Font-Bold="True " ForeColor="#FFFFCC" /> <PagerStyle BackColor="#FFFFCC" ForeColor="#3300 99" HorizontalAlign="Center" /> <RowStyle BackColor="White" ForeColor="#330099" /> <SelectedRowStyle BackColor="#FFCC66" Font-Bold= "True" ForeColor="#663399" /> <SortedAscendingCellStyle BackColor="#FEFCEB" /> <SortedAscendingHeaderStyle BackColor="#AF0101" /> <SortedDescendingCellStyle BackColor="#F6F0C0" / > <SortedDescendingHeaderStyle BackColor="#7E0000" /> <Columns> <asp:TemplateField HeaderText="UID"> <ItemTemplate> <asp:label ID="lb1" runat="server" Text='<%#Eval ("UID") %>'>'></asp:label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Name"> <ItemTemplate> <asp:label ID="lb1" runat="server" Text='<%#Eval ("Uname") %>'>'></asp:label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Photo"> <ItemTemplate> <asp:Image ID="img" runat="server" ImageUrl='<%# Eval("Image") %>' Height="100" Width="100" /> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> </td> </tr> </table> </td> </tr> </table> </form> </body> </html>

Das könnte Ihnen auch gefallen