杂项

 
November 06
预览上传图片
<INPUT id="File1" type="file" name="File1" runat="server" onchange="document.getElementById('IMG1').src=this.value;"><IMG id="IMG1" alt="" src="">
July 21
前台页面标签内容
前台:
<title runat="server" id="quit"></title>  
 
 
  protected System.Web.UI.HtmlControls.HtmlGenericControl quit;
    private void Page_Load(object sender, System.EventArgs e)
    {
        quit.InnerText = "标题内容";
    }
June 29
asp.net2.0 skin
一、简介:

  利用Themes我们可以很容易的更改控件、页面的风格,而不需要修改我们的代码和页面文件。Themes文件被单独的放在1个App_Themes文件夹下面,与你的程序是完全分开的。

  二、怎么使用Themes和Skins:

  先看个非常简单的实例:

App_Themes/default/1.skin文件代码:

<asp:Label Font-Bold="true" ForeColor="Red" runat="server" />

default.aspx:文件代码:

<%@ Page Language="C#" Theme="default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
 <title>Page with Example Theme Applied</title>
</head>
<body>
 <form id="form1" runat="server">
 <asp:Label ID="Label1" runat="server" Text="Hello 1" /><br />
 <asp:Label ID="Label2" runat="server" Text="Hello 2" /><br />
 </form>
</body>
</html>


  可以看到我们在default.aspx并没有写如何的控制style的代码,但运行取发现label上的字都变成了粗体红色了,这就是1个最基本的theme例子。

  App_Themes文件夹:

  App_Themes文件夹位于程序的根目录下,App_Themes下必须是Theme名称的子文件夹,子文件夹中可以包含多个.skin和.css文件。下图中建立2个Theme,名称分别为default和default2:



  使用themes

  1、在1个页面中应用Theme:

  如果想在某1个页面中应用Theme,直接在aspx文件中修改<%@ Page Theme="..." %>,比如你想这个页面应用default2 theme,设置<%@ Page Theme="default2" %>就OK

  2、在所有页面应用同1个Theme:

  如果要在所有页面上使用相同的Theme,在web.config中的<system.web>节点下加上句<pages theme="..."/>

  3、让控件不应用Theme:

  第1个例子中我们看到了2个Label的风格都变了,就是说.skin文件中的风格在页面上所有Label都起作用了。但有时我们希望某1个Label不应用.skin中的风格,这时你只需设置Label的EnableTheming属性为false的时候就可以了。

  也许你还想不同的label显示不同的风格,你只需设置label的SkinID属性就可以,见下面的实例:

App_Themes/default/1.skin

<asp:label runat="server" font-bold="true" forecolor="Red" />
<asp:label runat="server" SkinID="Blue" font-bold="true" forecolor="blue" />

deafult.aspx

<%@ Page Language="C#" Theme="default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
 <title>Page with Example Theme Applied</title>
</head>
<body>
 <form id="form1" runat="server">
 <asp:Label ID="Label2" runat="server" Text="Hello 2" SkinID="Blue" /><br />
 <asp:Label ID="Label3" runat="server" Text="Hello 3" /><br />
 </form>
</body>
</html>

  运行后就会发现2个label显示的风格不一样了。

  4、其他方法:

  前面已经说了在aspx文件头使用 <%@ Page Theme="..." %> 来使用theme,而用这个方法应用theme中的风格将会覆盖你写在aspx中的控件属性style。比如:

  App_Themes/default/1.skin

<asp:Label Font-Bold="true" ForeColor="Red" runat="server" />

  default.aspx

<%@ Page Language="C#" Theme="default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
</head>
<body>
 <form id="form1" runat="server">
 <asp:Label ID="Label1" runat="server" Text="Hello 1" /><br />
 <asp:Label ID="Label2" runat="server" Text="Hello 2" ForeColor="blue" />
 </form>
