Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3224462
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:13:34+00:00 2026-05-17T16:13:34+00:00

I have a Gridview which displays the filenames in the database. I have written

  • 0

I have a Gridview which displays the filenames in the database.

alt text

I have written code for deleting filename entry from database, but I also want to delete it from the directory, so how do I retrieve filename from Gridview ?

I don’t want to execute another select command for retrieving filename.

Code :

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
     int Fid = (int)GridView1.DataKeys[e.RowIndex].Value;
     sdsFiles.DeleteCommand = "Delete from Files where Fid = @id";
     sdsFiles.DeleteParameters.Clear();
     sdsFiles.DeleteParameters.Add("id",Fid.ToString());
     sdsFiles.Delete();
     System.IO.Directory.Delete(Server.MapPath("~/Data/"));
}

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T16:13:34+00:00Added an answer on May 17, 2026 at 4:13 pm

    Use the following code and do steps;

    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int Fid = (int)GridView1.DataKeys[e.RowIndex].Value;
        sdsFiles.DeleteCommand = "Delete from Files where Fid = @id";
        sdsFiles.DeleteParameters.Clear();
        sdsFiles.DeleteParameters.Add("id",Fid.ToString());
        sdsFiles.Delete();
        string fileName = ((Label)GridView1.Rows[e.RowIndex].FindControl("Label1")).Text;
        System.IO.File.Delete(Server.MapPath("") + "\\" + fileName);
    }
        
    
    1. you must go to gridview columns
      window

    2. Convert to file name column to
      TemplateField

    3. Save and Exit GridView Columns window

    4. Go to Files column template design

    5. Set label id "Label1"

    6. Go to code and use it

      alt text

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my aspx page I have a gridview which displays the value from my
hey guys, i have a gridview which displays 10records per page, now i want
want to have a Hyperlink-Button in a gridView in which I can display a
I have a GridView which is programatically filled from the DB (not a SqlDataSource
Have a gridview control which will show X amount of rows. I want to
I have a gridview which displays data for all employees and their images (stored
So I have an ASP.NET page with two controls: a GridView which displays rows
I have one web part (the provider) which displays insurance claims in a gridview.
I have a few aspx pages which displays GridView controls. In each control I
I have a gridview which displays rows and columns all linked to an sql

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.