use Function WriteXml save data to xml fileprivate void WriteXmlToFile(DataSet thisDataSet) {
if (thisDataSet == null) { return; }
// Create a file name to write to.
string filename = "myXmlDoc.xml";
// Create the FileStream to write with.
System.IO.FileStream myFileStream = new System.IO.FileStream
(filename, System.IO.FileMode.Create);
// Create an XmlTextWriter with the fileStream.
System.Xml.XmlTextWriter myXmlWriter =
new System.Xml.XmlTextWriter(myFileStream, System.Text.Encoding.Unicode);
// Write to the file with the WriteXml method.
thisDataSet.WriteXml(myXmlWriter);
myXmlWriter.Close();
}
if (thisDataSet == null) { return; }
// Create a file name to write to.
string filename = "myXmlDoc.xml";
// Create the FileStream to write with.
System.IO.FileStream myFileStream = new System.IO.FileStream
(filename, System.IO.FileMode.Create);
// Create an XmlTextWriter with the fileStream.
System.Xml.XmlTextWriter myXmlWriter =
new System.Xml.XmlTextWriter(myFileStream, System.Text.Encoding.Unicode);
// Write to the file with the WriteXml method.
thisDataSet.WriteXml(myXmlWriter);
myXmlWriter.Close();
}
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Color" %><html>
<script runat="server">
dim MyConnection as OleDbConnection
dim cmdSelect as OleDbCommand
dim dtrReader as OleDbDataReader
Sub Page_Load(sender As Object, e As EventArgs)
MyConnection = New OleDbConnection( "Provider=Microsoft.Jet.OLEDB.4.0; Data Source =" + Server.MapPath(".")+"/datagrid.mdb")
If Not IsPostBack Then
BindGrid()
End If
End Sub Sub BindGrid()
Dim MyCommand As OleDbDataAdapter = new OleDbDataAdapter("select * from [news]", MyConnection)
Dim DS As DataSet = new DataSet()
MyCommand.Fill(DS,"min")
MyDataGrid.DataSource =DS.Tables("min").DefaultView
MyDataGrid.DataBind()
End SubSub Mydatagrid_PageIndexChanged(s as object,e as DataGridPageChangedEventargs)
MyDataGrid.CurrentPageIndex=e.newPageIndex
BindGrid()
End Sub Sub Button1_Click(sender As Object, e As System.EventArgs)
'-------------------
MyDataGrid.AllowPaging = "false"
BindGrid()
'-------------------
MyDataGrid.SelectedItemStyle.BackColor=Color.white
MyDataGrid.AlternatingItemStyle.BackColor=Color.white
MyDataGrid.ItemStyle.BackColor=Color.white
MyDataGrid.HeaderStyle.BackColor=Color.white
MyDataGrid.HeaderStyle.ForeColor=Color.red
Response.ContentType = "application/vnd.ms-excel"
Response.Charset = ""
Me.EnableViewState = False
Dim tw As New System.IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
MyDataGrid.RenderControl(hw)
Response.Write(tw.ToString())
Response.End()
'-------------------
MyDataGrid.AllowPaging = "true"
BindGrid()
End Sub
</script>
<body>
<form runat="server">
DataGrid Custom Paging Example<BR>
<asp:Button id="button1" onclick="Button1_Click" text="Write To Excle File" runat="server"/>
<BR>
<asp:datagrid id="MyDataGrid"
runat="server"
CellPadding="4"
BackColor="White"
BorderColor="#330033"
BorderWidth="1px"
BorderStyle="None"
Font-Size="9pt"
Font-Names="§ºÊ^"
AllowPaging="true"
pageSize="2"
OnPageIndexChanged="Mydatagrid_PageIndexChanged" >
<PagerStyle Mode="NumericPages"
Font-Bold="true"
BackColor="#F2F2F2"
HorizontalAlign="right">
</PagerStyle>
<SelectedItemStyle BackColor="#FFCC66"></SelectedItemStyle>
<AlternatingItemStyle BackColor="#FFCC99"></AlternatingItemStyle>
<ItemStyle BackColor="White"></ItemStyle>
<HeaderStyle Font-Bold="True" HorizontalAlign="Center" ForeColor="#330033" BorderColor="Black" BackColor="#FF9900"></HeaderStyle>
</asp:datagrid>
</form>
</body>
</html>