DataGrid loading XML data in C #

Source: Internet
Author: User

 protected System.Web.UI.WebControls.DataGrid Dgaddinfo;
  public String xmlfilename = "Zph.xml";
  private void Page_Load (object sender, System.EventArgs e)
  {
   //    datagriddatabind ();
   
   if (! IsPostBack)
   {
    dataload ("ID");
  &NBSP}
  }

   #region
  private void Dataload (string sortstring)
  {
    //string XMLfileName = @ "C:/inetpub/wwwroot/zhaopinhui/zph.xml";
   dataset ds = new DataSet ();
   filestream FS = new FileStream (Server.MapPath (XMLfileName), FileMode.Open);
   ds. READXML (FS);
   if (ds. Tables.count = = 0)
   {
    ds. Tables.add (Makezphtable ());
   }
   trace.warn ("rowcount1=", Convert.ToString (DS). Tables[0]. Rows.Count));

DataView dv =new DataView (ds. Tables[0]);
if (sortstring.length>0)
{
Dv. Sort = sortstring;
}
This.dgAddInfo.DataSource = DV;
This.dgAddInfo.DataBind ();
Fs. Close ();
}
#endregion

#region Create a Job fairs table
Private DataTable makezphtable ()
{
DataTable thetable = new DataTable ("Zph");

DataColumn theColumn1 = new DataColumn ();
Thecolumn1.datatype = System.Type.GetType ("System.Int32");
Thecolumn1.columnname = "ID";
THETABLE.COLUMNS.ADD (THECOLUMN1);

DataColumn theColumn2 = new DataColumn ();
Thecolumn2.datatype = System.Type.GetType ("System.Int32");
Thecolumn2.columnname = "Zphid";
THETABLE.COLUMNS.ADD (THECOLUMN2);

DataColumn theColumn3 = new DataColumn ();
Thecolumn3.datatype = System.Type.GetType ("System.String");
Thecolumn3.columnname = "Title";
THETABLE.COLUMNS.ADD (THECOLUMN3);

DataColumn theColumn4 = new DataColumn ();
Thecolumn4.datatype = System.Type.GetType ("System.String");
Thecolumn4.columnname = "Content";
THETABLE.COLUMNS.ADD (THECOLUMN4);

DataColumn theColumn5 = new DataColumn ();
Thecolumn5.datatype = System.Type.GetType ("System.DateTime");
Thecolumn5.columnname = "Date";
THETABLE.COLUMNS.ADD (THECOLUMN5);

DataColumn theColumn6 = new DataColumn ();
Thecolumn6.datatype = System.Type.GetType ("System.String");
Thecolumn6.columnname = "Time";
THETABLE.COLUMNS.ADD (THECOLUMN6);

DataColumn theColumn7 = new DataColumn ();
Thecolumn7.datatype = System.Type.GetType ("System.String");
Thecolumn7.columnname = "Num";
THETABLE.COLUMNS.ADD (THECOLUMN7);

   datacolumn theColumn8 = new DataColumn ();
   thecolumn8.datatype = System.Type.GetType ("System.String");
   thecolumn8.columnname = "place";
   thetable.columns.add (THECOLUMN8);
   return thetable;
  } 

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.