my aspx file
<%@ Page Language="C#" MasterPageFile="~/fowlmereplaygroup.master" AutoEventWireup="true" CodeFile="AdminPhoto.aspx.cs" Inherits="AdminPhoto" Title="Untitled Page" %>
Photo Admin
my aspx.cs file
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class AdminPhoto : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// Define data objects
SqlConnection conn;
SqlCommand comm;
SqlDataReader reader;
// Read the connection string from Web.Config
string connectionString = ConfigurationManager.ConnectionStrings["fowlmereplaygroup"].ConnectionString;
// Initialise connection
conn = new SqlConnection(connectionString);
// Create Command
comm = new SqlCommand("SELECT PhotoID, PhotoLocation FROM Photos", conn);
// Enclose database code in try catch finally
try
{
// Open the connection
conn.Open();
// Execute the command
reader = comm.ExecuteReader();
// Fill the grid with data
PhotoView.DataSource = reader;
PhotoView.DataBind();
// Close the reader
reader.Close();
}
finally
{
// Close the connectionString
conn.Close();
}
}
protected void Deletebtn_Click(object sender, EventArgs e)
{
for (int vLoop = 13; vLoop < PhotoView.Rows.Count; vLoop++)
{
CheckBox PhotoChk = (CheckBox)PhotoView.Rows[vLoop].FindControl("PhotoChk");
if (PhotoChk.Checked == true)
{
Label PhotoIDlbl = (Label)PhotoView.Rows[vLoop].FindControl("PhotoIDlbl");
int PhotoID = Convert.ToInt32(PhotoIDlbl.Text);
// using the PhotoID, delete that record. by using sqlcommand and its executenonquery() method
// Define data objects
SqlConnection conn;
SqlCommand comm;
// Read the connection string from Web.Config
string connectionString = ConfigurationManager.ConnectionStrings["fowlmereplaygroup"].ConnectionString;
// Initialise connection
conn = new SqlConnection(connectionString);
// Create Command
comm = new SqlCommand("DELETE FROM Photos WHERE PhotoID=@PhotoID", conn);
// Add Comand Parameters
comm.Parameters.Add("@PhotoID", System.Data.SqlDbType.Int);
comm.Parameters["@PhotoID"].Value = PhotoIDlbl.Text;
try
{
// Open the connection
conn.Open();
// Execute the command
comm.ExecuteNonQuery();
}
catch
{
// Display error message
dbErrorMessage.Text = "Error deleting event";
}
finally
{
// Close the connection
conn.Close();
}
Label PhotoLocationlbl = (Label)PhotoView.Rows[vLoop].FindControl("PhotoLocationlbl");
string filepath = PhotoLocationlbl.Text;
System.IO.File.Delete(filepath);
}
}
}
}
phil camfieldPosted Oct 13, 2008, 5:10 AM
my aspx file
my aspx.cs file is
protected void Deletebtn_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox cb = (CheckBox)row.FindControl("chkgrid");
if (cb.Checked)
{
int PhotoID = Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Value);
SqlDataSource1.DeleteParameters["PhotoID"].DefaultValue = PhotoID.ToString();
SqlDataSource1.Delete();
}
}
}
Vijaya KadiyalaPosted Oct 9, 2008, 1:46 PM
HI
Look at the below code modify it based on your control names.
Thanks
-- Vjhttp
://dotnetvj.blogspot.comhttp
://oravj.blogspot.com