『深巷の布衣』


我为她/它狂~~~

在工作中注重结果,在生活中享受过程!
posts - 208,comments - 110,trackbacks - 7
 

“/QCZhuangOA”应用程序中的服务器错误。

“/QCZhuangOA/FM/FileUpload/课程�?doc”不是有效的虚拟路径。

说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.Web.HttpException: “/QCZhuangOA/FM/FileUpload/课程�?doc”不是有效的虚拟路径。

源错误:

行 18:         // retrieve the path of the file to download, and create
            行 19:         // a FileInfo object to read its properties
            行 20:         string path = Server.MapPath(Request.Params["File"]);
            行 21:         System.IO.FileInfo file = new System.IO.FileInfo(path);
            行 22: 
posted @ 2008-03-26 01:32 潘奕涛 阅读(417) | 评论 (0)编辑
.net 1.1中的解决方法(转)
1建立一个DataSetHelper类(DataSetHelper.cs)
public class DataSetHelper
{
    
public DataSet ds;
    
public DataSetHelper(ref DataSet DataSet)
    
{
        ds 
= DataSet;
    }

    
public DataSetHelper()
    
{
        ds 
= null;
    }

    
private bool ColumnEqual(object A, object B)
    
{
        
if (A == DBNull.Value && B == DBNull.Value) //  both are DBNull.Value
            return true;
        
if (A == DBNull.Value || B == DBNull.Value) //  only one is DBNull.Value
            return false;
        
return (A.Equals(B));  // value type standard comparison
    }

    
public DataTable SelectDistinct(string TableName, DataTable SourceTable, string FieldName)
    
{
        DataTable dt 
= new DataTable(TableName);
        dt.Columns.Add(FieldName, SourceTable.Columns[FieldName].DataType);

        
object LastValue = null;
        
foreach (DataRow dr in SourceTable.Select("", FieldName))
        
{
            
if (LastValue == null || !(ColumnEqual(LastValue, dr[FieldName])))
            
{
                LastValue 
= dr[FieldName];
                dt.Rows.Add(
new object[] { LastValue });
            }

        }

        
if (ds != null)
            ds.Tables.Add(dt);
        
return dt;
    }

}
2 建立一个Web窗体,在page_load中写下面的代码
       DataSet ds;
        DataSetHelper dsHelper;
        ds 
= new DataSet();
        dsHelper 
= new DataSetHelper(ref ds);

        
// Create source table
        DataTable dt = new DataTable("Orders");
        dt.Columns.Add(
"EmployeeID", Type.GetType("System.String"));
        dt.Columns.Add(
"OrderID", Type.GetType("System.Int32"));
        dt.Columns.Add(
"Amount", Type.GetType("System.Decimal"));

        dt.Rows.Add(
new object[] "Sam"525.00 });
        dt.Rows.Add(
new object[] "Tom"750.00 });
        dt.Rows.Add(
new object[] "Sue"911.00 });
        dt.Rows.Add(
new Object[] "Tom"127.00 });
        dt.Rows.Add(
new Object[] "Sam"14512.00 });
        dt.Rows.Add(
new Object[] "Sue"1517.00 });
        dt.Rows.Add(
new Object[] "Sue"222.50 });
        dt.Rows.Add(
new object[] "Tom"243.00 });
        dt.Rows.Add(
new object[] "Tom"3378.75 });

        ds.Tables.Add(dt);
       DataTable td
=dsHelper.SelectDistinct("DistinctEmployees", ds.Tables["Orders"], "EmployeeID");
       
this.GridView1.DataSource = td;
       
this.GridView1.DataBind();

 .net 2.0中的解决方法(原创)

public DataTable GetTopSearch()
        
{
            DataSet dsKeyword 
= dal.GetKeyword();
            DataSet dsTopSearch 
= new DataSet();
            
for (int i = 0; i < 4; i++)
            
{
                
string keyword = dsKeyword.Tables[0].Rows[i]["Name"].ToString();
                
string condition = dsKeyword.Tables[0].Rows[i]["SearchCondition"].ToString();
                dsTopSearch.Merge(dal.GetTopSearch(keyword,condition));
            }

            
return dsTopSearch.Tables[0].DefaultView.ToTable(true"ID","Name","Author","Publisher","PublishDate","TypeName","Price","SalePrice","SavePrice","Rebate","ImagePath","ContentIntro");
        }