</body>
</html>

  运行结果,所有的label的forecolor都为red。

  而使用<%@ Page StyleSheetTheme="..." %>应用theme就不会覆盖你在aspx文件中写的属性style:

  控件应用style属性的顺序如下:

  a、StyleSheetTheme引用的风格

  b、代码设定的控件属性(覆盖StyleSheetTheme)

  c、Theme引用的风格(覆盖前面2个)

  theme中包含CSS:

  theme中也可以使用.css文件,当你把.css文件放在1个theme目录下后,在用到了这个theme的页面中自动会应用你的.css的

  三、后台代码轻松为网站换府肤

  前面讲的都是在aspx文件或web.config中应用theme,而在blog这样的每个用户都有不同的skin的网站中用上面的方法来实现换skin显然是不方便的。

  下面就介绍怎么在后台代码中动态的引用theme来解决上面的情况,theme必须在page被请求的最早期就应用上,所以我们必须在Page_PreInit事件中写代码,代码很简单,就1句:

Page.Theme = "...";

  这里我们只要从数据库中去读取每个用户设置的不同theme名就可以轻松实现每个用户都有不同的skin了。
May 29
asp.net 实现购物车

 

<%@ Page language="c#" Codebehind="shoppingcart.aspx.cs" AutoEventWireup="false" Inherits="myshop.shoppingcart" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
  <HEAD>
  <title>shoppingcart</title>
  <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  <LINK href="mycss.css" type="text/css" rel="stylesheet">
  <meta name="vs_defaultClientScript" content="JavaScript">
  <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
  </HEAD>
 <body>
  <center>
   <form id="Form1" runat="server">
    <table width="500" border="0" cellspacing="0" cellpadding="0">
     <tr>
      <td>
       <ASP:DataGrid id="ShoppingCartDlt" runat="server" Width="500" BackColor="white" BorderColor="black"
        ShowFooter="false" CellPadding="3" CellSpacing="0" Font-Name="Verdana" Font-Size="8pt" HeaderStyle-BackColor="#cecfd6"
        AutoGenerateColumns="false" MaintainState="true">
        <Columns>
         <asp:TemplateColumn HeaderText="删除">
          <ItemTemplate>
           <center>
            <asp:CheckBox id="chkProductID" runat="server" />
           </center>
          </ItemTemplate>
         </asp:TemplateColumn>
         <asp:BoundColumn DataField="ProdID" HeaderText="ID" />
         <asp:BoundColumn DataField="ProName" HeaderText="商品名称" />
         <asp:BoundColumn DataField="UnitPrice" HeaderText="单价" />
         <asp:TemplateColumn HeaderText="数量">
          <ItemTemplate>
           <asp:TextBox id="CountTb" runat="server" Text=%27<%#DataBinder.Eval(Container.DataItem,"ProdCount")%>%27>
           </asp:TextBox>
          </ItemTemplate>
         </asp:TemplateColumn>
         <asp:BoundColumn DataField="TotalPrice" HeaderText="小计(元)" />
        </Columns>
       </ASP:DataGrid></td>
     </tr>
    </table>
    <br>
    <table width="500" border="0" cellspacing="0" cellpadding="0">
     <tr>
      <td><asp:Button id="update" runat="server" Text="更新我的购物车"  CssClass="button2" /></td>
      <td><asp:Button id="CheckOut" runat="server" Text="结算"  CssClass="button5" />&nbsp;&nbsp;<input type="button" name="close2" value="继续购物" onClick="window.close();return false;"
        class="button2"></td>
      <td align="right"><br>
       <asp:Label id="label" runat="server" Width="100px" Visible="True" ForeColor="#FF8080" Height="18px"></asp:Label></td>
     </tr>
    </table>
   </form>
  </center>
 </body>
</HTML>
=======================================================================================
以上为HTML页面部分
==========================================================================================


using System;
using System.Collections;
using System.ComponentModel;
using System.Web.SessionState;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;
using System.Configuration;

namespace myshop
{
 /// <summary>
 /// shoppingcart 的摘要说明。
 /// </summary>
 public class shoppingcart : System.Web.UI.Page
 {
  protected System.Web.UI.WebControls.DataGrid ShoppingCartDlt;
  protected System.Web.UI.WebControls.Button update;
  protected System.Web.UI.WebControls.Button CheckOut;
  protected System.Web.UI.HtmlControls.HtmlForm Form1;
  protected System.Web.UI.WebControls.Label label;
  protected System.Web.UI.WebControls.CheckBox     chkProductID;
  protected System.Web.UI.WebControls.TextBox      txtCount;
  protected System.Web.UI.WebControls.TextBox      CountTb;
  string AddProID;
 
