首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

百分请问System.Web.UI.WebControls.TextBox

2012-09-18 
百分请教System.Web.UI.WebControls.TextBox?我添加内容的时候,有的不写。数据库字段里会出现System.Web.UI

百分请教System.Web.UI.WebControls.TextBox?
我添加内容的时候,有的不写。数据库字段里会出现System.Web.UI.WebControls.TextBox

还有就是我点编辑后我以前上传好的图片路径也变成了System.Web.UI.WebControls.TextBox。希望高手帮一下忙,谢谢了。

我的代码如下:

C# code
using System;using System.Data;using System.IO;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 admin_AddNew : System.Web.UI.Page{    protected void Page_Load(object sender, EventArgs e)    {        pageload();    }    private void pageload()    {       //网页加载        if (!IsPostBack)        {            //CommFun.IsAdmin();            string strqry;            DBFun.FillDwList(dw_ProductClass,"select Id,Name from BigClass");            string Action=Request.QueryString["Action"];            string id =Request.QueryString["Id"];            string allid=Request.QueryString["AllId"];            if (Action=="Edit"&& id !=null)            {               //显示信息并加以修改                strqry=string .Format("select * from T_News where id={0}",id);                DataRow dr =DBFun .GetDataView (strqry).Table.Rows[0];                tb_ProductName.Text=dr["Title"].ToString();                dw_ProductClass.Text=dr["Name"].ToString();                tb_ReadCount.Text=dr["ReadCount"].ToString();                tb_PicUrl .Text =dr["ProductPic"].ToString();                tb_VideoUrl.Text= dr["VideoUrl"].ToString();                tb_PicUrl.Text = dr["PlayUrl"].ToString();                FreeTextBox1.Text=dr["Content"].ToString();                img_pic.Src="..\\image\\"+dr["ProductPic"].ToString();                pan_Add.Visible =false;                pan_Edit.Visible =true;                btn_Ok .Text="修改";            }            else            {              pan_Add.Visible = true;              pan_Edit.Visible = false;              btn_Ok.Text = "添加";              img_pic.Visible = false;                        }                }    }    protected void btn_Ok_Click(object sender, EventArgs e)    {        //修改        modify();    }    private void modify()    {        string strsql;        if (btn_Ok.Text == "修改")        {            string id = Request.QueryString["id"];            if (id == null || id == "")                return;            string img_url;            img_url = img(myfileEdit);            if (img_url == "")            {                img_url = tb_PicUrl.Text;                if (img_url == "")                    img_url = "nopic.jpg";//如果不上传!为默认图片              }            strsql = string.Format("Update T_News set Title='{0}',BigClassId={1},Name='{2}'," + " ProductPic='{3}',ReadCount={4},VideoUrl='{5}',PlayUrl='{6}',Content='{7}' where id ={8}", tb_ProductName.Text, dw_ProductClass.Text, dw_ProductClass.SelectedItem.Text, img_url, tb_ReadCount.Text, tb_VideoUrl.Text,tb_PlayUrl,FreeTextBox1.Text.Replace("'", "''"), id);            if (DBFun.ExecuteUpdate(strsql))            {                Response.Write("<script>alert('修改成功!');window.location.href='AddNew.aspx?Action=Edit&ID=" + id + "';</script>");            }            else            {                Response.Write("<script>alert('修改失败!请确认输入是否正确。');</script>");            }        }        else        {            //添加            string img_url;            img_url = img(myfileAdd);            if (img_url == "")                img_url = "nopic.jpg";            strsql = string.Format("Insert into [T_News] (Title,BigClassId,Name,"                   + "ProductPic,ReadCount,VideoUrl,PlayUrl,Content) values('{0}',{1},'{2}','{3}',{4},'{5}','{6}','{7}')",                   tb_ProductName.Text, dw_ProductClass.Text, dw_ProductClass.SelectedItem.Text,                   img_url, tb_ReadCount.Text,tb_VideoUrl, tb_PlayUrl.Text, FreeTextBox1.Text.Replace("'", "''"));            if (DBFun.ExecuteUpdate(strsql))            {                string NewId = DBFun.SearchValue("Select Max(id) from T_News");                Response.Write("<script>alert('添加成功!');window.location.href='AddNew.aspx?Action=Edit&ID=" + NewId + "';</script>");            }            else            {                Response.Write("<script>alert('添加失败!请确认输入是否正确!');</script>");            }        }    }    private string img(System.Web.UI.HtmlControls.HtmlInputFile Fupload)    {        //文件上传        try        {            if (Fupload.PostedFile.FileName == "")                return "";            string dir = DateTime.Now.ToString("yyyyMM");            if (!Directory.Exists(Server.MapPath("..\\image\\") + dir))            {                Directory.CreateDirectory(Server.MapPath("..\\image\\") + dir);                if (!Directory.Exists(Server.MapPath("..\\image\\") + dir))                    return "";            }            Random rd = new System.Random();            string filename;            string extname;            if (Fupload.PostedFile.FileName != "")            {                extname = Fupload.PostedFile.FileName.Substring(Fupload.PostedFile.FileName.LastIndexOf(".") + 1).ToUpper();                if ("JPG|GIF|BMP|PNG".IndexOf(extname) == -1)                {                    return "";                }                filename = dir + "\\" + DateTime.Now.ToString("yyyyMM") + rd.Next(1000).ToString() + "." + extname;                Fupload.PostedFile.SaveAs(Server.MapPath("..\\image\\") + filename);                return filename;            }            return "";        }        catch { return ""; }    }} 



[解决办法]
出现楼主所说的情况,应该是往数据写值的时候,没有得到控件的值,而只得到了控件的类型

楼主这种SQL插入写法,我没有用过,所以,不太清楚哪里不对,表面看起来没什么错呀
[解决办法]
调试了下,也没有看出来有错
[解决办法]
页面: 
<%@ Page language="c#" Codebehind="filesystem.aspx.cs" AutoEventWireup="false" Inherits="WebShop.filesystem" %> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > 
<HTML> 
<HEAD> 
<title>filesystem</title> 
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR"> 
<meta content="C#" name="CODE_LANGUAGE"> 
<meta content="JavaScript" name="vs_defaultClientScript"> 
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema"> 
<LINK href="CssStyle.css" type="text/css" rel="stylesheet"> 
<form id="Form1" method="post" runat="server"> 
</HEAD> 
<body MS_POSITIONING="GridLayout"> 
<FONT face="宋体"> 
<table cellSpacing="1" cellPadding="0" width="777" align="center" bgColor="#336600" border="0"> 
<tr> 
<td bgColor="#08498c" colSpan="3"><IMG src="images/FileSystemBaner.gif"></td> 
</tr> 
<tr> 
<td width="170" bgColor="#e3e3e3" rowSpan="2">
<asp:linkbutton id="LinkButton1" runat="server">后退</asp:linkbutton></td> 
<td width="604" bgColor="#efefef" colSpan="2">
<asp:datalist id="DataList1" runat="server" RepeatColumns="4" RepeatDirection="Horizontal" DataKeyField="Name" 
Width="604"> 
<ItemTemplate> 
<table width="150" align="center"> 
<tr> 
<td align="center" width="10"></td> 
<td align="left" width="140"><%#DataBinder.Eval(Container.DataItem,"Image")%> 
</td> 
</tr> 
<tr> 
<td width="10" align="right"> 
<asp:CheckBox ID="checkBox1" Runat="server" /></td> 
<td width="140" align="left"><font face="宋体"><%#DataBinder.Eval(Container.DataItem,"Name")%></font></td> 
</tr> 
</table> 
</ItemTemplate> 
</asp:datalist></td> 
</tr> 
<tr> 
<td align="right" bgColor="#efefef" colSpan="2"><asp:button id="Button3" runat="server" Text="删除选中项"></asp:button>
<input id="fileFeild1" type="file" name="fileFeild1" runat="server">
<asp:button id="Button1" runat="server" Text="确定上传"></asp:button><br> 
<asp:textbox id="TextBox1" runat="server"></asp:textbox>
<asp:button id="Button2" runat="server" Text="创建目录"></asp:button></td> 
</tr> 
<tr> 


<td bgColor="#888888" colSpan="3"><span class="STYLE1"><asp:label id="Label2" runat="server" ForeColor="White"> 当前所在位置:</asp:label><SPAN class="STYLE1"><asp:label id="Label1" runat="server" ForeColor="White" Width="87px"></asp:label></SPAN></span></td> 
</tr> 
</table> 
</FONT></FORM> 
</body> 
</HTML> 

后台代码: 
using System; 
using System.Collections; 
using System.ComponentModel; 
using System.Data; 
using System.IO; 
using System.Drawing; 
using System.Web; 
using System.Web.SessionState; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Web.UI.HtmlControls; 

namespace WebShop 

/// <summary> 
/// filesystem 的摘要说明。 
/// </summary> 
public class filesystem : System.Web.UI.Page 

protected System.Web.UI.WebControls.LinkButton LinkButton1; 
protected System.Web.UI.WebControls.DataList DataList1; 
protected System.Web.UI.WebControls.Button Button3; 
protected System.Web.UI.WebControls.Button Button1; 
protected System.Web.UI.WebControls.TextBox TextBox1; 
protected System.Web.UI.WebControls.Button Button2; 
protected System.Web.UI.WebControls.Label Label2; 
protected System.Web.UI.WebControls.Label Label1; 
protected System.Web.UI.HtmlControls.HtmlInputFile fileFeild1; 

private void Page_Load(object sender, System.EventArgs e) 

if(!IsPostBack) 

Bind(); 



private void Bind() 

string initpath=""; 
if(Request["path"]==null) 

initpath=Server.MapPath("FileSystem"); 

else 

initpath=Request["path"]; 

this.Label1.Text=initpath; 

DataTable dt=new DataTable(); 
DataColumn dc0=new DataColumn("Image",System.Type.GetType("System.String")); 
dt.Columns.Add(dc0); 
DataColumn dc1=new DataColumn("Name",System.Type.GetType("System.String")); 
dt.Columns.Add(dc1); 

DirectoryInfo di=new DirectoryInfo(this.Label1.Text); 
DirectoryInfo[] dis=di.GetDirectories(); 
foreach(DirectoryInfo d in dis) 

DataRow dr=dt.NewRow(); 
dr[0]="<a href='filesystem.aspx?path="+HttpUtility.UrlEncode(d.FullName,System.Text.Encoding.UTF8)+"'><img src='images/folder.gif' border=0/></a>"; 
dr[1]=d.Name; 
dt.Rows.Add(dr); 


FileInfo[] fis=di.GetFiles(); 
foreach(FileInfo f in fis) 

string ex=f.Extension.ToLower(); 
if(ex==".jpg" || ex==".jpeg" || ex==".gif" || ex==".png" || ex==".bmp") 

string fullname=f.FullName; 
string urlpath=fullname.Substring(fullname.IndexOf("FileSystem")); 
string url=HttpUtility.UrlEncode(urlpath,System.Text.Encoding.UTF8); 
DataRow dr=dt.NewRow(); 
dr[0]="<a href='"+url+"' target='_blank'><img src='"+url+"' border=0 width=100 height=128/></a>"; 
dr[1]=f.Name; 
dt.Rows.Add(dr); 



this.DataList1.DataSource=dt; 
this.DataList1.DataBind(); 


#region Web 窗体设计器生成的代码 


override protected void OnInit(EventArgs e) 

// 
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 
// 
InitializeComponent(); 
base.OnInit(e); 


/// <summary> 
/// 设计器支持所需的方法 - 不要使用代码编辑器修改 
/// 此方法的内容。 
/// </summary> 
private void InitializeComponent() 

this.LinkButton1.Click += new System.EventHandler(this.LinkButton1_Click); 
this.Button3.Click += new System.EventHandler(this.Button3_Click); 
this.Button1.Click += new System.EventHandler(this.Button1_Click); 
this.Button2.Click += new System.EventHandler(this.Button2_Click); 
this.Load += new System.EventHandler(this.Page_Load); 


#endregion 

private void LinkButton1_Click(object sender, System.EventArgs e) 

string Parent=Directory.GetParent(this.Label1.Text).ToString(); 
if(Parent.IndexOf("FileSystem")>-1) 

Response.Redirect("filesystem.aspx?path="+Parent); 

else 

return; 



private void Button1_Click(object sender, System.EventArgs e) 

HttpPostedFile hpf=this.fileFeild1.PostedFile; 
string ClientPath=hpf.FileName; 
string filename=Path.GetFileName(ClientPath); 
string ex=Path.GetExtension(filename); 
if(ex==".jpg" || ex==".jpeg" || ex==".gif" || ex==".png" || ex==".bmp") 

string SavePath=this.Label1.Text+"\\"+filename; 
hpf.SaveAs(SavePath); 
Bind(); 

else 

Response.Write(Tools.GetAlertJS("所上传的图片格式不正确!")); 
return; 



private void Button2_Click(object sender, System.EventArgs e) 

string filename=this.TextBox1.Text; 
Directory.CreateDirectory(this.Label1.Text+"\\"+filename); 
Bind(); 


private void Button3_Click(object sender, System.EventArgs e) 

for(int i=0;i<this.DataList1.Items.Count;i++) 

if(((CheckBox)this.DataList1.Items[i].FindControl("CheckBox1")).Checked) 

int index=this.DataList1.Items[i].ItemIndex; 
string filePath=this.Label1.Text+"\\"+this.DataList1.DataKeys[index].ToString(); 
if(Directory.Exists(filePath)) 

Directory.Delete(filePath,true); 

if(File.Exists(filePath)) 

File.Delete(filePath); 

Bind(); 




}
[解决办法]
或许是组SQL语句的问题,楼主也没说是哪几个字段没有值,哪几个字段插入的值是控件的类型。
 strsql = string.Format("Insert into [T_News] (Title,BigClassId,Name,"
+ "ProductPic,ReadCount,VideoUrl,PlayUrl,Content) values('{0}',{1},'{2}','{3}',{4},'{5}','{6}','{7}')",
tb_ProductName.Text, dw_ProductClass.Text, dw_ProductClass.SelectedItem.Text,
img_url, tb_ReadCount.Text,tb_VideoUrl, tb_PlayUrl.Text, FreeTextBox1.Text.Replace("'", "''"));
上面这一句strsql的值对吗,放在查询分析器里能执行吗?
如果像楼主说的字段插入的值是控件的类型的话,从strsql的值里就能看出来吧。
还有最好不要用小写的string,最好用大写的String。

如果strsql的值是对的,那你从DBFun.ExecuteUpdate(strsql)追进去,看执行到哪一步的时候SQL语句变了?
[解决办法]
你传的参数类型对吗?你传了七个参数,现在看全是string类型,数据库里是吗?
[解决办法]
1 其实想解决很简单,就是你单步调试看看哪部分执行异常导致sql语句变形,重点关注那两个sql语句形成部分!


2 提问题要写完全点,比如你说的第一个小问题,你得说下倒底是哪个字段被填充成了syste。web。。。。。
[解决办法]
还有一点,
strsql = string.Format("Insert into [T_News] (Title,BigClassId,Name,"
+ "ProductPic,ReadCount,VideoUrl,PlayUrl,Content) values('{0}',{1},'{2}','{3}',{4},'{5}','{6}','{7}')",
tb_ProductName.Text, dw_ProductClass.Text, dw_ProductClass.SelectedItem.Text,
img_url, tb_ReadCount.Text,tb_VideoUrl, tb_PlayUrl.Text, FreeTextBox1.Text.Replace("'", "''")); 
最好把('{0}',{1},'{2}','{3}',{4},'{5}','{6}','{7}')改成({0},{1},{2},{3},{4},{5},{6},{7}),赋值时把数据类型写正确就可以了,字符类型的可以考虑加个ToString(),也就是tb_ReadCount.Text.ToString()。
[解决办法]
第2个参数{1}赋值dw_ProductClass.Text,
第5个参数{4}赋值tb_ReadCount.Text,
第6个参数{5}赋值tb_VideoUrl,
这几个对吗?
[解决办法]
是不是所用组件中取得的属性不对?
[解决办法]
Fupload.PostedFile.SaveAs(Server.MapPath("..\\image\\") + filename);
改为Fupload.PostedFile.SaveAs(Server.MapPath("~\\image\\") + filename);

调试的时候可以先把try{}catch{}注释掉,这样比较容易发现问题
[解决办法]
楼主代码处tb_PlayUrl后少了.Text
5楼代码处tb_VideoUrl后少了.Text
由于你用的是stirng.Format,所以你不写.Text的话,编译器就会调用该类的.ToString()方法,也就是返回它的类名System.Web.UI.WebControl.TextBox
以后要记得仔细一点
[解决办法]
mark
[解决办法]

探讨
楼主代码处tb_PlayUrl后少了.Text
5楼代码处tb_VideoUrl后少了.Text
由于你用的是stirng.Format,所以你不写.Text的话,编译器就会调用该类的.ToString()方法,也就是返回它的类名System.Web.UI.WebControl.TextBox
以后要记得仔细一点

[解决办法]
你得访问 Textbox.Text 属性获取值,而不是直接传 TextBox 会导致内部调用 TextBox.ToString() // 返回类型名
[解决办法]
学习!
[解决办法]
页面: 
<%@ Page language="c#" Codebehind="filesystem.aspx.cs" AutoEventWireup="false" Inherits="WebShop.filesystem" %> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > 
<HTML> 
<HEAD> 
<title>filesystem </title> 
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR"> 
<meta content="C#" name="CODE_LANGUAGE"> 
<meta content="JavaScript" name="vs_defaultClientScript"> 
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema"> 
<LINK href="CssStyle.css" type="text/css" rel="stylesheet"> 
<form id="Form1" method="post" runat="server"> 
</HEAD> 
<body MS_POSITIONING="GridLayout"> 
<FONT face="宋体"> 
<table cellSpacing="1" cellPadding="0" width="777" align="center" bgColor="#336600" border="0"> 
<tr> 
<td bgColor="#08498c" colSpan="3"> <IMG src="images/FileSystemBaner.gif"> </td> 
</tr> 
<tr> 
<td width="170" bgColor="#e3e3e3" rowSpan="2">


<asp:linkbutton id="LinkButton1" runat="server">后退 </asp:linkbutton> </td> 
<td width="604" bgColor="#efefef" colSpan="2">
<asp:datalist id="DataList1" runat="server" RepeatColumns="4" RepeatDirection="Horizontal" DataKeyField="Name" 
Width="604"> 
<ItemTemplate> 
<table width="150" align="center"> 
<tr> 
<td align="center" width="10"> </td> 
<td align="left" width="140"> <%#DataBinder.Eval(Container.DataItem,"Image")%> 
</td> 
</tr> 
<tr> 
<td width="10" align="right"> 
<asp:CheckBox ID="checkBox1" Runat="server" /> </td> 
<td width="140" align="left"> <font face="宋体"> <%#DataBinder.Eval(Container.DataItem,"Name")%> </font> </td> 
</tr> 
</table> 
</ItemTemplate> 
</asp:datalist> </td> 
</tr> 
<tr> 
<td align="right" bgColor="#efefef" colSpan="2"> <asp:button id="Button3" runat="server" Text="删除选中项"> </asp:button>
<input id="fileFeild1" type="file" name="fileFeild1" runat="server">
<asp:button id="Button1" runat="server" Text="确定上传"> </asp:button> <br> 
<asp:textbox id="TextBox1" runat="server"> </asp:textbox>
<asp:button id="Button2" runat="server" Text="创建目录"> </asp:button> </td> 
</tr> 
<tr> 
<td bgColor="#888888" colSpan="3"> <span class="STYLE1"> <asp:label id="Label2" runat="server" ForeColor="White"> 当前所在位置: </asp:label> <SPAN class="STYLE1"> <asp:label id="Label1" runat="server" ForeColor="White" Width="87px"> </asp:label> </SPAN> </span> </td> 
</tr> 
</table> 
</FONT> </FORM> 
</body> 
</HTML> 

后台代码: 
using System; 
using System.Collections; 
using System.ComponentModel; 
using System.Data; 
using System.IO; 
using System.Drawing; 
using System.Web; 
using System.Web.SessionState; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Web.UI.HtmlControls; 

namespace WebShop 

/// <summary> 
/// filesystem 的摘要说明。 
/// </summary> 
public class filesystem : System.Web.UI.Page 

protected System.Web.UI.WebControls.LinkButton LinkButton1; 
protected System.Web.UI.WebControls.DataList DataList1; 
protected System.Web.UI.WebControls.Button Button3; 
protected System.Web.UI.WebControls.Button Button1; 
protected System.Web.UI.WebControls.TextBox TextBox1; 
protected System.Web.UI.WebControls.Button Button2; 
protected System.Web.UI.WebControls.Label Label2; 
protected System.Web.UI.WebControls.Label Label1; 
protected System.Web.UI.HtmlControls.HtmlInputFile fileFeild1; 

private void Page_Load(object sender, System.EventArgs e) 

if(!IsPostBack) 

Bind(); 




private void Bind() 

string initpath=""; 
if(Request["path"]==null) 

initpath=Server.MapPath("FileSystem"); 

else 

initpath=Request["path"]; 

this.Label1.Text=initpath; 

DataTable dt=new DataTable(); 
DataColumn dc0=new DataColumn("Image",System.Type.GetType("System.String")); 
dt.Columns.Add(dc0); 
DataColumn dc1=new DataColumn("Name",System.Type.GetType("System.String")); 
dt.Columns.Add(dc1); 

DirectoryInfo di=new DirectoryInfo(this.Label1.Text); 
DirectoryInfo[] dis=di.GetDirectories(); 
foreach(DirectoryInfo d in dis) 

DataRow dr=dt.NewRow(); 
dr[0]=" <a href='filesystem.aspx?path="+HttpUtility.UrlEncode(d.FullName,System.Text.Encoding.UTF8)+"'> <img src='images/folder.gif' border=0/> </a>"; 
dr[1]=d.Name; 
dt.Rows.Add(dr); 


FileInfo[] fis=di.GetFiles(); 
foreach(FileInfo f in fis) 

string ex=f.Extension.ToLower(); 
if(ex==".jpg" || ex==".jpeg" || ex==".gif" || ex==".png" || ex==".bmp") 

string fullname=f.FullName; 
string urlpath=fullname.Substring(fullname.IndexOf("FileSystem")); 
string url=HttpUtility.UrlEncode(urlpath,System.Text.Encoding.UTF8); 
DataRow dr=dt.NewRow(); 
dr[0]=" <a href='"+url+"' target='_blank'> <img src='"+url+"' border=0 width=100 height=128/> </a>"; 
dr[1]=f.Name; 
dt.Rows.Add(dr); 



this.DataList1.DataSource=dt; 
this.DataList1.DataBind(); 


#region Web 窗体设计器生成的代码 
override protected void OnInit(EventArgs e) 

// 
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 
// 
InitializeComponent(); 
base.OnInit(e); 


/// <summary> 
/// 设计器支持所需的方法 - 不要使用代码编辑器修改 
/// 此方法的内容。 
/// </summary> 
private void InitializeComponent() 

this.LinkButton1.Click += new System.EventHandler(this.LinkButton1_Click); 
this.Button3.Click += new System.EventHandler(this.Button3_Click); 
this.Button1.Click += new System.EventHandler(this.Button1_Click); 
this.Button2.Click += new System.EventHandler(this.Button2_Click); 
this.Load += new System.EventHandler(this.Page_Load); 


#endregion 

private void LinkButton1_Click(object sender, System.EventArgs e) 

string Parent=Directory.GetParent(this.Label1.Text).ToString(); 
if(Parent.IndexOf("FileSystem")>-1) 

Response.Redirect("filesystem.aspx?path="+Parent); 

else 

return; 



private void Button1_Click(object sender, System.EventArgs e) 

HttpPostedFile hpf=this.fileFeild1.PostedFile; 
string ClientPath=hpf.FileName; 
string filename=Path.GetFileName(ClientPath); 
string ex=Path.GetExtension(filename); 
if(ex==".jpg" || ex==".jpeg" || ex==".gif" || ex==".png" || ex==".bmp") 

string SavePath=this.Label1.Text+"\\"+filename; 
hpf.SaveAs(SavePath); 
Bind(); 

else 

Response.Write(Tools.GetAlertJS("所上传的图片格式不正确!")); 
return; 





private void Button2_Click(object sender, System.EventArgs e) 

string filename=this.TextBox1.Text; 
Directory.CreateDirectory(this.Label1.Text+"\\"+filename); 
Bind(); 


private void Button3_Click(object sender, System.EventArgs e) 

for(int i=0;i <this.DataList1.Items.Count;i++) 

if(((CheckBox)this.DataList1.Items[i].FindControl("CheckBox1")).Checked) 

int index=this.DataList1.Items[i].ItemIndex; 
string filePath=this.Label1.Text+"\\"+this.DataList1.DataKeys[index].ToString(); 
if(Directory.Exists(filePath)) 

Directory.Delete(filePath,true); 

if(File.Exists(filePath)) 

File.Delete(filePath); 

Bind(); 







这样是可以的啊

热点排行