Get the insert Record ID, move the cursor to the row of the DataGrid to change the color)

Source: Internet
Author: User
From a drop of water
Http://www.cnblogs.com/yidishui
Obtain the ID of the inserted record Void Page_load ( Object Sender, system. eventargs E)
{
// Database connection string
String Connstr = System. configuration. configurationsettings. deleettings [ " Connectionsqlserver " ];
// Create an insert SQL statement and call the @ identity function to return the id value
String Insert_query =   " Insert into categories (categoryname, description) values ('it', 'internet '); "  
+   " Select @ identity as 'identified '; " ;
 
// Perform database operations
Sqlcommand mycommand =   New Sqlcommand (insert_query, New Sqlconnection (connstr ));
Mycommand. Connection. open ();
Mylabel. Text = Mycommand. executescalar (). tostring ();
Mycommand. Connection. Close ();
}  

Move the cursor to the row of the DataGrid to change the color. Private   Void Datagrid1_itemdatabound ( Object Sender, system. Web. UI. webcontrols. datagriditemeventargs E)
{
If (E. Item. itemtype = Listitemtype. Item | E. Item. itemtype = Listitemtype. alternatingitem)
{
// Add Custom Attributes. When the mouse moves over, set the background color of the row to "6699ff" and save the original background color.
E. Item. Attributes. Add ( " Onmouseover " , " Stylecolor = This. style. backgroundcolor; this. style. backgroundcolor = '# 6699ff' " );
// Add custom properties to restore the background color of the row when the mouse moves
E. Item. Attributes. Add ( " Onmouseout " , " This. style. backgroundcolor = stylecolor " );
 
}
}

Blog site
Http://xiexiaokui.cnblogs.com

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.