A ajax.net instance of a query

Source: Internet
Author: User
Tags eol tostring

Because the project can only use. NET 1.1, Atlas is not used, can only play ajaxprofession.net, the following is a case of inquiry. Put a DataGrid1 on the page, all the results are placed in the client side of JS in the SQL sentence to the server side of the method, carry out a search, and can control whether the two-click line to open a new inquiry. Can DataGrid1 the contents of the loading to Excel and simulate Gmail's Ajax

Using System;
Using System.Collections;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Web;
Using System.Web.SessionState;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.HtmlControls;
Using System.Data.SqlClient;
Using System.IO;
Namespace EOL
{
/**////<summary>
A summary description of the index.
</summary>
public class Index:System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected Webcontrollibrary.inputcalendar StartTime;
protected Webcontrollibrary.inputcalendar Endtime;
protected Webcontrollibrary.inputcalendar pstarttime;
protected Webcontrollibrary.inputcalendar pendtime;
Protected System.Data.SqlClient.SqlConnection conn=new SqlConnection ();
protected System.Web.UI.WebControls.TextBox eformsn;
protected System.Web.UI.WebControls.Label Label1;
Protected System.Web.UI.WebControls.DataGrid datagrid1=new DataGrid ();
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.HtmlControls.HtmlInputText Applicant;
public string Toexcel;

private void Page_Load (object sender, System.EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax (typeof (Eol.index));
}

Public DataSet DB (string dataname, String sqlCmd)
{
String connstr= "server=172.16.0.120;uid=msikdb;pwd=dbmsik;database=" +dataname;
CONN.CONNECTIONSTRING=CONNSTR;
Try
{
Conn.Open ();
}
catch (Exception ex)
{
Conn.close ();
Response.Write (ex. message);
}
SqlCommand cmd=new SqlCommand (SQLCMD, Conn);
SqlDataAdapter Da=new SqlDataAdapter ();
Da. Selectcommand=cmd;
DataSet ds = new DataSet ();
Da. Fill (DS);
Conn.close ();
return DS;
}

Web Form design tool generated code #region Web Form design tool generated code
Override protected void OnInit (EventArgs e)
{
//
CodeGen: This is the call required for the ASP.net Web Form design tool.
//
InitializeComponent ();
Base. OnInit (e);
}

/**////<summary>
This is the necessary way to support the design tool-please do not use the Code editor to modify
The content of this method.
</summary>
private void InitializeComponent ()
{
This. Conn = new System.Data.SqlClient.SqlConnection ();
This. Button2.click + = new System.EventHandler (this. button2_click);
This. datagrid1.itemcreated + = new System.Web.UI.WebControls.DataGridItemEventHandler (This.getpageindexstyle);
This. Load + = new System.EventHandler (this. Page_Load);

}
#endregion

private void Getpageindexstyle (object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{

if (E.item.itemtype = = Listitemtype.pager)
{
E.item.cells[0]. Text= "Total Row:" +this. DataGrid1.Items.Count.ToString ();
}
}

[Ajaxpro.ajaxmethod]
public string Ajaxdata (string sSQL, bool clientevent)
{
if (clientevent)
{
Datagrid1.itemdatabound+=new Datagriditemeventhandler (Datagrid1_itemdatabound);
}
// datagrid1.allowpaging=true;
 DataGrid1.PagerStyle.Position=PagerPosition.Top;
// datagrid1.pagerstyle.mode=pagermode.numericpages;
// datagrid1.itemcreated+=new Datagriditemeventhandler (Getpageindexstyle);
Datagrid1.datasource=db ("Query", sSQL);
Datagrid1.headerstyle.backcolor=system.drawing.color.blue;
Datagrid1.width=unit.percentage (100);
Datagrid1.headerstyle.forecolor=system.drawing.color.white;
Datagrid1.databind ();

System.Text.StringBuilder sb=new System.Text.StringBuilder ();
System.IO.StringWriter sw=new System.IO.StringWriter (SB);
System.Web.UI.HtmlTextWriter htw=new HtmlTextWriter (SW);
This. Datagrid1.rendercontrol (HTW);
String S=SB. ToString (). Replace ("12:00:00", "");
This.toexcel=s;
session["Txtexcel"]=s;
return s;
}

public void Settoexcel ()
{
This line is very important, the attachment parameters are downloaded as an attachment, you can change the online to open
Filename=fileflow.xls Specifies the name of the output file, noting that its extension name matches the specified file type, which can be:. doc. xls. txt. htm
Response.appendheader ("Content-disposition", "Attachment;filename=eol_" +eformsn. text+ ". xls");
Response.contentencoding=system.text.encoding.getencoding ("Big5");
RESPONSE.CONTENTTYPE Specifies that file types can be Application/ms-excel,application/ms-word, application/ms-txt,application/ Ms-html or other browsers can directly support the document file
Response.ContentType = "Application/ms-excel";

Response.Write (This.toexcel);
Response.Write (session["Txtexcel"]);

Related Article

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.