時間:2015-06-28 00:00:00 來源:IT貓撲網(wǎng) 作者:網(wǎng)管聯(lián)盟 我要評論(0)
1.彈出對話框.點(diǎn)擊轉(zhuǎn)向指定頁面
Code:
Response.Write("");
Response.Write("");
2.彈出對話框
Code:
Response.Write("");
3.刪除文件
Code:
string filename ="20059595157517.jpg";
pub.util.DeleteFile(HttpContext.Current.Server.MapPath("../file/")+filename);
4.綁定下拉列表框datalist
Code:
System.Data.DataView dv=conn.Exec_ex("select -1 as code,'請選擇經(jīng)營模式' as content from dealin union select code,content from dealin");
this.dealincode.DataSource=dv;
this.dealincode.DataTextField="content";
this.dealincode.DataValueField="code";
this.dealincode.DataBind();
this.dealincode.Items.FindByValue(dv[0]["dealincode"].ToString()).Selected=true;
5.時間去秒顯示
Code:
<%# System.DateTime.Parse(DataBinder.Eval(Container.DataItem,"begtime").ToString()).ToShortDateString()%>
6.標(biāo)題帶鏈接
Code:
<%# ""+ DataBinder.Eval(Container.DataItem,"proname")+""%>
7.修改轉(zhuǎn)向
Code:
<%# ""+"修改"+""%>
8.彈出確定按鈕
Code:
<%# ""+"刪除"+""%>
9.輸出數(shù)據(jù)格式化 "{0:F2}" 是格式 F2表示小數(shù)點(diǎn)后剩兩位
Code:
<%# DataBinder.Eval(Container, "DataItem.PriceMoney","{0:F2}") %>
10.提取動態(tài)網(wǎng)頁內(nèi)容
Code:
Uri uri = new Uri("http://m.ygkjgt7.cn/");
WebRequest req = WebRequest.Create(uri);
WebResponse resp = req.GetResponse();
Stream str = resp.GetResponseStream();
StreamReader sr = new StreamReader(str,System.Text.Encoding.Default);
string t = sr.ReadToEnd();
this.Response.Write(t.ToString());
11.獲取" . "后面的字符
Code:
i.ToString().Trim().Substring(i.ToString().Trim().LastIndexOf(".")+1).ToLower().Trim()
12. 打開新的窗口并傳送參數(shù):
傳送參數(shù):
Code:
response.write("<script>window.open(’*.aspx?id="+this.DropDownList1.SelectIndex+"&id1="+...+"’)</script>")
接收參數(shù):
Code:
string a = Request.QueryString("id");
string b = Request.QueryString("id1");
12.為按鈕添加對話框
Code:
Button1.Attributes.Add("onclick","return confirm(’確認(rèn)?’)");
button.attributes.add("onclick","if(confirm(’are you sure...?’)){return true;}else{return false;}")
13.刪除表格選定記錄
Code:
int intEmpID = (int)MyDataGrid.DataKeys[e.Item.ItemIndex];
string deleteCmd = "Delete from Employee where emp_id = " + intEmpID.ToString()
14.刪除表格記錄警告
Code:
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;
}
}
15.點(diǎn)擊表格行鏈接另一頁
Code:
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事件中
Code:
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 + "’");
}
雙擊表格打開新一頁
Code:
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 + "’)");
}
16.表格超連接列傳遞參數(shù)
Code:
?。糰sp: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")%>’ />
17.表格點(diǎn)擊改變顏色
Code:
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里
Code:
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=’’;");
}
18.關(guān)于日期格式
日期格式設(shè)定
Code:
DataFormatString="{0:yyyy-MM-dd}"
我覺得應(yīng)該在itembound事件中
e.items.cell["你的列"].text=DateTime.Parse(e.items.cell["你的列"].text.ToString("yyyy-MM-dd"))
Code:
19.獲取錯誤信息并到指定頁面
不要使用Response.Redirect,而應(yīng)該使用Server.Transfer
e.g
Code:
// in global.asax
protected void Application_Error(Object sender, EventArgs e) {
if (Server.GetLastError() is HttpUnhandledException)
Server.Tra
關(guān)鍵詞標(biāo)簽:Asp.net
相關(guān)閱讀
熱門文章 誅仙3飛升任務(wù)怎么做-誅仙3飛升任務(wù)流程最新2022 鐘離圣遺物推薦-原神鐘離圣遺物詞條 解決方法:應(yīng)用程序“DEFAULT WEB SITE”中的服務(wù)器錯誤 使用aspnet_regiis.exe 重新注冊.NET Framework
人氣排行 誅仙3飛升任務(wù)怎么做-誅仙3飛升任務(wù)流程最新2022 asp.net表單提交方法GET\POST 在ASP.NET中如何判斷用戶IE瀏覽器的版本 Asp.net中messagebox的實(shí)現(xiàn)方法 Asp.net中的web.config配置 在ASP.NET MVC中實(shí)現(xiàn)大文件異步上傳 asp.net獲取URL和IP地址 FileUpload上傳多文件出現(xiàn)錯誤的解決方法