天天看點

學習筆記(在商飛項目裡 1)

1、 table 每行 滑鼠懸停和移出的樣式變化:
<tr class="line-odd" onmouseover="currentcolor = this.style.backgroundColor;this.style.backgroundColor='#F7FFF7';this.style.cursor='hand';" onmouseout="this.style.backgroundColor = currentcolor;">
 <td>二号樓</td>
 <td></td>
</tr>

2、由1,我們可以對gridview行 滑鼠懸停和移出的樣式變化:
  protected void gvBuildList_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                try
                {
                    e.Row.Attributes.Add("onmouseover", "currentcolor = this.style.backgroundColor;this.style.backgroundColor='#F7FFF7';this.style.cursor='hand';");
                    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor = currentcolor;");
                }
                catch { }
            }
        }
3 xml檔案,删除節點的方法:
                DataSet ds = new DataSet();
                ds.ReadXml(Server.MapPath("XML/BuildList.xml"));
                bool isHave = false;
                foreach (DataRow drTemp in ds.Tables[0].Rows)
                {
                    if (drTemp["BuildText"].ToString().Equals(this.gvBuildList.Rows[e.RowIndex].Cells[0].Text))
                    {
                        drTemp.Delete();
                        break;
                    }
                }
                ds.WriteXml(Server.MapPath("XML/BuildList.xml"));


4 文本框中隻能輸入數字的js方法:
function CheckTotalPrice(text)
{
    text.value=text.value.replace(/[^\.\d]/g,'');
    if(text.value.split('.').length>2)
    {
        text.value=text.value.split('.')[0]+'.'+text.value.split('.')[1];
    }
    else if(text.value.split('.').length==2)
    {
        text.value=text.value.split('.')[0] + '.'+text.value.split('.')[1].substr(0,2);
    }
}
  <asp:TextBox ID="txtTotalPriceTo" runat="server" CssClass="text-line" onKeyUp="CheckTotalPrice(this)"></asp:TextBox>

5 清除表單裡所有TextBox裡的值(該表單裡有其它元素)
<script language="C#" runat="server">
protected void ClearText(Object sender,EventArgs e)
{
 ClearTextBox(this);
}
protected void ClearTextBox(Control c)
{
 if(c is TextBox)
 {
  ((TextBox)c).Text="";
 }
 foreach(Control cc in c.Controls)
 {
  ClearTextBox(cc);
 }
}
</script>
<asp:Button ID="btn" runat="server" Width="86px" CssClass="bttn" Text="重新填寫" OnClick="ClearText" />

6 連接配接列印機,列印功能:執行個體  固定資産系統,asset/AssetBillQuery.aspx
7 gridview 裡,模闆列裡添加按鈕,按鈕出發背景事件的方法:
 前台:按鈕添加屬性 CommandName="DeleteBill",值自己随意填寫。 
<asp:GridView ID="gvList" runat="server" AutoGenerateColumns="False"OnRowCommand="gvList_RowCommand">  
   <asp:TemplateField HeaderText="永久删除">
      <ItemTemplate>
           <asp:ImageButton ID="ImageButton1" runat="server" CommandName="DeleteBill" ImageUrl="~/images/system/delete.gif" CommandArgument='<%#DataBinder.Eval(Container.DataItem,"batchNO") %>' OnClientClick="javascript:return confirm('确認要删除固定資産賬單資訊嗎?删除後将連同資産明細一并徹底删除');" />
       </ItemTemplate>                        
  </asp:TemplateField>
</asp:GridView>
背景:
  protected void gvList_RowCommand(object sender, GridViewCommandEventArgs e)
   {
      switch (e.CommandName)
       {
           case "DeleteBill":
               this.DeleteBill(e.CommandArgument.ToString());
               break;
           default:
                break;
      }
 }

8 gridview 裡,模闆列裡添加按鈕,進行增删改操作的方法,可以用7的方法,也可以這樣:
 <asp:GridView ID="gvList" runat="server"  AutoGenerateColumns="False" OnRowEditing="gvList_RowEditing" OnRowDeleting="gvList_RowDeleting" OnRowUpdating="gvList_RowUpdating"  OnRowCancelingEdit="gvList_RowCancelingEdit">
   <asp:TemplateField HeaderText="導出賬單">
                <ItemTemplate>
   <asp:ImageButton ID="ibtnPrint" runat="server" CommandName="Cancel" ImageUrl="~/images/system/export.gif" />
                </ItemTemplate>
               </asp:TemplateField>
              <asp:TemplateField HeaderText="賬單明細">
                <ItemTemplate>
                         <asp:ImageButton ID="ibtnAsset" runat="server" CommandName="Delete" ImageUrl="~/images/system/export.gif" />
                </ItemTemplate>

              </asp:TemplateField>
              <asp:TemplateField HeaderText="列印标簽">
                   <ItemTemplate>
                          <asp:ImageButton ID="ibtnPrintLable" runat="server" CommandName="Update" ImageUrl="~/images/system/BtnPrint.gif" />
                    </ItemTemplate>
               </asp:TemplateField>
              <asp:TemplateField HeaderText=" 修 改 ">
                    <ItemTemplate>
                          <asp:ImageButton ID="ibtEdit" runat="server" CommandName="Edit" ImageUrl="~/images/system/edit.gif" />
                    </ItemTemplate>
                </asp:TemplateField>
</asp:GridView >
  protected void gvList_RowEditing(object sender, GridViewEditEventArgs e)
        {
            AssetQueryBO bo = new AssetQueryBO();
            AssetRegisterBill bill = bo.GetRegisterBill(this.gvList.Rows[e.NewEditIndex].Cells[0].Text);

        }
        protected void gvList_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            OpenWebForm("./BillAssetList.aspx?BATCHNO=" + this.gvList.Rows[e.RowIndex].Cells[0].Text);
        }

        protected void gvList_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {

        }
        protected void gvList_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            Response.Redirect("./AssetsBillExport.aspx?billNO=" + this.gvList.Rows[e.RowIndex].Cells[0].Text);
        }
10 彈出模态對話框,頁面上有回傳操作,操作完後點選關閉按鈕,發現關閉不了,解決方法為:
在<head></head>中加入<base targe="_self"/>      

作者:沐雪

​​