ASP.ENT实训报告……………………………………………装………………………订……………………线…………………………………………………实训报告cm.Parameters[@fileAuthor].Value=this.Author.Value.Trim();cm.Parameters.Add(@fileSource,SqlDbType.NVarChar,50);cm.Parameters[@fileSource].Value=this.tSource.Text.Trim();cm.Parameters.Add(@filePath,SqlDbType.NVarChar,200);cm.Parameters[@filePath].Value=this.File1.PostedFile.FileName.Trim();cm.Parameters.Add(@fileSize,SqlDbType.NVarChar,50);cm.Parameters[@fileSize].Value=this.File1.PostedFile.ContentLengthcm.Parameters.Add(@fileType,SqlDbType.NVarChar,50);cm.Parameters[@fileType].Value=this.File1.PostedFile.ContentType;cm.ExecuteNonQuery();}catch(Exceptionex){str=centerfontcolor=red文件上传失败,请重试/fontbr;Response.Write(ex.Message);}●文件的下载(主代码如下)SqlConnectioncn=newSqlConnection(conn);cn.Open();SqlCommandcm=newSqlCommand(sel_file,cn);cm.CommandType=CommandType.StoredProcedure;cm.Parameters.Add(@fileTitle,SqlDbType.NVarChar,50);cm.Parameters[@fileTitle].Value=b;SqlDataReaderdr=cm.ExecuteReader();if(dr.Read()){stringpath=dr.GetString(3);//path:文件物理路径System.IO.FileInfofile=newSystem.IO.FileInfo(path);Response.Clear();Response.Charset=GB2312;Response.ContentEncoding=System.Text.Encoding.UTF8;//添加头信息,为文件下载/另存为对话框指定默认文件名Response.AddHeader(Content-Disposition,attachment;filename=+Server.UrlEncode(name));//添加头信息,指定文件大小,让浏览器能够显示下载进度Response.AddHeader(Content-Length,file.Length.ToString());Response.ContentType=application/octet-stream;Response.WriteFile(file.FullName);//把文件流发送到客户端Response.End();//停止页面的执行dr.Close();cn.Close();}else{Response.Write(暂无该资源!);}实训报告●DataGrid的分页实现(主代码如下)首先,要添加4个Label并分别设置CommandArgument属性为first,next,prev,last;然后,添加事件onclick=PagerButtonClick;具体事件代码为:publicvoidPagerButtonClick(Objectsender,EventArgse)//分页显示{stringarg=((LinkButton)sender).CommandArgument;//获得LinkButton的参数值switch(arg){case(next):if(this.DataGrid1.CurrentPageIndex==DataGrid1.PageCount-1){Response.Write(已是最后一页);}elseif(this.DataGrid1.CurrentPageIndex(DataGrid1.PageCount-1))DataGrid1.CurrentPageIndex++;break;case(prev):if(this.DataGrid1.CurrentPageIndex==0){Response.Write(已是第一页);}elseif(DataGrid1.CurrentPageIndex0)DataGrid1.CurrentPageIndex--;break;case(last):DataGrid1.CurrentPageIndex=(DataGrid1.PageCount-1);break;case(first):DataGrid1.CurrentPageIndex=0;break;}try{SqlConnectionconn=newSqlConnection(con);//连接字符串conn.Open();SqlDataAdaptermyCommand=newSqlDataAdapter();//创建SqlDataAdaptermyCommand.SelectCommand=newSqlCommand(sel_all_user,conn);myCommand.SelectCommand.CommandType=CommandType.StoredProcedure;myCommand.Fill(ds,allUser);//建立并填充数据集this.DataGrid1.DataSource=ds;//绑定DataListthis.DataGrid1.DataBind();conn.Close();}catch(SqlExceptione){Response.Write(ExceptioninMain:+e.Message);//出错处理}}ASP.NET实训报告·3·……………………………………………装………………………订……………………线…………………………………………………实训报告●DataGrid按钮列的使用(以删除为例)首先,要设置DataGrid的DataKeyField属性为id;然后,设置事件DataGrid1_DeleteCommand,代码如下:privatevoidDataGrid1_DeleteCommand(objectsource,System.Web.UI.WebControls.DataGridCommandEventArgse){try{SqlConnectionconn=newSqlConnection(con);//建立连接conn.Open();SqlCommanddelUser=newSqlCommand(del_user,conn);//建立命令delUser.CommandType=CommandType.StoredProcedure;SqlParameterid=delUser.Parameters.Add(@id,SqlDbType.BigInt);id.Value=this.DataGrid1.DataKeys[e.Item.ItemIndex];//获得参数的值intr=delUser.ExecuteNonQuery();//删除if(r0){this.Label1.Text=centerfontcolor=red删除成功!/font;conn.Close();this.DataGrid1.EditItemIndex=-1;if(this.DataGrid1.CurrentPageIndex0){this.DataGrid1.CurrentPageIndex=this.DataGrid1.CurrentPageIndex-1;}getAllUser();}else{this.Label1.Text=centerfontcolor=red删除错误!/font;conn.Close();this.DataGrid1.EditItemIndex=-1;getAllUser();}}catch(SqlExceptioner){Response.Write(SqlExceptioninMain:+er.Message);}}事件上面所调用的方法getAllUser()代码如下:privatevoidgetAllUser(){try{SqlConnectionconn=newSqlConnection(con);//连接字符串conn.Open();SqlDataAdaptermyCommand=newSqlDataAdapter();//创建SqlDataAdaptermyCommand.SelectCommand=newSqlCommand(sel_all_user,conn);myCommand.SelectCommand.CommandType=CommandType.StoredProcedure;myCommand.Fill(ds,allUser);//建立并填充数据集this.DataGrid1.DataSource=ds;//绑定DataListthis.DataGrid1.DataBind();conn.Close();}catch(SqlExceptione){Response.Write(ExceptioninMain:+e.Message);//出错处理}}实训报告●对管理员信息的修改,代码如下:首先,验证数据库中是否已存在更新信息;privateboolvalidateUser()//验证是否已有此管理员{try{stringcon=ConfigurationSettings.AppSettings[dsn];//取得DSN字符SqlConnectionconn=newSqlConnection(con);//连接字符串conn.Open();SqlCommandval=newSqlCommand(sel_adminByName,conn);//通过存储过程查看用户val.CommandType=CommandType.StoredProcedure;SqlParameteruser=val.Parameters.Add(@adminName,SqlDbType.Char,20);//参数设定user.Value=this.tAdminName.Text.Trim();SqlDataReaderrd;rd=val.ExecuteReader();if(rd.Read()==true){this.Label1.Text=centerfontcolor=red已有此管理员/font;returnfalse;}elsereturntrue;}catch(SqlExceptione)//出错处理{Response.Write(SqlExceptioninMain:+e.Message);returnfalse;}}如果数据库中无要更新信息,则可修改;privatevoidupdatepwd(stringd)//修改管理员密码{stringcon=ConfigurationSettings.AppSettings[dsn];//取得DSN字符SqlConnectionconn=newSqlConnection(con);//连接字符串conn.Open();SqlCommandval=