ASP.NET中常用的三十三種代碼第1/7頁(yè)
更新時(shí)間:2007年03月25日 00:00:00 作者:
1. 打開(kāi)新的窗口并傳送參數(shù):
傳送參數(shù):
response.write("<script>window.open('*.aspx?id="+this.DropDownList1.SelectIndex+"&id1="+...+"')</script>")
接收參數(shù):
string a = Request.QueryString("id");
string b = Request.QueryString("id1");
2.為按鈕添加對(duì)話框
Button1.Attributes.Add("onclick","return confirm('確認(rèn)?')");
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('您是否確定要?jiǎng)h除這條信息');");
break;
default:
break;
}
}
5.點(diǎn)擊表格行鏈接另一頁(yè)
private void grdCustomer_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
//點(diǎn)擊表格打開(kāi)
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 + "');");
}
雙擊表格連接到另一頁(yè)
在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 + "'");
}
雙擊表格打開(kāi)新一頁(yè)
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.表格超連接列傳遞參數(shù)
<asp:HyperLinkColumn Target="_blank" headertext="ID號(hào)" DataTextField="id" NavigateUrl="aaa.aspx?id='
<%# DataBinder.Eval(Container.DataItem, "數(shù)據(jù)字段1")%>' & name='<%# DataBinder.Eval(Container.DataItem, "數(shù)據(jù)字段2")%>' />
7.表格點(diǎn)擊改變顏色
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';");
}
寫(xiě)在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='';");
}
傳送參數(shù):
response.write("<script>window.open('*.aspx?id="+this.DropDownList1.SelectIndex+"&id1="+...+"')</script>")
接收參數(shù):
string a = Request.QueryString("id");
string b = Request.QueryString("id1");
2.為按鈕添加對(duì)話框
Button1.Attributes.Add("onclick","return confirm('確認(rèn)?')");
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('您是否確定要?jiǎng)h除這條信息');");
break;
default:
break;
}
}
5.點(diǎn)擊表格行鏈接另一頁(yè)
private void grdCustomer_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
//點(diǎn)擊表格打開(kāi)
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 + "');");
}
雙擊表格連接到另一頁(yè)
在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 + "'");
}
雙擊表格打開(kāi)新一頁(yè)
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.表格超連接列傳遞參數(shù)
<asp:HyperLinkColumn Target="_blank" headertext="ID號(hào)" DataTextField="id" NavigateUrl="aaa.aspx?id='
<%# DataBinder.Eval(Container.DataItem, "數(shù)據(jù)字段1")%>' & name='<%# DataBinder.Eval(Container.DataItem, "數(shù)據(jù)字段2")%>' />
7.表格點(diǎn)擊改變顏色
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';");
}
寫(xiě)在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='';");
}
相關(guān)文章
WPF實(shí)現(xiàn)畫(huà)線動(dòng)畫(huà)效果
這篇文章主要為大家詳細(xì)介紹了WPF實(shí)現(xiàn)畫(huà)線動(dòng)畫(huà)效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-12-12.NET使用報(bào)表工具FastReport實(shí)現(xiàn)打印功能
這篇文章介紹了.NET使用報(bào)表工具FastReport實(shí)現(xiàn)打印功能的方法,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-03-03asp.net程序優(yōu)化 盡量減少數(shù)據(jù)庫(kù)連接操作
最近做一個(gè)項(xiàng)目,做的比較郁悶,現(xiàn)在把項(xiàng)目經(jīng)驗(yàn)總結(jié)在這里。項(xiàng)目的主要功能就是為第三方程序提供數(shù)據(jù),并根據(jù)客戶端的調(diào)用提供數(shù)據(jù)更新。我的程序?qū)儆诜?wù)端。服務(wù)端以站點(diǎn)形式部署,以Xml的數(shù)據(jù)格式輸出2012-05-05Asp.net SignalR 讓實(shí)時(shí)通訊變得如此簡(jiǎn)單
下面小編就為大家分享一篇Asp.net SignalR 讓實(shí)時(shí)通訊變得如此簡(jiǎn)單,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-01-01