1、

select * from table1 where isnull(aa,'')=''

isnull(aa,
'')的意思:如果列“aa”中的数据是NULL的话,就将NULL替换成''

上面的SQL语句等价于:

select
* from table1 where aa is null or aa=''

 

 2、

SQL Cast()变量类型转换
cast(@DanYuanHao as varchar):SQL中变量的类型转换

@HouseNumber为varchar

@DanYuanHao为int

SET @HouseNumber
=(@CodeBefore+@DaiMaFenGeHao+cast(@DanYuanHao as varchar)+cast(@DaiMaFenGeHao as varchar)+cast(@LouCengHao as varchar)+cast(@FangJianHao as varchar))


SET @Address
=(@AddressBefore+cast(@DanYuanHao as varchar)+'单元'+cast(@LouCengHao as varchar)+cast(@FangJianHao as varchar))

 3、



数字的正则表达式: ValidationExpression
="^[0-9]*$"
浮点数的正则表达式: ValidationExpression
="^\d+(\.\d+)?$"

 

 4、

代码
<script language="javascript" type="text/javascript">
function checkboxchange(CBID) {
if (document.getElementById(CBID).checked == true) {
switch (CBID) {
case "CBBuildID":
document.getElementById(
'DDLBuildID').removeAttribute("disabled");
break;
}
}
else {
switch (CBID) {
case "CBBuildID":
document.getElementById(
"DDLBuildID").setAttribute("disabled", "disabled");
break;
}
}
}
</script>
前台:
<input type="checkbox" id="CBBuildID" onclick="checkboxchange(CBBuildID.id);" />
后台:
DDLBuildID.Enabled
= false;

 

 5、

