转载是种美德...
Calchas 发表于 2010, June 22, 10:49 AM
有时候需要清空GridView的数据,填充新的数据。
可以用GridView1.DataSource = null;
去除数据,重新绑定数据源。即可!
Calchas 发表于 2009, August 20, 8:40 AM
MSDN说明:
因为 SqlDataSourceCommandEventArgs 类是从 CancelEventArgs 类派生的,所以可以通过将
Cancel 属性设置为 true,取消挂起的 SqlDataSource 数据库命令。通过访问由 Command 属
性公开的 DbCommand 对象,可以在运行此命令之前,检查和操作 CommandText、Parameters
集合以及其他命令属性。
OnUpdating、OnInserting 和 OnDeleting 方法使用 SqlDataSourceCommandEventArgs 类,以
在运行 SqlDataSource 数据库命令前提供对此命令的访问。SqlDataSource 控件公开了许多事
件,可处理这些事件以在数据操作过程中使用基础数据对象。下表列出了这些事件、关联的
EventArgs 和事件处理程序类,以更好地引导您使用各种与使用 SqlDataSource 控件的数据操
作的生存期相对应的事件。
示例一:
MSDN的updating/updated事件片段
该示例演示,当使用 SqlDataSource 控件更新数据时,如何使用 DbTransaction 对象来添加
事务上下文。
private void OnSqlUpdating(Object source, SqlDataSourceCommandEventArgs e) {
DbCommand command = e.Command;
DbConnection cx = command.Connection;
cx.Open();
DbTransaction tx = cx.BeginTransaction();
command.Transaction = tx;
}
private void OnSqlUpdated(Object source, SqlDataSourceStatusEventArgs e) {
DbCommand command = e.Command;
DbTransaction tx = command.Transaction;
// In this code example the OtherProcessSucceeded variable represents
// the outcome of some other process that occurs whenever the data is
// updated, and must succeed for the data change to be committed. For
// simplicity, we set this value to true.
bool OtherProcessSucceeded = true;
if (OtherProcessSucceeded) {
tx.Commit();
Label2.Text=”The record was updated successfully!”;
}
else {
tx.Rollback();
Label2.Text=”The record was not updated.”;
}
}
示例二:数据插入过程中更改数据
//根据 @slevel传递来的数据,改变@fk参数中的数据
protected void SqlDataSource_Inserting(object sender, SqlDataSourceCommandEventArgs e)
{
//@slevel为Sql语句中参数
if (e.Command.Parameters["@slevel"].Value == “C级”)
e.Command.Parameters["@FK"].Value = 30;
}
示例三:取消删除
protected void SqlDataSource_Deleting(object sender, SqlDataSourceCommandEventArgs e)
{
if (e.Command.Parameters["@输入日期"].Value == null)
e.Cancel = true;
}
Calchas 发表于 2009, August 20, 8:39 AM
在 System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
在 System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
在 System.IO.FileStream..ctor(String path, FileMode mode)
在 System.Web.HttpPostedFile.SaveAs(String filename)
在 System.Web.UI.WebControls.FileUpload.SaveAs(String filename)
在 PowerEasy.SiteFactory.WebSite.Admin.Accessories.FileUpload.BtnUpload_Click(Object sender, EventArgs e)
在 System.Web.UI.WebControls.Button.OnClick(EventArgs e)
在 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
在 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
在 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
在 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
在 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
解决过程:
检查磁盘空间剩余量大于1G
发现程序所在磁盘为NETWORK SERVICE的配额最大只有50M,而相关文件夹也是在50M,调整此配置,问题解决。
标签: asp.net
Calchas 发表于 2009, July 16, 9:12 AM
X.ASPX
x.ashx
Calchas 发表于 2009, June 25, 2:43 PM
说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。
编译器错误信息: CS0016: 未能写入输出文件“c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\d5ed7960\90f6b658\en-us\App_GlobalResources.gsyxhw8p.resources.dll”--“拒绝访问。 ”
这个问题的解决方法,其实很简单,只要在windows/temp权限设置里面把Network service(如果是win2000则是asp.net用户)的权限加上就行
Calchas 发表于 2009, June 5, 1:53 PM
一、DropDownList:
1、选项值保存到数据库:
Hashtable ht=new Hashtable();//这里用Hashtable
ht.Add("字段名",DropDownListID.SelectedItem.Text.ToString());//保存选项Text
ht.Add("字段名",DropDownListID.SelectedItem.Value.ToString());//保存选项Value
2、选项值由数据库绑定到DropDownList:
首先DropDownListID.ClearSelection();//清除选项
DropDownListID.Items.FindByText(dr["字段名"].ToString()).Selected = true;//选项Text
DropDownListID.Items.FindByValue(dr["字段名"].ToString()).Selected = true;//选项Value
二、RadioButtonList:
1、选项值保存到数据库(同DropDownList):
Hashtable ht=new Hashtable();//这里用Hashtable
ht.Add("字段名",RadioButtonListID.SelectedItem.Text.ToString());//保存选项Text
ht.Add("字段名",RadioButtonListID.SelectedItem.Value.ToString());//保存选项Value
2、选项值由数据库绑定到RadioButtonList
string SelectItem = dr["字段名"].ToString();//将数据库中的选项值从DataRow中读出赋给变量SelectItem
for (int i = 0; i < RadioButtonListID.Items.Count; i++)
{//用for循环判断那项被选种
if (RadioButtonListID.Items[i].Text == SelectItem)RadioButtonListID.Items[i].Selected = true;
}
三、CheckBoxList:
1、选项值保存到数据库
string SelectItem = "";//声明一个变量来接受选项
for (int i = 0; i < CheckBoxListID.Items.Count; i++)
{//用for循环将所有选项用","隔开连接起来
if (CheckBoxListID.Items[i].Selected)
{
SelectItem = SelectItem + CheckBoxListID.Items[i].Value + ",";//选项后加","隔开
}
}
ht.Add("字段名",SelectItem.ToString());
2、选项值由数据库绑定到CheckBoxList
string SelectItem = dr["字段名"].ToString();
string[] arrStr = SelectItem.Split(',');//字段是以","隔开
foreach (string str in arrStr)
{
for (int i = 0; i <CheckBoxListID.Items.Count; i++)
{
if (this.CheckBoxListID.Items[i].Value == str)
{
this.CheckBoxListID.Items[i].Selected = true;
}
}
}
标签: asp.net
Calchas 发表于 2009, May 19, 12:52 PM
如果页面里面有一个 FormView , 里面编辑模式下有一个TextBox 控件 txtMajor, 如果想在CS文件中对其赋值的话。
单纯使用 this.txtMajor.Text = ""; 这样是不行的,会提示找不到 txtMajor 此名称的控件。
编译器错误消息: CS0117: “Index”并不包含“txtMajor”的定义
解决办法是:
TextBox txtMajor = (TextBox)fvPlanInfo.FindControl("txtMajor");
txtMajor= "";
Calchas 发表于 2009, April 24, 12:59 PM
用C#+ODBC做的BS系统,在VS2005里面调试没有问题,但是发布后就会出现"ERROR [IM002] [Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认驱动程序"的错误,问题在于DSN建立的类型不对.
在"ODBC数据源管理器"中,设置用于连接数据库的DSN有三种: 用户DSN、系统DSN和文件DSN.
IIS是系统级的NT服务,因此无法访问"用户DNS"建立的数据源,应当改成"系统DNS".