:: Home     :: MS Dynamics CRM     :: .Net 1.1     :: .Net 2.0     :: Sharepoint Portal     :: Ajax

  login:        
  passwords:  
 

Asp.Net Interview Questions
Asp.Net 2.0/3.5 Sample Interview Questions and Answers. Interview Tips for a successful job Interview


 

Code Walkthroughs

Datagrid Formatting the Data
We are able to format the content of the datagrid cell by one of two simple methods, dependant upon whether the column is a bound column or whether it is a template column. In our example we shall format the column to have to digits after the decimal point , followed by a...

Datagrid Highlight a Row With Click Through
It is relatively easy to add alternating colours to the rows in your datagrid. However, when we move the mouse over the rows we may want to highlight this row, and possibly to add the option of a click through based on the row selected...

Add a Delete Button to a Datagrid
To add a delete button to a datagrid follows a similar process to adding an edit button. In the datagrid header...

Add an Edit Button to a Datagrid
The datagrid has a predefined editColumn for handling the editing of a datagrid. Adding this simple column definition to a datagrid adds a powerful feature. When a row is not in edit mode the column item shows the word...

Making a Datagrid Row Editable
Two of the most popular methods of editing a datagrid in asp.net are to either select the row and take the user off to a different presentation of the data, or to change the formatting of the row presented in the database with appropriate edit text boxes, checkboxes and...

Adding Tooltips to Datagrid Rows
Adding tooltips to datagrid rows is easy, assuming that you have already created the code for adding row highlighting. In this article I shall assume that you have already read the article entitled Datagrid Highlight a Row With Click Through...

Binding a Datagrid to an Access Database
This list covers the full lifecycle of a content management system, from initially creating the content, through to delivering it to end users...

Adding Data to a DropDownList
The aim of this article is to answer the question 'How do I add items to a DropDownList?' Initially as part of the declaration for the DropDownList we can also define a number of items, much in the same way as in classic ASP...

Getting Current Date Time
In classic ASP we had now() which would return the current date and time. For asp.net this no longer exists. So what should we use...

Test if File Exists
Sometimes, in order to reduce our chance of error, when working with the filesystem in ASP.NET, we need to determine wether a file exists before performing an action on it. The following short piece of code will enable us to test whether a file exists...

Using Javascript with ASP.NET Form Elements
Adding simple pieces of Javascript to an Asp.net page can be acheived by adding to the attributes of the particular imagebutton or linkbutton. if its normal ASP.Net Button then you can...

Regular Expressions
In the table below we list the characters used in .Net regular expressions, together with their meaning, But first...

Authentication in Asp.net
Forms authentication in ASP.Net is far more easier and safe than Asp 3. It is possible to place a web.config file in any directory of a web site.Therefore, we are able to make most of a web site public, whilst providing authentication on, say, one directory...

Discussion Forums

General ASP.NET

.Net Programming

cSharp Home

Sql Server Home

Javascript / Client Side Development

IT Jobs

Ajax Programming

Ruby on Rails Development

Perl Programming

C Programming Language

C++ Programming

Python Programming Language

Laptop Suggestions?

TCL Scripting

Fortran Programming

Scheme Programming

12. XML

FAQ Home
   12.1 How to write the data from database into an XML file?
   12.2 How to read data from an XML file and display it in a DataGrid?
   12.3 How to read data from the XML file using FileStream and display it in a DataGrid?
   12.4 How to save an xml-string into an Xml document?
   12.5 How to use the <asp:xml> tag?
   12.6 How to display the Attribute values in an XML Document in a DataGrid?



12.1 How to write the data from database into an XML file?


VB.NET


'Fill the DataSet
ds.WriteXml(Server.MapPath ("products.xml" ) )


C#


//Fill the DataSet
ds.WriteXml(Server.MapPath ("products.xml" ) );


Note : Make sure you have write and modify rights.


12.2 How to read data from an XML file and display it in a DataGrid?


VB.NET


