hey frds I want to fetch data from a column and display it as a row that's called pvorting !!!! may u pls help me out?


private DataTable PivotTable(DataTable origTable)
{
DataTable newTable = new DataTable();
DataRow dr = null;

//Add Columns to new Table
------------------------------
for (int i = 0; i <= origTable.Rows.Count; i++)
{
newTable.Columns.Add(new DataColumn(origTable.Columns[i].ColumnName, typeof(String)));
}
//Execute the Pivot Method
for (int cols = 0; cols < origTable.Columns.Count; cols++)
{
dr = newTable.NewRow();
for (int rows = 0; rows < origTable.Rows.Count; rows++)
{
if (rows < origTable.Columns.Count)
{
dr[0] = origTable.Columns[cols].ColumnName;
// Add the Column Name in the first Column
dr[rows + 1] = origTable.Rows[rows][cols];
}
}
newTable.Rows.Add(dr); //add the DataRow to the new Table rows collection
}
return newTable;
--------------------------------------------------------------------------
This method is used to fill grid view
------------------------------------------------
private void BindGridView()
{
try
{

string sqlStatement = "SELECT Top(5)* FROM Customers";
SqlCommand sqlCmd = new SqlCommand(sqlStatement, connection);
SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);
sqlDa.Fill(dt);
if (dt.Rows.Count > 0)
{
//Bind the First GridView with the original data from the DataTable
GridView1.DataSource = dt;
GridView1.DataBind();

//Pivot the Original data from the DataTable by calling the
//method PivotTable and pass the dt as the parameter
DataTable pivotedTable = PivotTable(dt);
GridView2.DataSource = pivotedTable;
GridView2.DataBind();

}
}
catch (Exception ex)
{
lblMsg.Text="Error:"+ex.Message.ToString();
}

-------------------------------------------------------------------
You can call bindgrid method where u want.just i wnt to call in page load event
--------------------------
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindGridView();
}
}

Comments

  1. While using @font-face I am facing a problem that is when I am going to convert the font from hindi to english, this is working fine in each and every browser for each datacontrol. but for dropdownlist this is not good in IE8 but fine in other browsers.I am using it in the following way:

    1) in aap_theme folder

    @font-face
    {
    font-family: "MyCustomFont";
    src: url('../font/MFDEV010.ttf') format('truetype')
    }
    @font-face
    {
    font-family: "MyFont";
    src: url('../font/MFDEV010.eot?iefix') format('eot')

    }

    .HindiSkin
    {
    font-family: "MyFont", "MyCustomFont";
    font-size:17px;

    }
    .EngSkin
    {
    font-family: Arial Unicode MS ;
    font-size:15px;

    }

    .InputSelect
    {
    /*border: 1px solid #b0b0b0;*/
    font-family: verdana;
    font-size: 12px;
    color: #090908;
    font-weight: normal;
    width: 190px;
    padding:1px;
    height:25px;
    }

    .InputSelectHindi
    {
    /*border: 1px solid #b0b0b0;*/
    font-family: "MyCustomFont","MyFont";
    font-size: 18px;
    color: #090908;
    font-weight: normal;
    width: 190px;
    padding:1px;
    height:30px;
    }

    2) in the skin file i have include:





    3) on the page

    on the page i have add the reference of the theme here like this:
    StylesheetTheme="EnglishFontSkin"



    Note: this is working fine ever![enter image description here][1]ywhere but not IE8, please give the solution for it.
    thnx in advance

    ReplyDelete

Post a Comment

Popular posts from this blog

ASP.NET Session States in SQL Server Mode

How to find client's MAC Address in Asp.Net and C#.net

Use XML Data For Save in Database