  private void Page_Load(object sender, System.EventArgs e)
  {
   try
   {
    if (Session["logon"]!="yes"||Session["username"]==null)
    {
     Response.Redirect("error.htm") ;
    }
   }
   catch
   {
    Response.Redirect("error.htm") ;
   }                                         /////////////查看用户是否已经登陆。

   if(!IsPostBack)
   {
    if(Request.Params["mode"]=="view")         //检测是否为直接查看购物车。
    {
     ViewShoppingCart();
     Caculator();
    }
    if(Request.Params["productID"]!=null||Request.Params["productID"]!="")
    {
     AddProID=Request["productID"];
     UpdateShoppingCart();
     Caculator();
    }
   }// 在此处放置用户代码以初始化页面
  }

  public void CreateCartTable()   //创建购物车
  { 
   DataSet ds = new DataSet();
   DataTable newDT=new DataTable("CartTable");
   ds.Tables.Add(newDT);
   DataColumn newDC;
   newDC=new DataColumn("ProdID",System.Type.GetType("System.Int32"));
   ds.Tables["CartTable"].Columns.Add(newDC);

   newDC=new DataColumn("ProdCount",System.Type.GetType("System.Int32"));
   newDC.DefaultValue=1;
   ds.Tables["CartTable"].Columns.Add(newDC);

   newDC=new DataColumn("ProName",System.Type.GetType("System.String"));
   ds.Tables["CartTable"].Columns.Add(newDC);

   newDC=new DataColumn("UnitPrice",System.Type.GetType("System.Double"));
   ds.Tables["CartTable"].Columns.Add(newDC);
             
   newDC=new DataColumn("TotalPrice",System.Type.GetType("System.Double"));
   ds.Tables["CartTable"].Columns.Add(newDC);

   newDC=new DataColumn("IsDeleted",System.Type.GetType("System.Int32"));
   newDC.DefaultValue=0;                                                    //  public void WriteShoppingCart() 中 newDR[5]="0"; 行,已被注销,
   ds.Tables["CartTable"].Columns.Add(newDC);

   Session["myCartTable"]=newDT;
   ShoppingCartDlt.DataSource=ds.Tables["CartTable"].DefaultView;
   ShoppingCartDlt.DataBind();
      
  }

  public void UpdateShoppingCart()
  {
   if(Session["myCartTable"]==null)//Session["myCartTable"]==null
   {
    CreateCartTable();                                    //调用函数CreateCartTable()新建一个DataTable
    WriteShoppingCart();


   }
   else
   {                                                         //如果购物蓝中已有商品,则需要对购物信息表DataTable进行更新,并将其棒定到ShoppingCartDlt
                 
    WriteShoppingCart();
   }
  }

  public void ViewShoppingCart()                               //查看购物车
  {
   if(Session["myCartTable"]!=null)
   {
    DataTable viewTable=new DataTable("nowCartTable");
    viewTable=(DataTable)Session["myCartTable"];
    ShoppingCartDlt.DataSource = viewTable.DefaultView;         //购物车棒定到ShoppingCartDlt
    ShoppingCartDlt.DataBind();
   }
             
  }

