• 获得插入记录标识号, 鼠标移到DataGrid的行更改颜色(转)


    转自一滴水
    http://www.cnblogs.com/yidishui

    获得插入记录标识号
                void Page_Load(object sender, System.EventArgs e) 
                

                    
    // 数据库连接字符串 
                    string ConnStr = System.Configuration.ConfigurationSettings.AppSettings["ConnectionSqlServer"]; 
                    
    // 创建插入SQL语句及调用@@identity函数返回标识值 
                    string insert_query = "insert into Categories (CategoryName,Description) values ('IT', 'Internet');" 
                            
    + "SELECT @@identity AS 'identity';"
     
                    
    // 执行数据库操作 
                    SqlCommand myCommand = new SqlCommand(insert_query, new SqlConnection(ConnStr)); 
                    myCommand.Connection.Open(); 
                    myLabel.Text 
    = myCommand.ExecuteScalar().ToString(); 
                    myCommand.Connection.Close(); 
                }
     

    鼠标移到DataGrid的行更改颜色
    private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) 
      

            
    if(e.Item.ItemType == ListItemType.Item  || e.Item.ItemType == ListItemType.AlternatingItem) 
           

              
    //添加自定义属性,当鼠标移过来时设置该行的背景色为"6699ff",并保存原背景色 
             e.Item.Attributes.Add("onmouseover","StyleColor=this.style.backgroundColor;this.style.backgroundColor='#6699ff'"); 
             
    //添加自定义属性,当鼠标移走时还原该行的背景色 
        e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=StyleColor"); 
     
       }
      
      }

    blog site
    http://xiexiaokui.cnblogs.com

  • 相关阅读:
    CSS的未来:游戏的变革Flexbox
    2013年第8周一JAVA对象序列化及TODO标签等
    大年初七回杭州
    2013年2月20日星期三
    2013年周六加班杂记
    大家初八但杭州收拾准备开始工作
    大家初六去香山
    2013年第8周四又是低效的一天
    2013年第8周二Delphi中Union结构
    2013年第8周日元宵节
  • 原文地址:https://www.cnblogs.com/xiexiaokui/p/573382.html
Copyright © 2020-2023  润新知