NumericUpDownExtender控件
WebService1.asmx服务

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace BeidouWY.Web.HouseManage
{
/// <summary>
/// WebService1 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo
= WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(
false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
[System.Web.Script.Services.ScriptService()]
public class WebService1 : System.Web.Services.WebService
{

[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
public int UpMethod(int current,string tag)
{
int newcurrent = current + 1;
if (newcurrent == 0)
newcurrent
+= 1;
return newcurrent;
}
[WebMethod]
public int DownMethod(int current, string tag)
{
int newcurrent = current - 1;
if (newcurrent == 0)
newcurrent
-= 1;
return newcurrent;
}
}
}


.aspx页面:
<cc1:NumericUpDownExtender ID="txtLouCengHao_NumericUpDownExtender" runat="server"
Enabled
="True" Maximum="88" Minimum="-1" RefValues=""
ServiceDownMethod
="DownMethod" ServiceDownPath="~/HouseManage/WebService1.asmx"
ServiceUpMethod
="UpMethod" Tag="" TargetButtonDownID=""
TargetButtonUpID
="" TargetControlID="txtLouCengHao"
Width
="50" ServiceUpPath="~/HouseManage/WebService1.asmx">
</cc1:NumericUpDownExtender>
可以参见:http:
//www.cnblogs.com/qc1984326/archive/2007/03/20/681909.html

 

 6、

Sys错误
在.aspx页面上加了ScriptManager后浏览页面出现:Sys未定义错误:
在Web.config文件的system.web节点下添加:
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" validate="false" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpHandlers>

 

 7、

异步线程的调用
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading;

public partial class _Default : System.Web.UI.Page
{
public static Thread t1;
public static string readme;
protected void Page_Load(object sender, EventArgs e)
{
t1
= new Thread(new ThreadStart(Thread1));
//t1.IsBackground = true;
}
protected void Button1_Click(object sender, EventArgs e)
{

t1.Priority
= ThreadPriority.Normal;
t1.Start();

Response.Write(
"<script language='javascript'>alert('线程1执行完毕');</script>");

Response.Write(
"<script language='javascript'>alert('"+readme+"');</script>");


}
public static void Thread1()
{
Thread.Sleep(
10000);
readme
= "OK";
}
protected void Timer1_Tick(object sender, EventArgs e)
{
if (readme == "OK")
{
Response.Write(
"<script language='javascript'>alert('OK');</script>");
readme
= "";
}
}
}

 

 8、

网站搜索
<META http-equiv="Content-Type" content="text/html; charset=gbk"> //charset=gbk:网站编码,不指定有可能在浏览器上出现乱码
<META content="搜索关键字" name=keywords>
<META content="搜索描述" name=description>
<title>搜索标题</title>


www.seomachine.cn

 

 9、

创建一个进程,对文件进行加压解压
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Win32;
using System.Diagnostics;

public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
private void Zip(string file, string src)
{
String the_rar;
RegistryKey the_Reg;
Object the_Obj;
String the_Info;
ProcessStartInfo the_StartInfo;
Process the_Process
= new Process();
try
{
the_Reg
= Registry.ClassesRoot.OpenSubKey(@"Applications\WinRAR.exe\Shell\Open\Command");
the_Obj
= the_Reg.GetValue("");
the_rar
= the_Obj.ToString();
the_Reg.Close();
the_rar
= the_rar.Substring(1, the_rar.Length - 7);
the_Info
= " a -ep1 " + file + " " + src;
the_StartInfo
= new ProcessStartInfo();
the_StartInfo.FileNa me
= the_rar;
the_StartInfo.Arguments
= the_Info;
the_StartInfo.WindowStyle
= ProcessWindowStyle.Hidden;
// the_StartInfo.WorkingDirectory ="";//获取或设置要启动的进程的初始目录。

the_Process.StartInfo
= the_StartInfo;
the_Process.Start();
the_Process.WaitForExit();
the_Process.Close();
// Response.Write("压缩成功");


}
catch (Exception ex)
{
the_Process.Close();
Response.Write(ex.ToString());
}

}
private void unZip(string file, string src)
{
String the_rar;
RegistryKey the_Reg;
Object the_Obj;
String the_Info;
ProcessStartInfo the_StartInfo;
Process the_Process
= new Process();
try
{
the_Reg
= Registry.ClassesRoot.OpenSubKey(@"Applications\WinRar.exe\Shell\Open\Command");
the_Obj
= the_Reg.GetValue("");
the_rar
= the_Obj.ToString();
the_Reg.Close();
the_rar
= the_rar.Substring(1, the_rar.Length - 7);
the_Info
= " X -o+ " + file + " " + src;
the_StartInfo
= new ProcessStartInfo();
the_StartInfo.FileName
= the_rar;
the_StartInfo.Arguments
= the_Info;
the_StartInfo.WindowStyle
= ProcessWindowStyle.Hidden;

the_Process.StartInfo
= the_StartInfo;
the_Process.Start();
the_Process.WaitForExit();
the_Process.Close();
// Response.Write("");
}
catch (Exception ex)
{
the_Process.Close();
Response.Write(ex.ToString());
// the_Process.Dispose();
}

}

}

 

 10、

SQL安装挂起
在xp和2003系统上安装SQLServer2000数据库,一般都要打SP4补丁,这次打补丁是因为虽然能ping通局域网内的服务器,
也能用SQL企业管理器打开服务器上的数据库中的表,但是将项目挂在IIS上浏览的时候不能连接上数据库
解决方案:打SP4补丁
SQLServerSP4补丁:
文件挂起解决办法:运行regedit:HKEY_LOCAL_MACHINE
->SYSTEM->CurrentControlSet->Session Manager->PendingFileRenameOperations删除
安装:写密码,选下面的复选框
另外:遇到此类问题时最直接的测试数据库连接的方法是利用控制面板
-》管理工具-》ODBC数据源管理器直接添加一个连接,看能不能连接上对方的数据库
操作方法:打开ODBC数据源管理器
-》添加-》选择SQL Server,完成
-》起个名字(随便起),描述不用写,(你想连接哪一个SQL Server)填写对方的IP地址或者计算机名称,下一步-》选择使用用户输入登录ID和密码的SQL Server验证,点击链接SQL Server以获得其他配置选项的默认配置,输入登录ID和密码,点击客户端配置 选择TCP/IP 选择动态决定端口 确定
下一步 (此时如果能连接到服务器上的SQLServer则能显示下一个界面,说明连接没有问题,如果不能显示下一个界面,则说明连接有问题
另外:如果同一台电脑上即安装了SQL2000又安装了SQL2005,则应该在安装的时候把他俩的端口改为不同的,默认他俩的端口号是相同的(都是1443),如果链接到同一个服务器(同一个端口,计算机名称又相同,则很有可能出现连接错乱)

 

11、 

1、安装个人版(xp系统,或2000专业版)或企业版(2003系统或2000企业版)
2、安装组件
3、安装数据库服务器
4、本地
5、创建新的实例
6、服务器和客户端
7、典型,两个都改成D盘
8、使用本地系统账户
9、混合模式

 

 12、

框架写法
<iframe name="Left" height="500px" width="180" src="LeftTree.aspx" border="0" frameborder="0"
scrolling
="no"></iframe>
<iframe name="Content" id="Content" height="100%" width="100%" border="0" frameborder="0" style="height: 450px;"
scrolling
="auto"></iframe>
<li><a href="HouseManage/CommnunManage.aspx" target="Content">小区设置</a> </li>
<li><a href="HouseManage/FloorManage.aspx" target="Content">楼房设置</a></li>
<li><a href="HouseManage/RoomManage.aspx" target="Content">房间设置</a></li>
<li>快速初始化</li>

 

 13、

实现类似于CS结构中的文本框选择
<td class="tdcatag">
<asp:TextBox ID="txtHouseID" runat="server" Width="200px" onfocus="RoomFocus()" onblur="RoomBlur()"></asp:TextBox>
<img src="../Images/open.gif" id="Img1" onclick="JavaScript:window.open('/HouseManage/RoomManage.aspx')"
style
="position:relative; z-index: auto; vertical-align:absmiddle; display:none "/>
<input id="HidHouseID" type="hidden" runat="server" />
</td>
<script language="javascript" type="text/javascript">
function RoomFocus() {
var a
= document.getElementById("Img1");
a.style.left
= -20;
a.style.display
= '';
}


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CRHoldList.aspx.cs" Inherits="BeidouWY.Web.CRManager.CRHoldList" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
<link href="../Css/CommStyle.css" rel="Stylesheet" type="text/css" />
<script language="javascript" type="text/javascript">
function RowDoubleClick(obj) {
// debugger;
var renstr = obj.cells[1].innerText;
var a
= parent.window.opener;
if (a != null) {
a.document.getElementById(
"txtComustonID").value = renstr;
a.document.getElementById(
"HidCustID").value = obj.cells[0].innerText;
parent.window.close();
}
}

</script>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
SkinID
="GridView1" Width="100%" onrowcreated="GridView1_RowCreated"
onrowdatabound
="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="ID" />
<asp:BoundField DataField="CustomerNumber" HeaderText="代码" />
<asp:BoundField DataField="CustomerName" HeaderText="名称" />
<asp:BoundField DataField="Sex" HeaderText="性别"/>
<asp:BoundField DataField="Tel" HeaderText="电话"/>
<asp:BoundField DataField="Mobile" HeaderText="手机号"/>
<asp:BoundField DataField="CustomerType" HeaderText="客户类别"/>
<asp:BoundField DataField ="PersonID" HeaderText="身份证号"/>
<asp:BoundField DataField="WorkUnits" HeaderText="工作单位"/>
<asp:BoundField DataField="Education" HeaderText="文化程度"/>
<asp:BoundField />
</Columns>
</asp:GridView>

</div>
</form>
</body>
</html>
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add(
"onDblClick", "RowDoubleClick(this)");
}
}

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
{
//如果想使第1列不可见,则将它的可见性设为false
e.Row.Cells[0].Attributes.Add("style", "display:none");
}
}

 

 14、