dim ds as new DataSet()
ds.ReadXml (Server.MapPath ("products.xml"))
DataGrid1.DataSource =ds
DataGrid1.DataBind()


C#


DataSet ds= new DataSet ();
ds.ReadXml (Server.MapPath ("products.xml"));
DataGrid1.DataSource =ds;
DataGrid1.DataBind();



12.3 How to read data from the XML file using FileStream and display it in a DataGrid?


Use namespace System.IO
VB.NET


dim ds as new DataSet()
dim fs as FileStream = new FileStream (Server.MapPath ("products.xml"),FileMode.Open , FileAccess.Read )
ds.ReadXml (fs)
DataGrid1.DataSource = ds
DataGrid1.DataBind ()


C#


DataSet ds= new DataSet ();
FileStream fs = new FileStream (Server.MapPath ("products.xml"),FileMode.Open , FileAccess.Read );
ds.ReadXml (fs);
DataGrid1.DataSource = ds;
DataGrid1.DataBind ();



12.4 How to save an xml-string into an Xml document?


VB.NET


Dim xmlText As String = "<?xml version=""1.0""?> Node1 Node2 "
Dim xmlDoc As New XmlDocument
xmlDoc.LoadXml(xmlText)
Dim writer As XmlTextWriter = New XmlTextWriter(Server.MapPath("data.xml"), Nothing)
writer.Formatting = Formatting.Indented
xmlDoc.Save(writer)


C#


string xmlText = "<?xml version=\"1.0\"?> Node1 Node2 ";
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlText);
XmlTextWriter writer = new XmlTextWriter(Server.MapPath("data.xml"),null);
writer.Formatting = Formatting.Indented;
xmlDoc.Save(writer);



12.5 How to use the <asp:xml> tag?



<asp:Xml id="Xml1" DocumentSource="products.xml" runat="server"></asp:Xml>



12.6 How to display the Attribute values in an XML Document in a DataGrid?


products.xml


<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<Product>
<ProductID pcode="P2">2</ProductID>
<ProductName>Chang</ProductName>
<SupplierID>1</SupplierID>
<CategoryID>1</CategoryID>
<QuantityPerUnit>24 - 12 oz bottles</QuantityPerUnit>
</Product>
<Product>
<ProductID pcode="P4">3</ProductID>
<ProductName>Aniseed Syrup</ProductName>
<SupplierID>1</SupplierID>
<CategoryID>2</CategoryID>
<QuantityPerUnit>12 - 550 ml bottles</QuantityPerUnit>
</Product>
</NewDataSet>



Use Namespace System.Xml
VB.NET


<asp:DataGrid id="DataGrid1" AutoGenerateColumns="False" runat="server">
<Columns>
     <asp:TemplateColumn HeaderText="ProductCode">
     <ItemTemplate>
          <%#CType(Container.DataItem, System.Xml.XmlNode).Attributes("pcode").value%>
     </ItemTemplate>
     </asp:TemplateColumn>
</Columns>
</asp:DataGrid>



dim xmldoc as XmlDocument = new XmlDocument()
xmldoc.Load(Server.MapPath("products.xml"))
dim xmlnodes as XmlNodeList = xmldoc.SelectNodes("NewDataSet/Product/ProductID")
DataGrid1.DataSource = xmlnodes
DataGrid1.DataBind ()


C#


<asp:DataGrid id="DataGrid1" AutoGenerateColumns="False" runat="server">
<Columns>
     <asp:TemplateColumn HeaderText ="ProductCode">
     <ItemTemplate>
          <%# ((System.Xml.XmlNode)Container.DataItem).Attributes["pcode"].Value %>
     </ItemTemplate>
     </asp:TemplateColumn>
</Columns>
</asp:DataGrid>



XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(Server.MapPath("products.xml"));
XmlNodeList xmlnodes = xmldoc.SelectNodes("NewDataSet/Product/ProductID");
DataGrid1.DataSource = xmlnodes;
DataGrid1.DataBind ();
 
Copyright 2005-2015, Megasolutions Ltd  |   Privacy Policy