Applying Web To Your Business

Transpose DataTable Contents

This code is useful to transpose the datatable rows and columns.

DataTable dtSource = new DataTable();   
protected void Page_Load(object sender, EventArgs e)   
    // Bind the source datatable from the database   
    dtSource = dataSource();   

public DataTable FlipDataTable(GridView gvNew)   
    DataTable dataTable = new DataTable("dataTable");  
    // create column  
    DataRow newRow;  
    for (int iRow = 0; iRow < dtSource.Columns.Count; iRow++)  
        newRow = dataTable.NewRow();  
        newRow[0] = dtSource.Columns[iRow].ToString();  
        for (int iCol = 1; iCol <= dtSource.Rows.Count; iCol++)  
            newRow[iCol] = dtSource.Rows[iCol - 1][iRow];  

Lets suppose you have a data source in XML like:

        <add key="SomeKey" value="SomeValue">
        <add key="SomeKey" value="SomeValue">

Now you want to edit the key and values with in the xml element collection.

<asp:XmlDataSource ID="configXmlDataSource" XPath="//add" 
    runat="server" DataFile="~/settings.config"/> 

Use the following code in the code-behind

// In this code we are getting the Data Item values 
// of the Rad Editor. On UpdateCommand Event we are getting 
// the values of data row in an instance of hash.   
GridDataItem dataItem = (GridDataItem)e.Item;    
Hashtable ht = new Hashtable();    

// Get the node values as per the selected key name:    
XmlNode AppNode = XmlDataSource1.GetXmlDocument().SelectSingleNode
    ( String.Format("//add[@key='{0}']", key));

// Now assign the new value of the Value attribute of the 
// selected node:  
AppNode.Attributes["value"].Value = ht["value"];  

//Finally we need to update the xml source file:  

Merge Two DataTable Columns

Lets you have two datatables having two same columns. This code is useful to merge the columns. More...

When a table's primary field is to auto increment with a seed and you are deleting the records from the table. Now you need to reset the primary field value to 1. The code given below is useful.


Widget FlickrBar not found.

Forbidden (403)X

About Us

studio NETSOULS is a complete IT services company, offering strategy, design, development and implementation of the total solution for your web and IT initiatives. The solutions we provide, enables businesses to leverage leading edge technology to gain sustainable competitive advantages in today's marketplace.

We specialize in designing, developing and deploying the next generation of IT solutions including e-business solutions Read more...

Month List