VB.NET常用代码有哪些
发表于:2025-11-11 作者:千家信息网编辑
千家信息网最后更新 2025年11月11日,小编给大家分享一下VB.NET常用代码有哪些,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!1. 打开新的窗口并传送参数:传送参数:response.write("<script>wi
千家信息网最后更新 2025年11月11日VB.NET常用代码有哪些
小编给大家分享一下VB.NET常用代码有哪些,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!
1. 打开新的窗口并传送参数:
传送参数:
response.write("<script>window.open('*.aspx?id="+this.DropDownList1.SelectIndex+"&id1="+...+"')</script>")接收参数:
string a = Request.QueryString("id"); string b = Request.QueryString("id1");2.为按钮添加对话框
Button1.Attributes.Add("onclick","return confirm('确认?')"); button.attributes.add("onclick","if(confirm('are you sure...?')){return true;}else{return false;}")3.删除表格选定记录
int intEmpID = (int)MyDataGrid.DataKeys[e.Item.ItemIndex]; string deleteCmd = "DELETE from Employee where emp_id = " + intEmpID.ToString()
4.删除表格记录警告
private void DataGrid_ItemCreated(Object sender,DataGridItemEventArgs e) { switch(e.Item.ItemType) { case ListItemType.Item : case ListItemType.AlternatingItem : case ListItemType.EditItem: TableCell myTableCell; myTableCell = e.Item.Cells[14]; LinkButton myDeleteButton ; myDeleteButton = (LinkButton)myTableCell.Controls[0]; myDeleteButton.Attributes.Add("onclick","return confirm('您是否确定要删除这条信息');"); break; default: break; } }
5.点击表格行链接另一页
private void grdCustomer_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { //点击表格打开 if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) e.Item.Attributes.Add("onclick","window.open('Default.aspx?id=" + e.Item.Cells[0].Text + "');"); } //双击表格连接到另一页 //在itemDataBind事件中 if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { string OrderItemID =e.item.cells[1].Text; ... e.item.Attributes.Add("ondblclick", "location.href='../ShippedGrid.aspx?id=" + OrderItemID + "'"); } //双击表格打开新一页 if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { string OrderItemID =e.item.cells[1].Text; ... e.item.Attributes.Add("ondblclick", "open('../ShippedGrid.aspx?id=" + OrderItemID + "')"); }6.表格超连接列传递参数
<asp:HyperLinkColumn Target="_blank" headertext="ID号" DataTextField="id" NavigateUrl="aaa.aspx?id=' <%# DataBinder.Eval(Container.DataItem, "数据字段1")%>' & name='<%# DataBinder.Eval(Container.DataItem, "数据字段2")%>' />
7.表格点击改变颜色
if (e.Item.ItemType == ListItemType.Item ||e.Item.ItemType == ListItemType.AlternatingItem) { e.Item.Attributes.Add("onclick","this.style.backgroundColor='#99cc00'; this.style.color='buttontext';this.style.cursor='default';"); } //写在DataGrid的_ItemDataBound里 if (e.Item.ItemType == ListItemType.Item ||e.Item.ItemType == ListItemType.AlternatingItem) { e.Item.Attributes.Add("onmouseover","this.style.backgroundColor='#99cc00'; this.style.color='buttontext';this.style.cursor='default';"); e.Item.Attributes.Add("onmouseout","this.style.backgroundColor='';this.style.color='';"); }8.VB.NET常用代码关于日期格式
日期格式设定
DataFormatString="{0:yyyy-MM-dd}"我觉得应该在itembound事件中
e.items.cell["你的列"].text=DateTime.Parse(e.items.cell["你的列"].text.ToString("yyyy-MM-dd"))9.获取错误信息并到指定页面
不要使用Response.Redirect,而应该使用Server.Transfer
e.g // in global.asax protected void Application_Error(Object sender, EventArgs e) { if (Server.GetLastError() is HttpUnhandledException) Server.Transfer("MyErrorPage.aspx"); //其余的非HttpUnhandledException异常交给ASP.NET自己处理就okay了 :) }Redirect会导致post-back的产生从而丢失了错误信息,所以页面导向应该直接在服务器端执行,这样就可以在错误处理页面得到出错信息并进行相应的处理
10.VB.NET常用代码清空Cookie
Cookie.Expires=[DateTime]; Response.Cookies("UserName").Expires = 0看完了这篇文章,相信你对"VB.NET常用代码有哪些"有了一定的了解,如果想了解更多相关知识,欢迎关注行业资讯频道,感谢各位的阅读!
表格
代码
常用
信息
参数
错误
页面
处理
事件
字段
数据
日期
格式
篇文章
完了
对话框
导向
按钮
更多
服务器
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
jquery调用数据库
生成焓 数据库
民法总则 网络安全
个人软件开发过程正式完整版
百米以上高楼数据库
数据库安全性设计流程
哪里查土壤修复数据库
安全狗服务器恢复隔离
软件开发的程度
2019国际网络安全大赛冠军
电脑出现安全模式网络安全模式
福建特种网络技术基础
ios软件开发iphone
大学数据库实训课程设计心得
数据库系统概论期中考试题库
计算机程序软件开发
苹果激活无服务器
帮有网络技术有限公司怎么样
数据仓库里为什么要建数据库
浦东新区大型网络技术采购信息
nvr服务器硬盘热插拔
没有服务器的管理权限设置
如何关闭腾讯网络安全网址
选修网络技术应用 目录
苏州科技城有互联网公司吗
dns服务器软件排名
数据库实体框架
物联网的网络安全
中通吉网络技术有限公司加班
计算机网络安全探究前言