  public void WriteShoppingCart()
  {
   if(Request.Params["mode"]!="view")                             //检查是否是直接查看购物车,如果直接查看,就不再写MYCARTTABLE
   {
    DataTable nowTable=new DataTable("nowCartTable");
    nowTable=(DataTable)Session["myCartTable"];
    int pn=nowTable.Rows.Count;

    int i=0;
    bool hasone=false;
    int nowProdID;
                 
    while(i<pn && !hasone)
    {
     nowProdID=Int32.Parse(nowTable.Rows[i][0].ToString());
     if(nowProdID==Int32.Parse(AddProID))                                   //判断购物信息表中,是否存有当前放入商品。 if(nowProdID==Int32.Parse(AddProID))
     {
      hasone=true;
     }
     else
     {
      i++;
     }

    }
    if(hasone)                          
    {                                                      //如果已有该商品,则 hasone=true,更改该数据行
     DataRow oldDR;
     oldDR=nowTable.Rows[i];
     oldDR["ProdCount"]=Int32.Parse(oldDR["ProdCount"].ToString())+1;
     oldDR["TotalPrice"]=Int32.Parse(oldDR["ProdCount"].ToString())*Double.Parse(oldDR["UnitPrice"].ToString());
    }
    else
    {                                                      //如果没有该商品,在表中新加如一行。
     DataRow newDR;
     double unitp;
     String strcon="provider=Microsoft.jet.OLEDB.4.0;data Source="+Server.MapPath(ConfigurationSettings.AppSettings["MDBpath2"])+";";
     OleDbConnection myConnection = new OleDbConnection(strcon);
     string strSQL= "select *  from pro where product_id="+AddProID+"";
     OleDbDataAdapter myCommand = new  OleDbDataAdapter(strSQL, myConnection);
     DataSet ds = new DataSet();
     myCommand.Fill(ds, "AddP");

     newDR=nowTable.NewRow();
     newDR[0]=AddProID;
                       
     newDR[2]=ds.Tables["Addp"].Rows[0]["product_name"].ToString();
     unitp=Double.Parse(ds.Tables["AddP"].Rows[0]["product_memprice"].ToString());        //会员价
                      
     newDR[3]=unitp;
     newDR[4]=unitp;                                           //第一次读库,所以总价格和单价是一样的。
     //newDR[5]="0";
     nowTable.Rows.Add(newDR);
                
     myConnection.Close();
                    
    }
                 
    ShoppingCartDlt.DataSource = nowTable.DefaultView;         //将更新后的 DataTable棒定到ShoppingCartDlt
    ShoppingCartDlt.DataBind();

    Session["myCartTable"] = nowTable; 
    //重新保存更新过的DataTable
   }   
  }

  
  
  public void Caculator()
  {
   if(Session["myCartTable"]!=null)                         //购物车是否为空
   {
    int h;
    Double TotalPri;
    TotalPri=0;
    DataTable nowTable3=new DataTable("nowCartTable3");
    nowTable3=(DataTable)Session["myCartTable"];
    if(nowTable3.Rows.Count>0)                               //返回购物车中是否有货物
    {
     for(h=0;h<=nowTable3.Rows.Count-1;h++)
     {       
      TotalPri=TotalPri+Int32.Parse(nowTable3.Rows[h][4].ToString());//Double.Parse((string)TotalText.Text);
                                        
     }
     label.Text="总计: "+TotalPri.ToString()+" 元" ;
    }
   }
  
  }

  public void Update()
  {
   
   int i;
   int j;
   int k;
   ArrayList deleteItem = new ArrayList(10);
   DataGridItem _item ;
   j=0;
   int deleteid;
     
            
   k=0;
   DataTable nowTable2=new DataTable("nowCartTable2");
   nowTable2=(DataTable)Session["myCartTable"];
    
           
   
   
   
   for(i=0;i<=this.ShoppingCartDlt.Items.Count-1;i++)
   {
    _item = this.ShoppingCartDlt.Items[i];
    TextBox CountText=(TextBox)this.ShoppingCartDlt.Items[i].Cells[4].FindControl("CountTb");//Controls[1];//_item.FindControl("CountTb");
    CheckBox ProductIDCheck =(CheckBox) _item.FindControl("chkProductID");
    
    nowTable2.Rows[i][1] = Int32.Parse(CountText.Text.ToString());
    nowTable2.Rows[i][4] = Int32.Parse(nowTable2.Rows[i][1].ToString()) * Double.Parse(nowTable2.Rows[i][3].ToString());

    if(ProductIDCheck.Checked)
    {
     nowTable2.Rows[i][5] = 1;//添加删除标记1
     j=j+1;
    }
    
   }
   string strExpr="IsDeleted>0";                     //http://msdn.microsoft.com/library/chs/default.asp?url=/library/CHS/cpref/html/frlrfSystemDataDataTableClassSelectTopic.asp
   DataRow[] foundRows = nowTable2.Select(strExpr);
   for(int m = 0; m < foundRows.Length; m ++)
   {
    //Console.WriteLine(foundRows[i][0]);
    foundRows[m].Delete();
   }
          
            
             
                              
   
   ShoppingCartDlt.DataSource = nowTable2.DefaultView;       
   ShoppingCartDlt.DataBind();
   Session["myCartTable"] = nowTable2;
   Caculator();

  }

  #region Web 窗体设计器生成的代码
  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
   //
   InitializeComponent();
   base.OnInit(e);
  }
  
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {   
   this.update.Click += new System.EventHandler(this.update_Click);
   this.CheckOut.Click += new System.EventHandler(this.CheckOut_Click);
   this.Load += new System.EventHandler(this.Page_Load);

  }
  #endregion