重写TreeNode基类方法,添加一个新属性,将要传值的属性存放在此属性中

前台脚本:
<script language="javascript" type="text/javascript">
function SelectCheckBox() {
var o
= window.event.srcElement; //获得触发此事件的对象

var inputobj ;
if (o.tagName == "INPUT" && o.type == "checkbox")
{

var parentobj
= o.parentNode ;
inputobj
= o ;
while(parentobj.tagName != "TABLE") //循环找到table下的子节点
{
parentobj
= parentobj.parentNode

}
// var aobj = parentobj.getElementsByTagName("A");
// var nextobj = parentobj.nextSibling
// if (nextobj.tagName != "DIV")
// return ;

var x
= parentobj.getElementsByTagName("A");
var s
= "";
s
= x[0].NodeData; //自定义的属性
if (s != "") {
//var housenumber = s.split('|')[0].split('=')[1];
document.getElementById("Hidden1").value = s; //给隐藏字段赋值
}
// for ( var i = 0 ; i < x.length;i ++ )
// {
// if (x[i].tagName == "INPUT" && x[i].type == "checkbox")
// {
// if(inputobj.checked)
// x[i].checked = true
// else
// x[i].checked = false
//
// }
// }
}
}

function WindowClose() {
var s
= document.getElementById("Hidden1").value;
var housenumber
= s.split('|')[0].split('=')[1]; //对隐藏字段中的值进行拆分
var houseid = s.split('|')[1].split('=')[1];
var custid
= s.split('|')[2].split('=')[1];
var custname
= s.split('|')[3].split('=')[1];
var Regid
= s.split('|')[4].split('=')[1];
if (window.opener != null) { //获得打开此窗体的父窗体
window.opener.document.getElementById("txtHouseID").value = housenumber; //在父窗体中找到对应的控件并赋值
window.opener.document.getElementById("HidhouseID").value = houseid;
window.opener.document.getElementById(
"txtCustomerID").value = custname;
window.opener.document.getElementById(
"HidCustomerID").value = custid;
window.opener.document.getElementById(
"Regid").value = Regid;
window.opener
= null;
window.close();
//关闭子窗体


}
}

