Hi :)
I tried to implement a pivot for radgrid ... And I have some problems ....
I'd like my line's name are not the field of my database (for example, now I have "db_name" and I want "Name").
I'd like to make a header for all the grid with "User Informations"
This is my code :
ASP :
C#
Thanks for the help :)
I tried to implement a pivot for radgrid ... And I have some problems ....
I'd like my line's name are not the field of my database (for example, now I have "db_name" and I want "Name").
I'd like to make a header for all the grid with "User Informations"
This is my code :
ASP :
<telerik:RadGrid runat="server" ID="view" ShowStatusBar="true" AutoGenerateColumns="false" Visible="false"> <ClientSettings> <Selecting AllowRowSelect="True"/> </ClientSettings> <GroupingSettings CaseSensitive="false" /> <MasterTableView ShowHeadersWhenNoRecords="true" DataKeyNames="Id" ClientDataKeyNames="Id"> <Columns> <telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="User Name" AutoPostBackOnFilter="true" Visible="true"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Phone" UniqueName="Phone" HeaderText="User Phone" AutoPostBackOnFilter="true" Visible="true"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Email" UniqueName="Email" HeaderText="User Email" AutoPostBackOnFilter="true" Visible="true"> </telerik:GridBoundColumn> </Columns> </MasterTableView> </telerik:RadGrid><br /><telerik:RadGrid runat="server" ID="view2" ShowStatusBar="true" Visible="true"> <ClientSettings> <Selecting AllowRowSelect="True"/> </ClientSettings> <GroupingSettings CaseSensitive="false" /> <MasterTableView ShowHeader="false" > </MasterTableView> </telerik:RadGrid>C#
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { BindGridView(); } } 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; } private void BindGridView() { String str = Request.RawUrl; if (!IsPostBack) { if (str.Contains("?a")) { Int32 url_id = Convert.ToInt32(Request.Params["a"]); user_id = url_id; DataTable dt = new DataTable(); SqlConnection cn = new SqlConnection(""); SqlCommand cmd = new SqlCommand("user_data", cn); cmd.Parameters.Add(new SqlParameter("@id", SqlDbType.Int)); cmd.Parameters["@id"].Value = url_id; cmd.CommandType = CommandType.StoredProcedure; SqlDataAdapter sqlDa = new SqlDataAdapter(cmd); sqlDa.Fill(dt); try { cn.Open(); if (dt.Rows.Count > 0) { //Bind the First GridView with the original data from the DataTable view.DataSource = dt; view.DataBind(); //Pivot the Original data from the DataTable by calling the //method PivotTable and pass the dt as the parameter DataTable pivotedTable = PivotTable(dt); view2.DataSource = pivotedTable; view2.DataBind(); } } catch (SqlException ex) { //... } finally { if (cn.State != ConnectionState.Closed) { cn.Close(); cmd.Parameters.Clear(); } } } } }Thanks for the help :)
