Because the project must be created using Ajax, datalist remains in the project,
I have never known how to implement datalist as Ajax,
So I searched the internet, but I did not find it again.
Later, I used datalist and page separation in a message board that I had previously done. This idea reminds me to implement Ajax interaction by outputting the datalist control in HTML.
Code
Protected Override Void Render (htmltextwriter writer)
{
String SQL = " Select count (*) from DBO. tb_message where employeeid = " + Loginid. tostring ();
Int I _recordcount = Int . Parse (dataaccess. getsingle (SQL, Null ). Tostring ());
If(I _recordcount> 0)
{
Writer. Write (sp. tostring ());
}
This. DB. rendercontrol (writer );
}
CodeThis method can only be used as a reference but cannot be used directly. However, this idea is to rewrite the render method.
Code
VaR S_gridview_currenpage = ' 0 ' ;
VaR XMLHTTP;
VaR Xmlhttpget;
Function Getxmlhttpobject (){
VaR Xmlhttpnew = Null ;
Try {
Xmlhttpnew = New XMLHttpRequest ();
}
Catch (E ){
Try {
Xmlhttpnew = New Activexobject ( " Msxml2.xmlhttp " );
}
Catch (E ){
Xmlhttpnew = New Activexobject ( " Microsoft. XMLHTTP " );
}
}
Return Xmlhttpnew;
}
Function Guestbook (){
Xmlhttpget = Getxmlhttpobject ();
If (Xmlhttpget = Null ){
Alert ( " Sorry, your browser does not support Ajax !; -) " );
Return ;
}
VaR URL = ' Contactlist. aspx ' ;
URL = URL + " ? SID = " + Math. Random ();
URL = URL + " & Page = " + S_gridview_currenpage;
Xmlhttpget. onreadystatechange = Bookgetok;
Xmlhttpget. Open ( " Get " , URL, True );
Xmlhttpget. Send ( Null );
}
Function Bookgetok (){
If (Xmlhttpget. readystate = 4 ){
VaR Gustbookdiv = Document. getelementbyid ( " Listdiv " );
Gustbookdiv. innerhtml = Xmlhttpget. responsetext;
}
}
I just found that there are also corresponding server controls and JS interactions on the Internet for your reference and mutual learning.