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"/>

作者:沐雪
文章均系作者原创或翻译,如有错误不妥之处,欢迎各位批评指正。