ASP.NET中常用的三十三種代碼第1/7頁
更新時間:2007年03月25日 00:00:00 作者:
1. 打開新的窗口并傳送參數(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.為按鈕添加對話框
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('您是否確定要刪除這條信息');");
break;
default:
break;
}
}
5.點(diǎn)擊表格行鏈接另一頁
private void grdCustomer_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
//點(diǎn)擊表格打開
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.表格超連接列傳遞參數(shù)
<asp:HyperLinkColumn Target="_blank" headertext="ID號" 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';");
}
寫在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.為按鈕添加對話框
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('您是否確定要刪除這條信息');");
break;
default:
break;
}
}
5.點(diǎn)擊表格行鏈接另一頁
private void grdCustomer_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
//點(diǎn)擊表格打開
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.表格超連接列傳遞參數(shù)
<asp:HyperLinkColumn Target="_blank" headertext="ID號" 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';");
}
寫在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)文章
asp.net 根據(jù)漢字的拼音首字母搜索數(shù)據(jù)庫(附 LINQ 調(diào)用方法)
我們經(jīng)常需要使用拼音首字母來檢索數(shù)據(jù)庫,特別是應(yīng)用于醫(yī)院、商店等行業(yè)軟件中。譬如搜索“zgr”就可以搜索所有包含“中國人”的記錄。那么如果來實(shí)現(xiàn)才能即高效又方便呢?2010-04-04
在Asp.net core項(xiàng)目中使用WebSocket
這篇文章介紹了在Asp.net core項(xiàng)目中使用WebSocket的方法,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-08-08
使用母版頁時內(nèi)容頁如何使用css和javascript
由于網(wǎng)站的主要頻道頁和列表頁的頭部和底部都是一樣的,如果將每個頁面放在單獨(dú)的頁面中,當(dāng)頭部和底部需要更改時維護(hù)量太大。于是想把頭部和底部做成母版頁,頻道頁和列表頁的具體內(nèi)容放到內(nèi)容頁中。這樣當(dāng)頭和底需要改動時,只要修改一下母版頁就可以了。2009-08-08
ASP.NET Core使用AutoMapper實(shí)現(xiàn)實(shí)體映射
本文詳細(xì)講解了ASP.NET Core使用AutoMapper實(shí)現(xiàn)實(shí)體映射的方法,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-03-03
.net c# gif動畫如何添加圖片水印實(shí)現(xiàn)思路及代碼
本文將詳細(xì)介紹下c#實(shí)現(xiàn)gif動畫添加圖片水印,思路很清晰,感興趣的你可以參考下哈,希望可以幫助到你2013-03-03