</script>

后台内容:
public partial class CROutTree : PageBase
{
protected void Page_Load(object sender, EventArgs e)
{
this.TreeView1.Attributes.Add("onclick", "SelectCheckBox()"); //为TreeView添加客户端事件

if (!IsPostBack)
{
this.TreeCompBind();

}
}
#region 树控件绑定
private void TreeCompBind()
{
DataTable dt;
BLL.JC_Company_Info bll
= new BeidouWY.BLL.JC_Company_Info();
dt
= bll.GetList("ParentCode='0'").Tables[0];
foreach (DataRow dr in dt.Rows)
{
TreeNode tn
= new TreeNode();
tn.Text
= dr["CompName"].ToString();
tn.Value
= dr["CompCode"].ToString();
tn.NavigateUrl
= "#";
// tn.Target = "Right";

this.TreeView1.Nodes.Add(tn);
CommunBind(tn.Value, tn.ChildNodes);
}

}

private void CommunBind(string CompCode, TreeNodeCollection TNC)
{
DataTable dt;
BLL.WC_Community_Info bll
= new BeidouWY.BLL.WC_Community_Info();
dt
= bll.GetList("ComanyCode='" + CompCode + "'").Tables[0];
foreach (DataRow dr in dt.Rows)
{
TreeNode tn
= new TreeNode();
tn.Text
= dr["CommunityName"].ToString();
tn.Value
= dr["CommunityCode"].ToString();
// tn.NavigateUrl = "CRList.aspx?type=2&ID=" + tn.Value;
//tn.Target = "Right";

tn.NavigateUrl
= "#";
TNC.Add(tn);
BuildBind(tn.Value, tn.ChildNodes);
}

}

private void BuildBind(string CommunityCode, TreeNodeCollection TNC)
{
DataTable dt;
BLL.WC_Build_Info bll
= new BeidouWY.BLL.WC_Build_Info();
dt
= bll.GetList("CommunityCode='" + CommunityCode + "'").Tables[0];
foreach (DataRow dr in dt.Rows)
{
TreeNode tn
= new TreeNode();
tn.Text
= dr["BuildName"].ToString();
tn.Value
= dr["ID"].ToString();
//tn.NavigateUrl = "CRList.aspx?type=3&ID=" + tn.Value;
//tn.Target = "Right";
tn.NavigateUrl = "#";
TNC.Add(tn);
RoomCustBind(tn.Value, tn.ChildNodes);
}

}
#endregion

protected void TreeView1_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
{

}

protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
TreeView tv
= (TreeView)sender;
if (tv.SelectedNode.Depth == 2 && tv.SelectedNode.ChildNodes.Count == 0)
{
this.RoomCustBind(tv.SelectedNode.Value, tv.SelectedNode.ChildNodes);
}
}