  private void update_Click(object sender, System.EventArgs e)
  {
   Update();
  
  }

  private void CheckOut_Click(object sender, System.EventArgs e)
  {
   Update();
   Response.Redirect("checkout.aspx");
  }
 }
}

May 22
DataGrid_EditCommand中使用eWebEditor获取id的问题
前台页面
<asp:TextBox id=content1 style="DISPLAY: none" runat="server" text='<%# DataBinder.Eval(Container.DataItem,"content") %>'></asp:TextBox>
<IFRAME id=eWebEditor1 src="ewebeditor/ewebeditor.asp?id=<%=i%>&amp;style=s_coolblue" frameBorder=0 width=550 scrolling=no height=350></IFRAME>
 
生成页面后 input id不固定,所以iframe中id参数不好确定
 
private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
  {
   this.DataGrid1.EditItemIndex=e.Item.ItemIndex;
   this.DataListBind();
   LinkButton bu=(LinkButton)e.Item.FindControl("LinkButton5");//获取按钮id
   i=bu.ClientID.ToString().Replace("LinkButton5","content1");//将按钮id后半段替换,就是对应input的id
  }
 
不能在这里通过
TextBox txtContent=(TextBox)e.Item.FindControl("content1");取得名称
因为它用于DataGrid1_UpdateCommand中
May 19
图片上的鼠标事件效果
------------图片透明度变化-------------
 
<SCRIPT language=JavaScript>
var i
function change(i){
var source=event.srcElement;
if (source.tagName=="IMG")
    source.style.filter="alpha(opacity="+i+")"
}
</SCRIPT>
 
 
onmouseover=change(100) onmouseout=change(20)
 
-------------图片颜色变化----------------
 
<SCRIPT language=JavaScript>
var i
function change(i){
var source=event.srcElement;
if (source.tagName=="IMG")
    source.style.filter=""+i+""
}
</SCRIPT>
 
 
onmouseover=change() onmouseout="change('gray')"
April 25
DW定制网页过渡功能
网页过渡是指当浏览者进入或离开网页时,页面呈现的不同的刷新效果,比如卷动、百叶窗等。这样你的网页看起来会更具有动感,不过也要注意适可而止,否则太花哨的变化也容易引起浏览者的反感。

  实现这个功能并不难,只需两步。

  首先用Dreamweaver打开页面,然后单击菜单中的Insert/Head/Meta(插入/文件头标签/Meta),会弹出如下图所示的对话框。

   在对话框中的Attribute选项的下拉列表中选HTTP-equivalent选项。
  在Value:中键入Page-Enter 或者 Page-Exit,表示进入网页或退出时,有网页过渡效果。
  在Content:中键入 Revealtrans(Duration=4,Transition=2) 。Duration=4 表示网页过渡效果的延续时间为4秒,Transition表示过渡效果方式,值为2时表示圆形收缩。

输入完后单击确定,存盘。这样当我们点击一个超链接进入这个页面时就可以看到效果了。另外还有二十多种效供你选择,只要将Transition的值改为相应的效果的代号即可,具体效果和设置如下表所示:

效果
 Content
 Transitionv
盒状收缩
RevealTrans
0 
盒状展开 
RevealTrans
1
圆形收缩 
RevealTrans
2 
圆形展开
RevealTrans
3
向上擦除
RevealTrans
4
向下擦除
RevealTrans
5
向左擦除
RevealTrans
6
向右擦除
RevealTrans
7
垂直百页窗
RevealTrans
8
水平百页窗
RevealTrans
9
横向棋盘式
RevealTrans
10
纵向棋盘式
RevealTrans
11
溶解
RevealTrans
12
左右向中部收缩
RevealTrans
13
中部向左右展开
RevealTrans
14
上下向中部收缩
RevealTrans
15
中部向上下展开
RevealTrans
16
阶梯状向左下展开
RevealTrans
17
阶梯状向左上展开
RevealTrans
18
阶梯状向右下展开
RevealTrans
19
阶梯状向右上展开
RevealTrans
20
随机水平线
RevealTrans
21
随机垂直线
RevealTrans
22
随机
RevealTrans
23

