this is my aspx.cs code.........
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.IO;
public partial class gallery : System.Web.UI.Page
{
String fn;
String path;
SqlConnection cnn = new SqlConnection();
SqlCommand cmd = new SqlCommand();
SqlDataAdapter adp;
DataTable dt;
Int32 id;
String album_name;
String caption;
String image;
protected void Page_Load(object sender, EventArgs e)
{
cnn.ConnectionString = ConfigurationManager.ConnectionStrings["Data Source=CIODEV03\\SQLEXPRESS;Initial Catalog=EmployeeDB;Integrated Security=True"].ConnectionString;
cnn.Open();
if (cnn.State == ConnectionState.Closed)
{
cnn.Open();
}
cnn.Close();
if (IsPostBack == false)
{
grd_bind();
}
}
protected void btninsert_Click(object sender, EventArgs e)
{
if (txtuploder.PostedFile.ContentLength > 0)
{
fn = Path.GetFileName(txtuploder.FileName);
path = Server.MapPath("images") + "/" + fn;
txtuploder.SaveAs(path);
}
if (cnn.State == ConnectionState.Closed)
{
cnn.Open();
}
SqlCommand cmd = new SqlCommand("tb_gallery_insert", cnn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = cnn;
cmd.Parameters.AddWithValue("@album_name", txtalbum.Text);
cmd.Parameters.AddWithValue("@caption", txtcaption.Text);
cmd.Parameters.AddWithValue("@image", fn);
cmd.ExecuteNonQuery();
cmd.Dispose();
grd_bind();
cnn.Close();
clr();
}
private void grd_bind()
{
if (cnn.State == ConnectionState.Closed)
{
cnn.Open(); }
adp = new SqlDataAdapter("SELECT * FROM tb_gallery ", cnn);
dt = new DataTable();
adp.Fill(dt);
adp.Dispose();
GridView1.DataSource = dt;
GridView1.DataBind();
}
private void clr()
{
txtalbum.Text = "";
txtcaption.Text = "";
}
protected void GridView1_RowDeleted(object sender, GridViewDeletedEventArgs e)
{
try
{
if (cnn.State == ConnectionState.Closed)
{
cnn.Open();
}
id = Convert.ToInt32(((Label)(GridView1.Rows[e.RowIndex].FindControl("label2"))).Text);
SqlCommand cmd = new SqlCommand("tb_gallery_delete", cnn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = cnn;
cmd.Parameters.Add("@id", SqlDbType.Int).Value = id;
SqlDataAdapter adp = new SqlDataAdapter("select * from tb_gallery where id=@id", cnn);
adp.SelectCommand.Parameters.Add("@id", SqlDbType.Int).Value = id;
DataSet ds = new DataSet();
adp.Fill(ds);
try
{
image = Convert.ToString(ds.Tables[0].Rows[0]["image"]);
File.Delete(Server.MapPath("images") + "\\" + image);
}
catch { }
cmd.ExecuteNonQuery();
cmd.Dispose();
grd_bind();
}
catch {
}
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
grd_bind();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
grd_bind();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
if (cnn.State == ConnectionState.Closed)
{
cnn.Open();
}
id = Convert.ToInt32(((Label)(GridView1.Rows[e.RowIndex].FindControl("label4"))).Text);
album_name = (((TextBox)(GridView1.Rows[e.RowIndex].FindControl("txt_album_name"))).Text);
caption = (((TextBox)(GridView1.Rows[e.RowIndex].FindControl("txt_caption"))).Text);
SqlCommand cmd = new SqlCommand("tb_gallery_update", cnn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = cnn;
cmd.Parameters.Add("@id", SqlDbType.Int).Value = id;
cmd.Parameters.Add("@album_name", SqlDbType.VarChar, 50).Value = album_name;
cmd.Parameters.Add("@caption", SqlDbType.VarChar, 50).Value = caption;
cmd.ExecuteNonQuery();
cmd.Dispose();
GridView1.EditIndex = -1;
grd_bind();
}
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
GridView1.PageIndex = e.NewSelectedIndex;
grd_bind();
}
}
this is my aspx code...........
lang="xml"><%@ Page Language="C#" AutoEventWireup="true" CodeFile="gallery.aspx.cs" Inherits="gallery" %>
<!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="form1" runat="server">
<div>
<asp:TextBox ID="txtalbum" runat="server"></asp:TextBox>
<asp:Label ID="Label1" runat="server" Text="AlbumName"></asp:Label>
<br />
<br />
<asp:TextBox ID="txtcaption" runat="server"></asp:TextBox>
<asp:Label ID="Label2" runat="server" Text="Caption"></asp:Label>
<br />
<br />
<asp:FileUpload ID="txtuploder" runat="server" />
<asp:Label ID="Label3" runat="server" Text="Image"></asp:Label>
<br />
<br />
<asp:Button ID="btninsert" runat="server" Text="Insert"
onclick="btninsert_Click" />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
onrowcancelingedit="GridView1_RowCancelingEdit"
onrowdeleting="GridView1_RowDeleting" onrowediting="GridView1_RowEditing"
onrowupdating="GridView1_RowUpdating"
onselectedindexchanging="GridView1_SelectedIndexChanging"
onselectedindexchanged="GridView1_SelectedIndexChanged">
<Columns>
<%----%>
<asp:TemplateField HeaderText="Album_name">
<EditItemTemplate>
<%----%>
<asp:TextBox ID="txt_album_name" runat="server"
Text='<%# Eval("album_name") %>'></asp:TextBox>
<asp:Label ID="Label4" runat="server" Text='<%# Eval("id") %>' Visible="False"></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("album_name") %>'></asp:Label>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("id") %>' Visible="False"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Caption">
<EditItemTemplate>
<asp:TextBox ID="txt_caption" runat="server" Text='<%# Eval("caption") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Eval("caption") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Image">
<ItemTemplate>
<%----%>
<img alt ="" src ='images/<%#Eval("image") %>' height="50px" width="50px"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Delete">
<%----%>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"
CommandName="Delete"
onclientclick="return confirm('are you sure you want to delet this column')">Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Update">
<EditItemTemplate>
<%----%>
<asp:LinkButton ID="LinkButton3" runat="server" CausesValidation="False"
CommandName="Update">Update</asp:LinkButton>
<asp:LinkButton ID="LinkButton4" runat="server" CausesValidation="False"
CommandName="Cancel">Cancel</asp:LinkButton>
</EditItemTemplate>
<ItemTemplate>
<%----%>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False"
CommandName="Edit">Edit</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
this is error..................
Server Error in '/WebSite11' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1061: 'System.Web.UI.WebControls.GridViewDeletedEventArgs' does not contain a definition for 'RowIndex' and no extension method 'RowIndex' accepting a first argument of type 'System.Web.UI.WebControls.GridViewDeletedEventArgs' could be found (are you missing a using directive or an assembly reference?)
Source Error:
Line 105: }<br />
Line 106:<br />
Line 107: id = Convert.ToInt32(((Label)(GridView1.Rows[e.RowIndex].FindControl("label2"))).Text);<br />
Line 108: <br />
Line 109: SqlCommand cmd = new SqlCommand("tb_gallery_delete", cnn);