Confirmation of delete c#

J

John Smith

Hello all,

I don't know c# that well and thus need urget help. I have a page that
displays files from an access database that has a button to be delet file
from database. I need a confirmation box to make sure the user wants to
delet the file. Here is my code:
private string GetFilesFromAccessDb()

{

StringBuilder buffer = new StringBuilder(1024);

buffer.Append("<table align=\"center\" width=\"95%\" border=\"0\"
cellspacing=\"2\" cellpadding=\"2\">");

buffer.Append("<tr><td width=\"40%\"><span
class=\"dimColor\">Name</span></td>");

buffer.Append("<td width=\"20%\" align=\"center\"><span
class=\"dimColor\">Size</span></td>");

buffer.Append("<td width=\"40%\" align=\"center\"><span
class=\"dimColor\">Content Type</span></td></tr>");


using(OleDbConnection con = new OleDbConnection(ConnectionString))

using(OleDbCommand cmd = new OleDbCommand(CmdText, con))

{

con.Open();

OleDbDataReader rd = cmd.ExecuteReader(CommandBehavior.SingleResult |
CommandBehavior.CloseConnection);

while(rd.Read())

{

int fileId;

string fileName;

int fileLength;

string contentType;

fileId = rd.GetInt32(0);

fileName = rd.GetString(1);

fileLength = rd.GetInt32(2);

contentType = rd.GetString(3);

buffer.Append("<tr><td><a href=\"file.aspx?file_id=");

buffer.Append(fileId);

buffer.Append("&mode=view\">");

buffer.Append(fileName);

buffer.Append("</a>");

buffer.Append("</a> [ <a href=\"file.aspx?file_id=");

buffer.Append(fileId);

buffer.Append("&mode=delete\"><font color = red>Del</a></font> ]");

buffer.Append(" [<a href=\"file.aspx?file_id=");

buffer.Append(fileId);

buffer.Append("&mode=download\"><font color = green>Dnld</a></font> ]");

//buffer.Append("<INPUT TYPE = BUTTON NAME = dnldButton VALUE = download
onClick)";

//buffer.Append("<INPUT TYPE = BUTTON NAME = delButton VALUE = Delete>");



buffer.Append("</td><td align=\"center\">");

buffer.Append(fileLength);

buffer.Append("</td><td align=\"center\">");

buffer.Append(contentType);

buffer.Append("</td></tr>");


}

rd.Close();

buffer.Append("</table>");

}

return buffer.ToString();

}



How do i do this?

cheers
 
G

Guest

John,

Are you using ASP.NET? It seems you are trying to generate web pages
dynamically by your StringBuilder which is unnecessary. The ideal way to do
this is to use the VS.NET to design (draw) a page and inside page you can use
controls and maybe you can bind those controls to your data source. You can
also call your C# function inside the aspx file by the tag like <% %> or <%
=something() %>.

In your case, if you want to confirm something with users, you can create a
page contains a button or something and handle the postback; or you can write
some javascript in your client code and pop up a dialog box directly from
user's browser to ask users.

Let me know if you need further help.

John Smith said:
Hello all,

I don't know c# that well and thus need urget help. I have a page that
displays files from an access database that has a button to be delet file
from database. I need a confirmation box to make sure the user wants to
delet the file. Here is my code:
private string GetFilesFromAccessDb()