private void RoomCustBind(string sID, TreeNodeCollection TNC)
{
string strSQL = "SELECT a.HouseNumber, b.houseid,c.CustomerName,c.id,c.customernumber,b.id as Regid "
+ " FROM WC_House_Info a INNER JOIN "
+ " CR_Occupation_Reg b ON "
+ " a.ID = b.HouseID "
+ " inner join CR_HouseHold_Info c "
+ " on b.comustonid=c.id "
+ " where b.INFlag='1' and OutFlag='0' and a.buildid='" + sID + "'";
DataTable dt;
dt
= DbHelperSQL.Query(strSQL).Tables[0];
foreach (DataRow dr in dt.Rows)
{
//TreeNode tn = new TreeNode();
BeidouWY.Web.Controls.CustTreeNode tn = new BeidouWY.Web.Controls.CustTreeNode(); //初始化的是重写基类的方法的类
string tname = dr["CustomerName"].ToString() != "" ? "[" + dr["CustomerName"].ToString() + "]" : "";
tn.Text
= dr["HouseNumber"].ToString() + tname;
tn.Value
= dr["HouseID"].ToString();
tn.ShowCheckBox
= true; //节点前面有个CheckBox
tn.NavigateUrl = "#";
tn.NodeData
= "HouseNumber=" + dr["HouseNumber"].ToString() + "|HouseID=" + dr["HouseID"].ToString() + "|ID=" + dr["ID"].ToString() + "|CustomerNumber=" + dr["CustomerNumber"].ToString() + "-" + dr["CustomerName"].ToString()+"|Regid="+dr["Regid"].ToString();
//自定义的NodeData属性,为了存放数据用的
//tn.NavigateUrl = "CRHoldList.aspx?type=4&ID=" + tn.Value;
//tn.Target = "Right";
//tn.SelectAction = TreeNodeSelectAction.Expand;
TNC.Add(tn);
}
}

protected void TreeView1_TreeNodeCheckChanged(object sender, TreeNodeEventArgs e)
{
TreeView tv
= (TreeView)sender;
if (tv.SelectedNode.Depth == 2 && tv.SelectedNode.ChildNodes.Count == 0)
{
this.RoomCustBind(tv.SelectedNode.Value, tv.SelectedNode.ChildNodes);
}
}
}

重写TreeView基类的方法:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
namespace BeidouWY.Web.Controls
{
public class CustTreeNode :System.Web.UI.WebControls.TreeNode //继承自TreeNode类
{
private string _nodedata;
public string NodeData
{
set
{
_nodedata
= value;
}
get
{
return _nodedata;
}
}
//protected override void Render(HtmlTextWriter writer)
//{
// base.RenderPostText
//}
protected override void RenderPreText(HtmlTextWriter writer) //重写基类的RenderPreText方法
{

writer.AddAttribute(
"NodeData", this.NodeData); //添加HTML属性

base.RenderPreText(writer);
}
//protected override void RenderPostText(HtmlTextWriter writer)
//{
// writer.
// base.RenderPostText(writer);
//}
}
}

 

 15、

frameset和iframe的区别
只有前台没有后台
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="BeidouWY.Web.Index" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="Css/CommStyle.css" rel="Stylesheet" type="text/css" />
</head>
<frameset rows="63,*,23" frameborder="no" border="0" framespacing="0"> //框架:必须写在<body>外面 ?rows:指定长宽高?
<frame src="top.aspx" name="topFrame" scrolling="No" noresize="noresize" id="topFrame" />
//里面嵌套的子框架 src:此框架中的页面地址; name:在子页面中如果要做A连接时Target指向的名字 ;scrolling="No":不允许滚动;noresize="noresize"不允许调整大小
<frame src="Center.aspx" name="mainFrame" id="mainFrame" />
<frame src="down.aspx" name="bottomFrame" scrolling="No" noresize="noresize" id="bottomFrame" />
</frameset>
</html>

-----------------------------------------------------------------------------------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="BaseDataManage.aspx.cs" Inherits="BeidouWY.Web.SysManage.BaseDataManage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>辅助资料</title>
<link href="../Css/CommStyle.css" rel="Stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div>
<table width ="98%" border="1" class="tablemain" border="1" bordercolor="#99CC33">
<tr>
<td width="200" valign="top">
<asp:TreeView ID="TreeView1" runat="server" Width="195px">
</asp:TreeView>
</td>
<td valign="top" ><iframe id="Cent" name="Cent" width="100%" height="400px" frameborder="0" scrolling="auto" src="BaseTypeManage.aspx"></iframe></td>
</tr> //iframe:在页面中嵌套的子页面:属性和<frameset相同;适用于比较简单的嵌套