April 21
点选“全选“复选框,实现对一组复选框操作
给每个复选框赋值:
<input name="checkbox2" type="checkbox" class="input01" id="checkbox2" value="<%#DataBinder.Eval(Container.DataItem,"messageid")%>">
 
全部选择的复选框:(点选后触发CHeckAll方法)
<input name="checkbox2" type="checkbox" class="input01" id="Checkbox2" value=0 onclick="CheckAll()">
 
//------------------------------------------------------------------------
<script language="javascript">
function CheckAll()
{
var allchecked = true;
for(var i=0;i<Form1.checkbox2.length;i++)
{
if(Form1.checkbox2[i].checked)
allchecked = true;
else
allchecked = false;
}
for(var i=0;i<Form1.checkbox2.length;i++)
{
if(allchecked)
Form1.checkbox2[i].checked = true;
else
Form1.checkbox2[i].checked = false;
}
}
</script>
 
//后台操作---------------------------------------------------------------------
   string strCheck;
 
   if(this.Request["checkbox2"]!=null)
   {
    strCheck = this.Request["checkbox2"].ToString();
   }
 
   update user_message set IsSendDel=1 where messageid in ("+strCheck+")
April 19
css强制换行
大家都知道连续的英文或数字能是容器被撑大,不能根据容器的大小自动换行,下面是 CSS如何将他们换行的方法!

对于div

1.(IE浏览器)white-space:normal; word-break:break-all;这里前者是遵循标准。

#wrap{white-space:normal; width:200px; }
或者
#wrap{word-break:break-all;width:200px;}

eg.
<div id="wrap">ddd1111111111111111111111111111111111111111111111111111111111111111111</div>

效果:可以实现换行

2.(Firefox浏览器)white-space:normal; word-break:break-all;overflow:hidden;同样的FF下也没有很好的实现方法,只能隐藏或者加滚动条,当然不加滚动条效果更好!

#wrap{white-space:normal; width:200px; overflow:auto;}
或者
#wrap{word-break:break-all;width:200px; overflow:auto; }

eg.

<div id="wrap">ddd1111111111111111111111111111111111111111111111111111111111111111111</div>

效果:容器正常,内容隐藏

对于table

1. (IE浏览器)使用样式table-layout:fixed;
eg.
<style>
.tb{table-layout:fixed}
</style>

<table class="tbl" width="80">
<tr>
<td>abcdefghigklmnopqrstuvwxyz 1234567890
</td>
</tr>
</table>

效果:可以换行

2.(IE浏览器)使用样式table-layout:fixed与nowrap
eg.
<style>
.tb {table-layout:fixed}
</style>

<table class="tb" width="80">
<tr>
<td nowrap>abcdefghigklmnopqrstuvwxyz 1234567890
</td>
</tr>
</table>

效果:可以换行

3. (IE浏览器)在使用百分比固定td大小情况下使用样式table-layout:fixed与nowrap

<style>
.tb{table-layout:fixed}
</style>

<table class="tb" width=80>
<tr>
<td width=25% nowrap>abcdefghigklmnopqrstuvwxyz 1234567890
</td>
<td nowrap>abcdefghigklmnopqrstuvwxyz 1234567890
</td>
</tr>
</table>

效果:两个td均正常换行

3.(Firefox浏览器)在使用百分比固定td大小情况下使用样式table-layout:fixed与nowrap,并且使用div
eg.
<style>
.tb {table-layout:fixed}
.td {overflow:hidden;}
</style>

<table class=tb width=80>
<tr>
<td width=25% class=td nowrap>
<div>abcdefghigklmnopqrstuvwxyz 1234567890</div>
</td>
<td class=td nowrap>
<div>abcdefghigklmnopqrstuvwxyz 1234567890</div>
</td>
</tr>
</table>

这里单元格宽度一定要用百分比定义

效果:正常显示,但不能换行(注:在FF下还没有能使容器内容换行的好方法,只能用overflow将多出的内容隐藏,以免影响整体效果)
后台隐藏用户控件的方法
控件名SortList.ascx  路径: DreamZone.Web/PageCtrls/SortRead文件夹内
 
using DreamZone.Web.PageCtrls.SortRead;  //导入命名空间
SortList sl=(SortList)this.FindControl("SortList1");
sl.Visible=false;
April 14
一个递归的实例
取出目录结构中chapterid下的所以子节点名称chaptername放入strChaptername
 
