首页 优化推广 Asp.net非常实用的51个代码(1)

Asp.net非常实用的51个代码(1)

来源: | 时间:2013/8/28 14:38:32 |

1.//弹出对话框.点击转向指定页面

  1. Response.Write(&quot;<script>window.alert('该会员没有提交申请,请重新提交!')</script>&quot;);

  2. Response.Write(&quot;<script>window.location ='http://www.51aspx.com/bizpulic/upmeb.aspx'</script>&quot;);
复制代码

2.//弹出对话框

  1. Response.Write(&quot;<script language='javascript'>alert('产品添加成功!')</script >&quot;);
复制代码

3.//删除文件

  1. string filename =&quot;20059595157517.jpg&quot;;

  2. pub.util.DeleteFile(HttpContext.Current.Server.MapPath(&quot;../file/&quot;)+filename);
复制代码

4.//绑定下拉列表框datalist

  1. System.Data.DataView dv=conn.Exec_ex(&quot;Select -1 as code,'请选择经营模式' as content from dealin union Select code,content from dealin&quot;);

  2. this.dealincode.DataSource=dv;

  3. this.dealincode.DataTextField=&quot;content&quot;;

  4. this.dealincode.DataValueField=&quot;code&quot;;    

  5. this.dealincode.DataBind();

  6. this.dealincode.Items.FindByValue(dv[0][&quot;dealincode&quot;].ToString()).Selected=true;
复制代码

5.//时间去秒显示

  1. <%# System.DateTime.Parse(DataBinder.Eval(Container.DataItem,&quot;begtime&quot;).ToString()).ToShortDateString()%>
复制代码

6.//标题带链接

  1. <%# &quot;<a class=\&quot;12c\&quot; target=\&quot;_blank\&quot; href=\&quot;http://www.51aspx/CV/_&quot;+DataBinder.Eval(Container.DataItem,&quot;procode&quot;)+&quot;.html\&quot;>&quot;+ DataBinder.Eval(Container.DataItem,&quot;proname&quot;)+&quot;</a>&quot;%>
复制代码

7.//修改转向

  1. <%# &quot;<A href=\&quot;editpushpro.aspx?id=&quot;+DataBinder.Eval(Container.DataItem,&quot;code&quot;)+&quot;\&quot;>&quot;+&quot;修改&quot;+&quot;</A>&quot;%>
复制代码

8.//弹出确定按钮

  1. <%# &quot;<A id=\&quot;btnDelete\&quot; onclick=\&quot;return confirm('你是否确定删除这条记录吗?');\&quot; href=\&quot;pushproduct.aspx?dl=&quot;+DataBinder.Eval(Container.DataItem,&quot;code&quot;)+&quot;\&quot;>&quot;+&quot;删除&quot;+&quot;</A>&quot;%>
复制代码

9.//输出数据格式化 "{0:F2}" 是格式 F2表示小数点后剩两位

  1. <%# DataBinder.Eval(Container, &quot;DataItem.PriceMoney&quot;,&quot;{0:F2}&quot;) %>
复制代码

10.//提取动态网页内容

  1. Uri uri = new Uri(&quot;http://www.51aspx.com/&quot;);

  2.    WebRequest req = WebRequest.Create(uri);

  3.    WebResponse resp = req.GetResponse();

  4.    Stream str = resp.GetResponseStream();

  5.    StreamReader sr = new StreamReader(str,System.Text.Encoding.Default);

  6.    string t = sr.ReadToEnd();

  7.    this.Response.Write(t.ToString());
复制代码

11.//获取" . "后面的字符

  1. i.ToString().Trim().Substring(i.ToString().Trim().LastIndexOf(&quot;.&quot;)+1).ToLower().Trim()
复制代码

12. 打开新的窗口并传送参数:   传送参数:

  1. response.write(&quot;<script>window.open(’×.aspx?id=&quot;+this.DropDownList1.SelectIndex+&quot;&amp;id1=&quot;+...+&quot;’)</script>&quot;)
复制代码

接收参数:

  1. string a = Request.QueryString(&quot;id&quot;);

  2. string b = Request.QueryString(&quot;id1&quot;);
复制代码

12.为按钮添加对话框

  1. Button1.Attributes.Add(&quot;onclick&quot;,&quot;return confirm(’确认?’)&quot;);

  2. button.attributes.add(&quot;onclick&quot;,&quot;if(confirm(’are you sure...?’)){return true;}else{return false;}&quot;)
复制代码

13.删除表格选定记录

  1. int intEmpID = (int)MyDataGrid.DataKeys[e.Item.ItemIndex];

  2. string deleteCmd = &quot;Delete from Employee where emp_id = &quot; + intEmpID.ToString()
复制代码

14.删除表格记录警告

  1. private void DataGrid_ItemCreated(Object sender,DataGridItemEventArgs e)

  2. {

  3.  switch(e.Item.ItemType)

  4.  {

  5.   case ListItemType.Item :

  6.   case ListItemType.AlternatingItem :

  7.   case ListItemType.EditItem:

  8.    TableCell myTableCell;

  9.    myTableCell = e.Item.Cells[14];

  10.    LinkButton myDeleteButton ;

  11.    myDeleteButton = (LinkButton)myTableCell.Controls[0];

  12.    myDeleteButton.Attributes.Add(&quot;onclick&quot;,&quot;return confirm(’您是否确定要删除这条信息’);&quot;);

  13.    break;

  14.   default:

  15.    break;

  16.  }

  17. }
复制代码

15.点击表格行链接另一页

  1. private void grdCustomer_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)

  2. {

  3.  //点击表格打开

  4.  if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListIte

服务热线

153 8323 9821

功能和特性

价格和优惠

网站和维护

推广和优化

微信服务号