</table>
</div>
</form>
</body>
</html>

<frameset><iframe>的区别:两者都是框架技术,<iframe>在有些低端浏览器上不支持,但是<frameset>在所有浏览器是上都支持
<frameset>一旦使用一定会占用连接数(一个页面占用一个连接数)但是<iframe>浏览时里面有页面会占用一个连接数,没有页面不会占用连接数

 16、

TreeView绑定
TreeView的绑定及其用法:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using BeidouWY.DBUtility;
namespace BeidouWY.Web.CRManager
{
public partial class CRTree : PageBase
{
protected void Page_Load(object sender, EventArgs e)
{
this.TreeView1.Attributes.Add("onclick", "SelectCheckBox()");

if (!IsPostBack)
{
this.TreeCompBind();

}
}

#region 树控件绑定
private void TreeCompBind()
{
DataTable dt;
BLL.JC_Company_Info bll
= new BeidouWY.BLL.JC_Company_Info();
dt
= bll.GetList("ParentCode='0'").Tables[0];
foreach (DataRow dr in dt.Rows)
{
TreeNode tn
= new TreeNode();
tn.Text
= dr["CompName"].ToString();
tn.Value
= dr["CompCode"].ToString();
tn.NavigateUrl
= "#";
// tn.Target = "Right";

this.TreeView1.Nodes.Add(tn);
CommunBind(tn.Value, tn.ChildNodes);
}

}

private void CommunBind(string CompCode, TreeNodeCollection TNC)
{
DataTable dt;
BLL.WC_Community_Info bll
= new BeidouWY.BLL.WC_Community_Info();
dt
= bll.GetList("ComanyCode='" + CompCode + "'").Tables[0];
foreach (DataRow dr in dt.Rows)
{
TreeNode tn
= new TreeNode();
tn.Text
= dr["CommunityName"].ToString();
tn.Value
= dr["CommunityCode"].ToString();
// tn.NavigateUrl = "CRList.aspx?type=2&ID=" + tn.Value;
//tn.Target = "Right";

tn.NavigateUrl
= "#";
TNC.Add(tn);
BuildBind(tn.Value, tn.ChildNodes);
}

}

private void BuildBind(string CommunityCode, TreeNodeCollection TNC)
{
DataTable dt;
BLL.WC_Build_Info bll
= new BeidouWY.BLL.WC_Build_Info();
dt
= bll.GetList("CommunityCode='" + CommunityCode + "'").Tables[0];
foreach (DataRow dr in dt.Rows)
{
TreeNode tn
= new TreeNode();
tn.Text
= dr["BuildName"].ToString();
tn.Value
= dr["ID"].ToString();
//tn.NavigateUrl = "CRList.aspx?type=3&ID=" + tn.Value;
//tn.Target = "Right";
tn.NavigateUrl = "#";
TNC.Add(tn);
RoomCustBind(tn.Value, tn.ChildNodes);
}

}
#endregion

protected void TreeView1_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
{

}

protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
TreeView tv
= (TreeView)sender;
if (tv.SelectedNode.Depth == 2 && tv.SelectedNode.ChildNodes.Count == 0)
{
this.RoomCustBind(tv.SelectedNode.Value, tv.SelectedNode.ChildNodes);
}
}

private void RoomCustBind(string sID, TreeNodeCollection TNC)
{
string strSQL = "SELECT a.HouseNumber, b.houseid,c.CustomerName,c.id,c.customernumber "
+ " FROM WC_House_Info a INNER JOIN "
+ " CR_Occupation_Reg b ON "
+ " a.ID = b.HouseID "
+ " inner join CR_HouseHold_Info c "
+ " on b.comustonid=c.id "
+ " where b.inflag='0' and a.buildid='" + sID + "'";
DataTable dt;
dt
= DbHelperSQL.Query(strSQL).Tables[0];
foreach (DataRow dr in dt.Rows)
{
//TreeNode tn = new TreeNode();
BeidouWY.Web.Controls.CustTreeNode tn = new BeidouWY.Web.Controls.CustTreeNode();
string tname = dr["CustomerName"].ToString() != "" ? "[" + dr["CustomerName"].ToString() + "]" : "";
tn.Text
= dr["HouseNumber"].ToString() + tname;
tn.Value
= dr["HouseID"].ToString();
tn.ShowCheckBox
= true;
tn.NavigateUrl
= "#";
tn.NodeData
= "HouseNumber=" + dr["HouseNumber"].ToString() + "|HouseID=" + dr["HouseID"].ToString() + "|ID=" + dr["ID"].ToString() + "|CustomerNumber=" + dr["CustomerNumber"].ToString() + "-" + dr["CustomerName"].ToString();
//tn.NavigateUrl = "CRHoldList.aspx?type=4&ID=" + tn.Value;
//tn.Target = "Right";
//tn.SelectAction = TreeNodeSelectAction.Expand;
TNC.Add(tn);
}
}

protected void TreeView1_TreeNodeCheckChanged(object sender, TreeNodeEventArgs e)
{
TreeView tv
= (TreeView)sender;
if (tv.SelectedNode.Depth == 2 && tv.SelectedNode.ChildNodes.Count == 0)
{
this.RoomCustBind(tv.SelectedNode.Value, tv.SelectedNode.ChildNodes);
}
}
}
}
------------------------------------------------------------------------------
if (ds.Tables[0].Rows.Count == 0)
{
ds.Tables[
0].Rows.Add(ds.Tables[0].NewRow());
this.GridView1.DataSource = ds;
this.GridView1.DataBind();

//this.GridView1.Rows[0].Cells[0].FindControl("CheckBox1").Visible = false;
this.GridView1.Rows[0].Visible = false;

}
else
{
this.GridView1.DataSource = ds;
this.GridView1.DataBind();
}

 17、

