.net 随笔(4)

来源:互联网 发布:手机淘宝怎么打开闲鱼 编辑:程序博客网 时间:2024/04/30 15:41

19:在JS和C#中用/"输入特殊字符"

就是说在特殊字符前打一个/就可以正常输出了,例如:
如果用单引号解决就是这样:
document.write("<tr><td bgcolor='"+subTableTdBgcolor+"' width='100%' class='link' >");
但我们的确可以使用双引号:
document.write("<tr><td bgcolor=/""+subTableTdBgcolor+"'/"width=/"100%/" class=/"link/" >");

 20:

RowEventArgs类型在vs2003与vs2005有着一些区别
GridViewRowEventArgs在VS2005下为e.row
DataGridRowEventArgs在VS2003为为e.item

2003的DataGrid在OnDataBound中可以捕获生成行的事件,而在
2005的Gridview在OnRowDataBound事件中才可以捕获。

21:单击表格行换颜色,再单击恢复的JS代码:
    </script>
    <script language ="javascript" type ="text/javascript" >
function bgChange(obj){
obj.style.backgroundColor=obj.style.backgroundColor!="#cc99ff" ?"#cc99ff":"";
}
    </script>

调用时:
bgChange(this);

22:最近研究了很多小技术,没时间总结。。。关于VS2005的皮肤设置(skinID),个人认为无法取代CSS的地位,因为只能对控件设置skinID,想必对winform好用一些(因为除了控件没别的)。

后来找了一些文章,发现也可以对CSS进行主题的设置:。(
quit start
http://www.frontfree.net/view/article_873.html

下面是好麻烦的一种方法:

    protected void Page_PreInit(object sender, EventArgs e)
    {
        this.Theme = getTheme;
    }

    private string getTheme
    {
        get
        {
            return  object.Equals(Request.QueryString["t"],null) ? _theme : Request.QueryString["t"].ToString();
        }
    }

推荐用这种:

 protected void Page_PreInit(object sender, System.EventArgs e)
 {
  Page.Theme = Request["ChooseTheme"];
 }
前台:
您可以在此处选择页面主题:
                    <asp:DropDownList ID="ChooseTheme" runat="server" AutoPostBack="True">
                        <asp:ListItem Value="BlueTheme">请选择颜色</asp:ListItem>
                        <asp:ListItem Value="PorpleTheme">紫色</asp:ListItem>
                        <asp:ListItem Value="BlueTheme">蓝色</asp:ListItem>
                    </asp:DropDownList>

23:asp.net随手乱记(20)VS2005可以直接操作SQL数据库

发现vs2005有连接SQL自带的工具,哭哇。不用再另装SQL2000 了

在菜单,工具,中选择“连接到数据库”

选择MicroSoft SQL SERVER

接下来就简单了。。。连上后,表,视图,存储过程,都可以方便的进行操作

存储过程还有语法高亮的显示,555

看来用不着那三百M的SQL客户端工具了。。。嘿嘿,要睡觉了,抓图的事改天再说,嗷嗷的高兴的说。。。

VS2005这种IDE真是强大的没话说。

24,不同控件的整合问题

如果数据分处于两个不同的控件,用户又要求其对应的话,我们可以使用CSS中的层定位。

在一些人眼里,webform是无法做到winform那样的控件定位的,我也一不小心把被这个观点束缚住了。

25,在gridview里,如果要对每行的自定义控件操作时,应该绑定其DataRowBound事件而不是DataBound事件:

    protected void gd_OnRowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType.ToString() == "DataRow")
        {
            e.Row.Attributes.Add("onclick", "location.href='Item_Show.aspx?item=" + e.Row.Cells[1].Text.Trim() + "';");

            try
            {
                DateTime mydate = new DateTime();
                mydate = Convert.ToDateTime(e.Row.Cells[3].Text);
                ((Label)e.Row.FindControl("Label1")).Text = mydate.AddDays(-7).ToShortDateString();
            }
            catch (Exception ee)
            {

            }
        }
    }

查找某行的ID,以前我是用((Label)e.Row.Cell[i].FindControl("Label1")).Text
现在发现用((Label)e.Row.FindControl("Label1")).Text也可以取得,免去了找列的麻烦。



未完

原创粉丝点击