先把DataTable转成DataView,再通过DataView.ToTable()转回DataTable,ToTable()方法中有一个重载可以轻松消除重复行.
注:该重载的第二个参数为要保存的字段名.

posted @ 2008-02-17 23:14 潘奕涛 阅读(714) | 评论 (0)编辑
1C#代码与javaScript函数的相互调用
  2
  3问:
  41.如何在JavaScript访问C#函数?
  52.如何在JavaScript访问C#变量?
  63.如何在C#中访问JavaScript的已有变量?
  74.如何在C#中访问JavaScript函数?
  8 
  9问题1答案如下:
 10javaScript函数中执行C#代码中的函数:
 11方法一:1、首先建立一个按钮,在后台将调用或处理的内容写入button_click中;
 12        2、在前台写一个js函数,内容为document.getElementById("btn1").click();
 13        3、在前台或后台调用js函数,激发click事件,等于访问后台c#函数;
 14
 15方法二:1、函数声明为public              
 16           后台代码(把public改成protected也可以)
 17           public string ss()
 18           {
 19              return("a");
 20           }

 21        2、在html里用<%=fucntion()%>可以调用
 22           前台脚本
 23           <script language=javascript>
 24           var a = "<%=ss()%>";
 25           alert(a);
 26           </script>
 27方法三:1<script language="javascript">
 28           <!--
 29           function __doPostBack(eventTarget, eventArgument)
 30           {
 31              var theForm = document.Form1;     //指runat=server的form
 32              theForm.__EVENTTARGET.value = eventTarget;
 33              theFrom.__EVENTARGUMENT.value = eventArgument;
 34              theForm.submit();
 35           }

 36           -->
 37           </script>
 38           <input id="Button1" type="button" name="Button1" value="按钮" onclick="javascript:__doPostBack('Button1','')">
 39         
 40方法四:<script language="javascript">
 41function SubmitKeyClick()
 42{
 43    if (event.keyCode == 13)
 44    {
 45        event.cancelBubble = true;
 46        event.returnValue = false;
 47        document.all.FunName.value="你要调用的函数名"
 48        document.form[0].submit();
 49    }

 50}

 51</script>
 52
 53<INPUT onkeypress="SubmitKeyClick()" id="aaa" type="text">
 54<input type="hidden" name="FunName"> 〈!--用来存储你要调用的函数 --
 55
 56在.CS里有:
 57public Page_OnLoad()
 58{
 59if (!Page.IsPost())
 60{
 61string strFunName=Request.Form["FunName"]!=null?Request.Form["FunName"]:"";
 62//根据传回来的值决定调用哪个函数
 63switch(strFunName)
 64{
 65case "enter()":
 66enter() ; //调用该函数
 67break;
 68case "其他":
 69//调用其他函数
 70break;
 71default:
 72//调用默认函数
 73break;
 74}

 75}

 76}

 77
 78public void enter()
 79{
 80//……比如计算某值
 81}

 82
 83问题2.如何在JavaScript访问C#变量?
 84答案如下:
 85方法一:1、通过页面上隐藏域访问<input id="xx" type="hidden" runat="server">
 86方法二:1、如后台定义了PUBLIC STRING N;前台js中引用该变量的格式为'<%=n%>'"+<%=n%>+"
 87方法三:1、或者你可以在服务器端变量赋值后在页面注册一段脚本
 88           "<script language='javascript'>var temp=" + tmp + "</script>"
 89           tmp是后台变量,然后js中可以直接访问temp获得值。
 90
 91
 92问题3.如何在C#中访问JavaScript的已有变量?
 93
 94答案如下:
 95
 96方法一:1、前台使用静态文本控件隐藏域,将js变量值写入其中;
 97        2、后台用request["id"]来获取值;
 98
 99方法二:可以用cookie或session
100
101
102问题4.如何在C#中访问JavaScript函数?
103答案如下:
104c#代码中执行javaScript函数:
105方法一:1、Page.RegisterStartupScript("ggg","<script>SetVisible(1);</script>");
106方法二:使用Literal类,然后
107private void Button2_Click(object sender, System.EventArgs e)
108{
109 string str;
110 str="<script language='javascript'>";
111 str+="selectRange()";
112 str+="</script>";
113 //Literal1.Visible=true;
114 Literal1.Text=str;
115}

116
posted @ 2007-12-10 03:05 潘奕涛 阅读(362) | 评论 (0)编辑