display:none和Visible=false的区别
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
{
//如果想使第1列不可见,则将它的可见性设为false
e.Row.Cells[0].Attributes.Add("style", "display:none");//加上display:none;使整个第一列隐藏掉,但是在查看源文件的时候还可以看到
} //和.Visible=false的区别:visible=false在加载的时候不对对象进行渲染,完全不显示在页面上,查看源文件也看不到
}

 18、

表联和子查询的区别
SELECT dbo.Pub_Meate.*, dbo.Base_Meter_Type.CodeName, dbo.DM_BaseData.CodeName AS gongtan, dbo.WC_Community_Info.CommunityName, DM_BaseData_1.CodeName AS yongtu FROM dbo.Pub_Meate LEFT OUTER JOIN dbo.Base_Meter_Type ON dbo.Pub_Meate.MeterTypeCode = dbo.Base_Meter_Type.ID LEFT OUTER JOIN dbo.WC_Community_Info ON dbo.WC_Community_Info.ID = dbo.Pub_Meate.CommUnId LEFT OUTER JOIN dbo.DM_BaseData ON dbo.DM_BaseData.Code = dbo.Pub_Meate.PubMeterCode LEFT JOIN (select code,codename from dm_basedata where parentcode='22') DM_BaseData_1 ON dbo.Pub_Meate.Effect= DM_BaseData_1.Code WHERE (dbo.DM_BaseData.ParentCode = '21')
是将左右表进行联接后在用Where条件进行过滤

SELECT dbo.Pub_Meate.*, dbo.Base_Meter_Type.CodeName, dbo.DM_BaseData.CodeName AS 'gongtan', dbo.WC_Community_Info.CommunityName, DM_BaseData_1.CodeName AS 'yongtu' FROM dbo.Pub_Meate LEFT JOIN dbo.Base_Meter_Type ON dbo.Pub_Meate.MeterTypeCode = dbo.Base_Meter_Type.ID LEFT JOIN dbo.WC_Community_Info ON dbo.WC_Community_Info.ID = dbo.Pub_Meate.CommUnId LEFT JOIN dbo.DM_BaseData ON dbo.DM_BaseData.Code = dbo.Pub_Meate.PubMeterCode LEFT JOIN dbo.DM_BaseData DM_BaseData_1 ON dbo.Pub_Meate.Effect = DM_BaseData_1.Code WHERE ( DM_BaseData_1.ParentCode = '22') AND (dbo.DM_BaseData. ParentCode = '21')
先将字表查出(用Where条件进行过滤)再将表进行联接,和上面相比,下面这种方法查出的数据有时候要比上面查出的数据多

 

 

 

 

 

 

 

 

 

 

posted on 2010-06-03 18:24  秦威龙  阅读(428)  评论(0编辑  收藏  举报