Image Upload Delete Update
Image Upload Delete Update
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.IO;
using System.Configuration;
namespace fileuploadwithprocedure
{
public partial class fileupload : System.Web.UI.Page
{
}
public void Display()
{
con.Open();
SqlCommand cmd = new SqlCommand("Emp_select", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
con.Close();
grdvu.DataSource = dt;
grdvu.DataBind();
}
protected void grdvu_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName=="D")
{
con.Open();
SqlCommand cmd = new SqlCommand("Emp_delete", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@argu_id",e.CommandArgument);
cmd.ExecuteNonQuery();
con.Close();
Display();
}
else if
(e.CommandName =="E")
{
con.Open();
SqlCommand cmd = new SqlCommand("Emp_Edit", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@argu_id", e.CommandArgument);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
con.Close();
textname.Text = dt.Rows[0]["Name"].ToString();
Textage.Text = dt.Rows[0]["Age"].ToString();
ViewState["IMMG"]= dt.Rows[0]["Imag"].ToString();
ViewState["argumtid"] = e.CommandArgument;
btnsave.Text = "Update";
}
}
con.Open();
SqlCommand cmd = new SqlCommand("Emp_insert", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@name", textname.Text);
cmd.Parameters.AddWithValue("@age", Textage.Text);
cmd.Parameters.AddWithValue("@imag", FILNM);
// cmd.Parameters.AddWithValue("@rsm", FILNM123);
cmd.ExecuteNonQuery();
con.Close();
textname.Text = "";
Textage.Text = "";
Display();
lbl.Text = "your record has been saved successfully!!";
}
else
{
lbl.Text = "Sorry.... your image extention is not coreect !!";
}
}
if (btnsave.Text == "Update")
{
string FILNM = Path.GetFileName(fiumage.PostedFile.FileName);
{
if (FILNM != "" )
{
FILNM = Path.GetFileName(fiumage.PostedFile.FileName);//
YH image ka name nilaklne ke liye use kiya hai kioki image folder ke ander save
hota hai or image ka name databse me save haota hai
else
{
lbl.Text = "Please Select the image !!";
}
}
}
}
}
}
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>Name:</td>
<td><asp:TextBox ID="textname" runat
="server"></asp:TextBox></td>
</tr>
<tr>
<td>Age:</td>
<td><asp:TextBox ID="Textage" runat
="server"></asp:TextBox></td>
</tr>
<tr>
<td>Imag:</td>
<td><asp:FileUpload ID ="fiumage" runat ="server" /></td>
</tr>
<tr>
<td></td>
<td><asp:button ID="btnsave" runat ="server" Text ="Save"
OnClick ="btnsave_Click"></asp:button></td>
</tr>
<tr>
<td></td>
<td><asp:Label ID="lbl" runat ="server" ForeColor="Red"
></asp:Label></td>
</tr>
<tr>
<td></td>
<td><asp:gridview ID="grdvu" runat ="server" Text="Display"
OnRowCommand ="grdvu_RowCommand" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText ="Student id " >
<ItemTemplate >
<%#Eval("id") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Student Name " >
<ItemTemplate >
<%#Eval("Name") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Student Age " >
<ItemTemplate >
<%#Eval("Age") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Student Imag " >
<ItemTemplate >
<asp:Image ID="image4" runat ="server" Width
="100px" ImageUrl ='<%# Eval ("Imag","~/PICS/{0}") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate >
<asp:LinkButton ID ="btndelete" runat ="server"
text ="Delete" CommandArgument ='<%#Eval("id") %>' CommandName
="D"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Student id " >
<ItemTemplate >
<asp:LinkButton ID ="btnedit" runat="server" Text
="Edit" CommandArgument =' <%#Eval("id") %>' CommandName ="E"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:gridview></td>
</tr>
</table>
</div>
</form>
</body>
</html>