private string digui(string chapterid)
  {
   string strSql="select chapterid,chaptername from writing_chapter where parentid="+chapterid;
   DataTable dt=sqlhelp.ExecuteSqlDataTable(strSql);
   string strChaptername="";
   
   for(int i=0;i<dt.Rows.Count;i++)    //取出所有parentid=chapterid的数据
   {
    DataRow dr=dt.Rows[i];
    strChaptername=strChaptername+dr["chaptername"].ToString();
    digui(dr["chapterid"].ToString());  //如果子节点下面还有节点则下面还有节点则再次调用本方法
   }
   return strChaptername;
  }
April 11
修改信息页面中的-ispostback-属性的作用
从数据库读数据赋值到textbox,然后保存修改后textbox的值
代码:
/////////////////////////////////////////////////////////////赋值 Page_Load
private void List()
{  
   if(!this.IsPostBack)
   {
    this.List();//如果是第一次加载的话执行该语句(当按钮点击时要重新加载Page_Load事件,会把修改信息重新从库中读出)
   }
   strcmd="select i.usernickname,m.title,m.content from user_message m join user_info i on m.ReceiveUserID=i.userid where m.UserID="+userid+" and m.messageid="+messageid;
   SqlDataReader dr=ssd.ExecuteSqlReader(strcmd);
   if (dr.Read())
   {
    this.TextBox1.Text =dr["usernickname"].ToString();
    this.TextBox2.Text=dr["title"].ToString();
    this.TextBox3.Text=dr["content"].ToString();
   }
   dr.Close();
}
/////////////////////////////////////////////////////////////取值并保存修改 Button_Click
string usernickname,title,content,cmd,cmdtext;
   usernickname=this.TextBox1.Text;
   title=this.TextBox2.Text;
   content=this.TextBox3.Text;

     ReceiveUserID=ssd.ExecuteSqlObject(cmd).ToString();
     cmdtext="update user_message set title='"+title+"',content='"+content+"',ReceiveUserID="+ReceiveUserID+", Issend=1,senddate='"+DateTime.Now+"' where messageid="+messageid;
     ssd.ExecuteSql(cmdtext);
 
一些零碎的东东
服务器控件中添加javascript触发事件
this.Button1.Attributes.Add("onclick","javascript:checkword()");
 
刷新addresslist.aspx页面
<script>location.replace('addresslist.aspx')</script>
 
强制换行
style="table-layout:fixed;word-wrap:break-word;word-break:break-all"
javaScript语句控制全部选择多个复选框
通过点击一个“全部选中“的复选框将列表中的按钮全部选中
<script language="javascript">
function CheckAll()
{
if(Form1.checkbox.checked)//检测全部选择的复选框是否被选中
var allchecked = true;//如被选中则变量赋值为1
else
allchecked = false
for(var i=0;i<Form1.checkbox2.length;i++)//通过循环给每个复选框赋值
{
Form1.checkbox2[i].checked = allchecked ;
}
}
</script>
以上有一个bug 当数据为一条时 点击全选不能选中(为一条时checkbox2不是数组)
 
尝试解决方案
 
<script language="javascript">
function CheckAll()
{
var v;
v=Form1.checkbox2.length-1
if(!Form1.checkbox2[i].checked)
allchecked = false;
for(var i=0;i<Form1.checkbox2.length;i++)
{
if(allchecked)
Form1.checkbox2[i].checked = false;
else
Form1.checkbox2[i].checked = true;
}
}
</script>
当没有数据时 点击全选选框出错
 
正确解决方案
<script language="javascript">
function CheckAll()
{
var allchecked = true;
for(var i=0;i<Form1.checkbox2.length;i++)
{
if(!Form1.checkbox2[i].checked)
allchecked = false;
}
for(var i=0;i<Form1.checkbox2.length;i++)
{
if(allchecked)
Form1.checkbox2[i].checked = false;
else
Form1.checkbox2[i].checked = true;
}
}
</script>
 
后台接收
   if(this.Request["checkbox2"]!=null)//判断是否有复选框数据
   {
    strCheck = this.Request["checkbox2"].ToString();
   }
 
数据库处理
  private void btnDel_Click(object sender, System.EventArgs e)//点击删除按钮后的动作
  {
   ssd.ExecuteSql("update user_friend set isdelete=1 where id in ("+strCheck+")");
   this.List();
  }
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值