{

StringBuilder buffer = new StringBuilder(1024);

buffer.Append("<table align=\"center\" width=\"95%\" border=\"0\"
cellspacing=\"2\" cellpadding=\"2\">");

buffer.Append("<tr><td width=\"40%\"><span
class=\"dimColor\">Name</span></td>");

buffer.Append("<td width=\"20%\" align=\"center\"><span
class=\"dimColor\">Size</span></td>");

buffer.Append("<td width=\"40%\" align=\"center\"><span
class=\"dimColor\">Content Type</span></td></tr>");


using(OleDbConnection con = new OleDbConnection(ConnectionString))

using(OleDbCommand cmd = new OleDbCommand(CmdText, con))

{

con.Open();

OleDbDataReader rd = cmd.ExecuteReader(CommandBehavior.SingleResult |
CommandBehavior.CloseConnection);

while(rd.Read())

{

int fileId;

string fileName;

int fileLength;

string contentType;

fileId = rd.GetInt32(0);

fileName = rd.GetString(1);

fileLength = rd.GetInt32(2);

contentType = rd.GetString(3);

buffer.Append("<tr><td><a href=\"file.aspx?file_id=");

buffer.Append(fileId);

buffer.Append("&mode=view\">");

buffer.Append(fileName);

buffer.Append("</a>");

buffer.Append("</a> [ <a href=\"file.aspx?file_id=");

buffer.Append(fileId);

buffer.Append("&mode=delete\"><font color = red>Del</a></font> ]");

buffer.Append(" [<a href=\"file.aspx?file_id=");

buffer.Append(fileId);

buffer.Append("&mode=download\"><font color = green>Dnld</a></font> ]");

//buffer.Append("<INPUT TYPE = BUTTON NAME = dnldButton VALUE = download
onClick)";

//buffer.Append("<INPUT TYPE = BUTTON NAME = delButton VALUE = Delete>");



buffer.Append("</td><td align=\"center\">");

buffer.Append(fileLength);

buffer.Append("</td><td align=\"center\">");

buffer.Append(contentType);

buffer.Append("</td></tr>");


}

rd.Close();

buffer.Append("</table>");

}

return buffer.ToString();

}



How do i do this?

cheers
 
J

John Smith

I am using this code off a freely available source. I do not know c# very
well, but udnerstandd what you mean. Is there anyway to do in its current
form?


cheers
Yang Lu said:
John,

Are you using ASP.NET? It seems you are trying to generate web pages
dynamically by your StringBuilder which is unnecessary. The ideal way to
do
this is to use the VS.NET to design (draw) a page and inside page you can
use
controls and maybe you can bind those controls to your data source. You
can
also call your C# function inside the aspx file by the tag like <% %> or
<%
=something() %>.

In your case, if you want to confirm something with users, you can create
a
page contains a button or something and handle the postback; or you can
write
some javascript in your client code and pop up a dialog box directly from
user's browser to ask users.

Let me know if you need further help.

John Smith said:
Hello all,

I don't know c# that well and thus need urget help. I have a page that
displays files from an access database that has a button to be delet file
from database. I need a confirmation box to make sure the user wants to
delet the file. Here is my code:
private string GetFilesFromAccessDb()

{

StringBuilder buffer = new StringBuilder(1024);

buffer.Append("<table align=\"center\" width=\"95%\" border=\"0\"
cellspacing=\"2\" cellpadding=\"2\">");

buffer.Append("<tr><td width=\"40%\"><span
class=\"dimColor\">Name</span></td>");

buffer.Append("<td width=\"20%\" align=\"center\"><span
class=\"dimColor\">Size</span></td>");

buffer.Append("<td width=\"40%\" align=\"center\"><span
class=\"dimColor\">Content Type</span></td></tr>");


using(OleDbConnection con = new OleDbConnection(ConnectionString))

using(OleDbCommand cmd = new OleDbCommand(CmdText, con))

{

con.Open();

OleDbDataReader rd = cmd.ExecuteReader(CommandBehavior.SingleResult |
CommandBehavior.CloseConnection);

while(rd.Read())

{

int fileId;

string fileName;

int fileLength;

string contentType;

fileId = rd.GetInt32(0);

fileName = rd.GetString(1);

fileLength = rd.GetInt32(2);

contentType = rd.GetString(3);

buffer.Append("<tr><td><a href=\"file.aspx?file_id=");

buffer.Append(fileId);

buffer.Append("&mode=view\">");

buffer.Append(fileName);

buffer.Append("</a>");

buffer.Append("</a> [ <a href=\"file.aspx?file_id=");

buffer.Append(fileId);

buffer.Append("&mode=delete\"><font color = red>Del</a></font> ]");

buffer.Append(" [<a href=\"file.aspx?file_id=");

buffer.Append(fileId);

buffer.Append("&mode=download\"><font color = green>Dnld</a></font> ]");

//buffer.Append("<INPUT TYPE = BUTTON NAME = dnldButton VALUE = download
onClick)";

//buffer.Append("<INPUT TYPE = BUTTON NAME = delButton VALUE = Delete>");



buffer.Append("</td><td align=\"center\">");

buffer.Append(fileLength);

buffer.Append("</td><td align=\"center\">");

buffer.Append(contentType);

buffer.Append("</td></tr>");


}

rd.Close();

buffer.Append("</table>");

}

return buffer.ToString();

}



How do i do this?

cheers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top