自动显示序号---分页
前台部分代码:
<asp:TemplateColumn HeaderText="序号">
<HeaderStyle Width="30px"></HeaderStyle>
<ItemTemplate> <%# xuhao++%></ItemTemplate>
</asp:TemplateColumn>
后台部分代码:
public class viewall : System.Web.UI.Page
{
protected int xuhao;
…………
private void Page_Load(object sender, System.EventArgs e)
{
if(!this.IsPostBack)
{
xuhao=1;
this.bind();
}
}
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
this.DataGrid1.CurrentPageIndex=e.NewPageIndex;
xuhao=e.NewPageIndex*20+1;
this.bind();
}
}
*******************************
判断日期输入是否正确(日期正确则为true,否则为false):
public bool IsDate(string str)
{
try
{
DateTime dt=Convert.ToDateTime(str);
return true;
}
catch
{
Response.Write("<script>alert('你输入的日期不正确,请重新输入');</script>");
return false;
}
}
*******************************
DataGrid记录数目和当前第几页的以及总页数目显示:
前台部分代码:
<asp:label id="LabPage" runat="server" Visible="False">Label</asp:label>
<asp:label id="LabRecord" runat="server" Visible="False">Label</asp:label>
<asp:label id="LabKong" runat="server" Width="414px">Label</asp:label>
后台代码:
private string strPage,strRecord;
private void AllBindGrid()//初始化页面
{
string sqlstr="select * from View_neirong";
SqlDataAdapter dt=new SqlDataAdapter(sqlstr,myconn);
DataSet ds=new DataSet();
dt.Fill(ds,"所有资料");
this.DataGrid1.DataSource=ds.Tables["所有资料"].DefaultView;
this.DataGrid1.DataBind();
myconn.Close();
this.LabPage.Text="";
this.LabRecord.Text="";
this.LabPage.Visible=false;
this.LabRecord.Visible=false;
strPage="第<font color='red'>"+Convert.ToString((this.DataGrid1.CurrentPageIndex+1)).ToString()+"</font>页";
strPage=strPage+"/共<font color='red'>"+this.DataGrid1.PageCount.ToString()+"</font>页";
strRecord="当前记录数:<font color='red'>"+this.DataGrid1.Items.Count.ToString()+"</font>";
this.LabPage.Text=strPage;
this.LabRecord.Text=strRecord;
this.LabPage.Visible=true;
this.LabRecord.Visible=true;
}
*******************************
无法关闭的窗口(Javascript)
<script>
var Xwindow = null;
function NoClose() {
Xwindow = window.open("about:blank","","fullscreen=3, toolbar=no,resizable=no,scrollbars=no,dependent,width=100,height=100");
}
setInterval("if(Xwindow==null || Xwindow.closed) NoClose()", 500);
</script>
*******************************
模态窗口:不关闭子窗口,无法操作父窗口(Javascript)
window.showModalDialog('ttt.htm','','','dialogLeft:300px; dialogTop:300px; dialogHeight:200px; dialogWidth:300px; help:off;status:off');
*******************************
//在DataGrid中使用超连接(HyperLink)跳出模态窗口,并向模态窗口传递主键值
<asp:TemplateColumn HeaderText="服务内容">
<ItemTemplate>
<asp:HyperLink id=HyperLink1 runat="server" NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "maintainID","javascript:window.showModalDialog(/"task_view.aspx?ID={0}/",window,/"dialogLeft:300px; dialogTop:300px; dialogHeight:300px; dialogWidth:400px; help:off;status:off/");")%>' Text='<%# DataBinder.Eval(Container.DataItem, "service_content","{0:c}").Length>30? DataBinder.Eval(Container.DataItem, "service_content","{0:c}").Substring(0,30)+"……": DataBinder.Eval(Container.DataItem, "service_content","{0:c}") %>'>
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>
*******************************
打开另一窗口:不关闭子窗口,并且可以把子窗口最小化,也可对父窗口操作
window.open("页面B",'upload', 'height=400, width=420, top=0, left=0, toolbar=no, menubar=no,scrollbars=no, resizable=no,location=no, status=no');
*******************************
页面20秒后刷新:
<meta http-equiv="refresh" content="20">
页面5秒后自动跳转到其他页面(其他页面仍在本窗口):
<meta http-equiv="refresh" content="5; url=./login.aspx?biaozhi=1">
页面5秒后自动跳转到其他页面(其他页面跳转到父窗口):
<meta http-equiv="refresh" content="5; url=javascript:window.parent.location.href='./login.aspx?biaozhi=1'">
*******************************
背景刷新,音乐更换
<SCRIPT LANGUAGE="javascript">
<!--
var sound1="http://歌曲地址"
var sound2="http://歌曲地址"
var sound3="http://歌曲地址"
var sound4="http://歌曲地址"
var sound5="http://歌曲地址"
var sound6="http://歌曲地址"
var sound7="http://歌曲地址"
var sound8="http://歌曲地址"
var sound9="http://歌曲地址"
var sound10="http://歌曲地址"
var x=Math.round(Math.random()*10)
if (x==0) x=sound1
else if (x==1) x=sound2
else if (x==2) x=sound3
else if (x==3) x=sound4
else if (x==4) x=sound5
else if (x==5) x=sound6
else if (x==6) x=sound7
else if (x==7) x=sound8
else if (x==8) x=sound9
else x=sound10
if (navigator.appName=="Microsoft Internet Explorer"
document.write('<bgsound src='http://dev.csdn.net/article/+'"'+x+'"'+' loop="infinite">')
else
document.write('<embed src='http://dev.csdn.net/article/+'"'+x+'"'+'hidden="true" autostart="true" loop="true">')
//-->
</SCRIPT>
*******************************
//自动生成软件编号
myconn.Open();
string firNum="YD101";//软件起始编号
int firNum_Int=int.Parse(firNum.Substring(2));
string resultNum=firNum;
SqlCommand cmd=new SqlCommand("soft_automark",myconn);
DataTable dt=new DataTable("soft");
SqlDataAdapter adpt=new SqlDataAdapter();
adpt.SelectCommand=cmd;
adpt.Fill(dt);
int softCount=0;
softCount=dt.Rows.Count;//软件记录数目
if(softCount==0)//无记录
{
resultNum=firNum;
}
else //有记录
{
SqlDataReader dr=cmd.ExecuteReader();
while(dr.Read()) //逐条取出记录
{
if(firNum==dr["soft_number"].ToString())
{
int soft_bhInt=int.Parse(dr["soft_number"].ToString().Substring(2));//当前记录编号后面的数字号
soft_bhInt+=1;
firNum="YD"+soft_bhInt.ToString();
resultNum=firNum;
}
else
{
resultNum=firNum;
break;
}
}
dr.Close();
}
this.txtNumber.Text=resultNum.ToString();//初始化软件编号
*******************************
//在javascript中实现单选框选择触发事件,获得被选中的单选框的值:
<script language="javascript" >
function check()
{
for(i=0;i<document.all.r1.length;i++)
{
if(document.all.r1[i].checked)
{
document.all.haha.value=document.all.r1[i].value;
break;
}
}
}
</script>
<body>
<form name="form1" >
<input type="radio" name="r1" value="radiobutto111" οnclick="check()"/>111
<input type="radio" name="r1" value="radiobutto222" οnclick="check()" />222
<input type="radio" name="r1" value="radiobutto333" οnclick="check()" />333
<br />
<input type="text" name="haha" value="" />
</form>
</body>
*******************************
内存驻留区的使用
(往DataTable里添加新的行时,数据不需要保存苦中,而在内存中自动更新,并显示出来):
public class sale_modify : System.Web.UI.Page
{
protected SqlConnection myconn;
protected DataTable viewdt=new DataTable("viewchakan");
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
myconn=conn.creatConn();
if(!this.IsPostBack)
{
myconn.Open();
//列
DataColumn cp=new DataColumn("产品",typeof(String));
DataColumn sl=new DataColumn("销售数量",typeof(Int32));
DataColumn cbj=new DataColumn("成本价",typeof(Single));
DataColumn dj=new DataColumn("单价",typeof(Single));
DataColumn cbzj=new DataColumn("成本总价",typeof(Single));
DataColumn xszj=new DataColumn("销售总价",typeof(Single));
viewdt.Columns.Add(cp);
viewdt.Columns.Add(sl);
viewdt.Columns.Add(cbj);
viewdt.Columns.Add(dj);
viewdt.Columns.Add(cbzj);
viewdt.Columns.Add(xszj);
this.DataGrid1.DataSource=viewdt.DefaultView;
this.DataGrid1.DataBind();
myconn.Close();
System.Web.HttpContext.Current.Cache["view_dt"]=viewdt;
}
else
{
viewdt=(DataTable)System.Web.HttpContext.Current.Cache["view_dt"];
}
}
private void Button1_Click(object sender, System.EventArgs e)
{
string cp=this.chanpin.Text.ToString();
int sl=Convert.ToInt32(this.shuliang.Text.ToString());
float dj=Convert.ToSingle(this.danjia.Text.ToString());
float cbj=Convert.ToSingle(this.chengbenjia.Text.ToString());
float cbzj=Convert.ToSingle(this.chengbenzongjia.Text.ToString());
float xszj=Convert.ToSingle(this.xiaoshouzongjia.Text.ToString());
DataRow viewdr=viewdt.NewRow();
viewdr["产品"]=cp;
viewdr["销售数量"]=sl;
viewdr["成本价"]=cbj;
viewdr["单价"]=dj;
viewdr["成本总价"]=cbzj;
viewdr["销售总价"]=xszj;
viewdt.Rows.Add(viewdr);
myconn.Open();
this.DataGrid1.DataSource=viewdt.DefaultView;
this.DataGrid1.DataBind();
myconn.Close();
}
*******************************
状态栏文字设置:
window.status="我就是我";
*******************************
javascript(正则表达式)判断电话号码:
function isphone(str)
{ var strphone=str;
return /(^[0-9]{3,4}/-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^/([0-9]{3,4}/)[0-9]{3,8}$)|(^0{0,1}13[0-9]{9}$)/.test(strphone);
}
if(!isphone(kehuchuanzhen.value))
{
alert("传真号码输入有误");
kehuchuanzhen.focus();
return false;
}
}
*******************************
javascript(正则表达式)判断时间(05:20):
^(20|21|22|23|[01]/d|/d):[0-5]/d$
*******************************
CheckBoxList的用法:
//乘车人员
string sqlstrE="select EmployeeID,EmployName from Employee order by EmployName asc";
DataTable dt=new DataTable("emp");
SqlDataAdapter adpt=new SqlDataAdapter(sqlstrE,myconn);
adpt.Fill(dt);
int c=dt.Rows.Count;
if(c>0)
{
for(int j=0;j<c;j++)
{
ListItem ltE=new ListItem(dt.Rows[j]["EmployName"].ToString(),dt.Rows[j]["EmployeeID"].ToString());
this.CheckBoxList1.Items.Add(ltE);
}
}
//初始化已选乘车人员
string[] array3;//暂存
array3=str_renyuan.Split(' ');//以空格分隔,取出id的值
foreach(string str in array3) //根据id的值,分别取出名字,放到array2中
{
int count=this.CheckBoxList1.Items.Count;
for(int j=0;j<count;j++)
{
if(str==this.CheckBoxList1.Items[j].Value.ToString())
{
this.CheckBoxList1.Items[j].Selected=true;
}
}
}
&&&&&&&&&&&&&&&取出CheckBoxList中的值:&&&&&&&&&&&&&&&&&&&&&
string renyuan=" ";
for(int n=0;n<this.CheckBoxList1.Items.Count;n++)
{
if(this.CheckBoxList1.Items[n].Selected)
renyuan+=this.CheckBoxList1.Items[n].Value.ToString()+" ";
}
*******************************
数字验证和货币验证的正则:
/^[/+|-]{0,1}[0-9]*/.{0,1}[0-9]*$/
或则
/d+(/./d{1,2})?
*******************************
*******************************