This article describes the method of C# programming to implement QQ interface. Share it for your reference, as follows:
step:
1. Create a new page, if it is called VerticalMenu
2. Copy the html code to the html code area
3. Copy the LoadTopMenu method to the cs code area
4. Just run
Code
<STYLE type="text/css"> A:link {}{ COLOR: #000000; FONT-SIZE: 12px; TEXT-DECORATION: none} A:visited {}{ COLOR: #000000; FONT-SIZE: 12px; TEXT-DECORATION: none} A:hover {}{ COLOR: #006CD9; FONT-SIZE: 12px; TEXT-DECORATION: none} BODY {}{ FONT-SIZE: 12px;} TD {}{ FONT-SIZE: 12px; line-height: 150%} </STYLE> <script language="JavaScript"> <!-- function showitem(id,name) { //Open the pop-up page //return ("<span><a href='"+id+"' target=_blank>"+name+"</a></span><br>") //Open in the frame return ("<span><a href='#' onclick=/"url('"+id+"');/">"+name+"</a></span><br>") } function url(id) { var source = ('fMain'); =id; } function switchoutlookBar(number) { var i = ; =number; var id1,id2,id1b,id2b if (number!=i && outlooksmoothstat==0){ if (number!=-1) { if (i==-1){ id2="blankdiv"; id2b="blankdiv"; } else{ id2="outlookdiv"+i; id2b="outlookdivin"+i; ("outlooktitle"+i).="1px none navy"; ("outlooktitle"+i).=; ("outlooktitle"+i).="#ffffff"; ("outlooktitle"+i).="center"; } id1="outlookdiv"+number id1b="outlookdivin"+number ("outlooktitle"+number).="1px none white"; ("outlooktitle"+number).=; //title ("outlooktitle"+number).="#ffffff"; ("outlooktitle"+number).="center"; smoothout(id1,id2,id1b,id2b,0); } else { ("blankdiv").=""; ("blankdiv").="100%"; ("outlookdiv"+i).="none"; ("outlookdiv"+i).="0%"; ("outlooktitle"+i).="1px none navy"; ("outlooktitle"+i).=; ("outlooktitle"+i).="#ffffff"; ("outlooktitle"+i).="center"; } } } function smoothout(id1,id2,id1b,id2b,stat) { if(stat==0){ tempinnertext1=(id1b).innerHTML; tempinnertext2=(id2b).innerHTML; (id1b).innerHTML=""; (id2b).innerHTML=""; outlooksmoothstat=1; (id1b).="hidden"; (id2b).="hidden"; (id1).="0%"; (id1).=""; setTimeout("smoothout('"+id1+"','"+id2+"','"+id1b+"','"+id2b+"',"++")",); } else { stat+=; if (stat>100) stat=100; (id1).=stat+"%"; (id2).=(100-stat)+"%"; if (stat<100) setTimeout("smoothout('"+id1+"','"+id2+"','"+id1b+"','"+id2b+"',"+stat+")",); else { (id1b).innerHTML=tempinnertext1; (id2b).innerHTML=tempinnertext2; outlooksmoothstat=0; (id1b).="auto"; (id2).="none"; } } } function getOutLine() { outline="<table "++">"; for (i=0;i<();i++) { outline+="<tr><td name=outlooktitle"+i+" id=outlooktitle"+i+" "; if (i!=) outline+=" nowrap align=center style='cursor:hand;background-color:"++";color:#ffffff;height:20;border:1 none navy' "; else outline+=" nowrap align=center style='cursor:hand;background-color:"++";color:white;height:20;border:1 none white' "; outline+=[i].otherclass outline+=" onclick='switchoutlookBar("+i+")'><span class=smallFont>"; outline+=[i].title+"</span></td></tr>"; outline+="<tr><td name=outlookdiv"+i+" valign=top align=center id=outlookdiv"+i+" style='width:100%" if (i!=) outline+=";display:none;height:0%;"; else outline+=";display:;height:100%;"; outline+="'><div name=outlookdivin"+i+" id=outlookdivin"+i+" style='overflow:auto;width:100%;height:100%'>"; for (j=0;j<[i].length;j++) outline+=showitem([i][j].key,[i][j].title); outline+="</div></td></tr>" } outline+="</table>" return outline } function show() { var outline; outline="<div id=outLookBarDiv name=outLookBarDiv style='width=100%;height:100%'>" outline+=(); outline+="</div>" (outline); } function theitem(intitle,instate,inkey) { =instate; =" nowrap "; =inkey; =intitle; } function addtitle(intitle) { []=new Array(); []=new theitem(intitle,1,0); return(-1); } function additem(intitle,parentid,inkey) { if (parentid>=0 && parentid<=) { [parentid][[parentid].length]=new theitem(intitle,2,inkey); [parentid][[parentid].length-1].otherclass=" nowrap align=left style='height:5' "; return([parentid].length-1); } else additem=-1; } function outlook() { =new Array(); =new Array(); ="style='height:100%;width:100%;overflow:auto' align=center";//The alignment method can be set here ="border=0 cellspacing='0' cellpadding='0' style='height:100%;width:100%'valign=middle align=center "; =addtitle; =additem; =-1; =show; =getOutLine; =; =outreflesh; =50; =10; = "#336699" } function outreflesh() { ("outLookBarDiv").innerHTML=(); } function locatefold(foldname) { if (foldname=="") foldname = [0].title for (var i=0;i<;i++) { if(foldname==[i].title) { =i; =i; } } } var outlookbar=new outlook(); var tempinnertext1,tempinnertext2,outlooksmoothstat outlooksmoothstat = 0; <%=LoadVerticalMenu()%>//Create vertical menu from database//--> </script> <table style="WIDTH:150px;HEIGHT: 100%" cellspacing="0" cellpadding="0" align="left" border="0"> <tr> <td bgcolor="#F0F0E5" style="HEIGHT: 100%" valign="top" align="middle" name="outLookBarShow"> <script language="JavaScript"> <!-- locatefold("") () //--> </script> </td> </tr> </table>
Code
public class VerticalMenu : { protected DataRow[] father; protected DataRow[] first; private void Page_Load(object sender, e) { // Simulate QQ menu } public static string ConnectionString= .ConfigurationSettings .AppSettings["ConnectionString"]; GetDataSet#region GetDataSet public static DataSet GetDataSet(string sql) { SqlDataAdapter sda =new SqlDataAdapter(sql,ConnectionString); DataSet ds=new DataSet(); (ds); return ds; } #endregion protected string LoadVerticalMenu() { string sqlFather="select * from PowerSetting"; DataSet dsFather=GetDataSet(sqlFather); father=[0].Select("IsBoot=0","IsBoot"); string menu=""; foreach(DataRow drfather in father) { menu+="var t;"; menu+="t=('"+drfather["Description"]+"');"; first=[0].Select("ParentID='"+Convert.ToInt32(drfather["ParentID"])+"' and IsBoot=1","IsBoot"); foreach(DataRow drfirst in first) { menu+="('"+drfirst["Description"]+"',t,'"+drfirst["Url"]+"');"; } } return menu; } Web Form Designer generated code#region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the Web Form Designer. // InitializeComponent(); (e); } /**//**//**//// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { += new (this.Page_Load); } #endregion }
3. Database scripts
if exists (select * from where id = object_id(N'[dbo].[PowerSetting]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table [dbo].[PowerSetting] GO CREATE TABLE [dbo].[PowerSetting] ( [PowerSettingID] [int] IDENTITY (1, 1) NOT NULL , --id [ParentID] [int] NOT NULL , --Parent nodeid [Description] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL , --Menu Description [Icon] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL , --To display icon [Url] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL , --url [Target] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL , --_self,_blankwait [CreateByID] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL , --Founderid [CreateON] [datetime] NULL , --Creation date [IsEnabled] [bit] NULL , --Is it available [IsBoot] [int] NULL --Is it the root node?;1It's the other, no ) ON [PRIMARY] GO
For more information about C# related content, please check out the topic of this site:C# data structure and algorithm tutorial》、《Tutorial on the usage of common C# controls》、《Introduction to C# object-oriented programming tutorial"and"Summary of thread usage techniques for C# programming》
I hope this article will be helpful to everyone's C# programming.