ASP.NET中常用的三十三种代码第1/7页
程序员文章站
2023-11-29 16:56:46
1. 打开新的窗口并传送参数: 传送参数: response.write("<script>window.open('*.aspx?id="+this...
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='';");
}
传送参数:
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='';");
}
1
上一篇: Android在Fragment中实现监听触摸事件
下一篇: 跟老齐学Python之网站的结构