Marcio Nascimento
Top achievements
Rank 1
Marcio Nascimento
asked on 14 Apr 2011, 02:54 AM
Hi There!
I have tried to load a double array into Radgrid without success. Any Ideas ?
Regards,
Marcio Nascimento
I have tried to load a double array into Radgrid without success. Any Ideas ?
protected void Page_Load(object sender, EventArgs e) { double[][] criterios = new double[][] { new double[] {1,5,0.33333333,1}, new double[] {0,1,0.2,0.5}, new double[] {0,0,1,3}, new double[] {0,0,0,1} }; DataTable matrix = new DataTable(); matrix = GetDataTableFromArray(criterios); RadGrid1.DataSource = matrix; } public static DataTable GetDataTableFromArray(object[] array) { DataTable dataTable = new DataTable(); dataTable.LoadDataRow(array, true); return dataTable; }Regards,
Marcio Nascimento
6 Answers, 1 is accepted
0
Hello Marcio,
The LoadDataRow method can be used to load data into single row and not for loading several rows at a time.
You can use this approach instead:
Best wishes,
Vasil
the Telerik team
The LoadDataRow method can be used to load data into single row and not for loading several rows at a time.
You can use this approach instead:
void RadGrid2_NeedDataSource(object sender, GridNeedDataSourceEventArgs e){ double[][] criterios = new double[][] { new double[] {1,5,0.33333333,1}, new double[] {0,1,0.2,0.5}, new double[] {0,0,1,3}, new double[] {0,0,0,1} }; DataTable matrix = new DataTable(); matrix = GetDataTableFromArray(criterios); RadGrid2.DataSource = matrix;}public static DataTable GetDataTableFromArray(double[][] array){ DataTable dataTable = new DataTable(); if (array.Length > 0) { for (int c = 0; c < array[0].Length; c++) { dataTable.Columns.Add(); } } foreach (double[] row in array) { DataRow dataRow = dataTable.NewRow(); for (int i = 0; i < row.Length; i++) dataRow[i] = row[i]; dataTable.Rows.Add(dataRow); } return dataTable;}Best wishes,
Vasil
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Marcio Nascimento
Top achievements
Rank 1
answered on 21 Apr 2011, 06:29 AM
Hi Vasil ! Thanks a Lot !
I was wondering one more thing....
I Checked the "Auto-generate edit column at runtime" option for Radgrid. When I click "Edit", the Radgrid disappears.
It is possible to edit values the way you did in the code and update those values back to criterios double array ?
Regards,
Marcio Nascimento
I was wondering one more thing....
I Checked the "Auto-generate edit column at runtime" option for Radgrid. When I click "Edit", the Radgrid disappears.
It is possible to edit values the way you did in the code and update those values back to criterios double array ?
Regards,
Marcio Nascimento
0
Hi Marcio,
Could you write us the whole code that you use? When I tried to go in edit mode using auto-generated edit column it works as expected.
You can handle UpdateCommand to update the array manually. Similar approach is used in this demo.
Automatic operations can be used only for datasources that are supporting such operations and because of this you should update the array manually as mentioned above. See this help topic for more information about the automatic insert, update and delete.
Greetings,
Vasil
the Telerik team
Could you write us the whole code that you use? When I tried to go in edit mode using auto-generated edit column it works as expected.
You can handle UpdateCommand to update the array manually. Similar approach is used in this demo.
Automatic operations can be used only for datasources that are supporting such operations and because of this you should update the array manually as mentioned above. See this help topic for more information about the automatic insert, update and delete.
Greetings,
Vasil
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Marcio Nascimento
Top achievements
Rank 1
answered on 25 Apr 2011, 10:57 PM
Hi Vasil,
Here is the thing. When I click the button1, I fill my radgrid with data. When I edit a row, the radgrid is still there but I can't update the dataTable back if I change the values. I know that is some basic thing but I couldn't find any example of it.
I appreciate any help from you.
Here is the thing. When I click the button1, I fill my radgrid with data. When I edit a row, the radgrid is still there but I can't update the dataTable back if I change the values. I know that is some basic thing but I couldn't find any example of it.
I appreciate any help from you.
public static DataTable dtTable;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{ dtTable = new DataTable(); dtTable.Columns.Add("Col 1"); dtTable.Columns.Add("Col 2"); dtTable.Columns.Add("Col 3"); dtTable.Rows.Add(1,5,5); dtTable.Rows.Add(2,5,5); dtTable.Rows.Add(3,5,5); RadGrid1.DataSource = dtTable; RadGrid1.DataBind(); }
protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e) { RadGrid1.DataSource = dtTable; }0
Marcio Nascimento
Top achievements
Rank 1
answered on 26 Apr 2011, 03:01 PM
Hi Vasil,
I'll explain better my needs.
It is common in my projects doing hard mathematical operations. Those operations request a lot of matrix calculations and the result should be visualized in a Grid. Until now, I have been doing this using SQL database to "convert" the double[][] array structure into a dataset, which Radgrid can read. However, with the increase of my system users, the calls to SQL Database will increase a lot too, exponentially.
So, I have been thinking...If I can convert those double arrays to read in RadGrid without needing SQL Database (which you already solved for me) and therefore I could save back those values into those double arrays, I could avoid all those calls to SQL Database and only storage and show the final result.
Could you help me in this task ?
Regards,
Marcio Nascimento
I'll explain better my needs.
It is common in my projects doing hard mathematical operations. Those operations request a lot of matrix calculations and the result should be visualized in a Grid. Until now, I have been doing this using SQL database to "convert" the double[][] array structure into a dataset, which Radgrid can read. However, with the increase of my system users, the calls to SQL Database will increase a lot too, exponentially.
So, I have been thinking...If I can convert those double arrays to read in RadGrid without needing SQL Database (which you already solved for me) and therefore I could save back those values into those double arrays, I could avoid all those calls to SQL Database and only storage and show the final result.
Could you help me in this task ?
Regards,
Marcio Nascimento
0
Hi Marcio,
Here is an example how to update the values in the array:
Aspx:
C#:
Kind regards,
Vasil
the Telerik team
Here is an example how to update the values in the array:
Aspx:
<telerik:RadGrid ID="RadGrid2" runat="server" OnNeedDataSource="RadGrid2_NeedDataSource" OnUpdateCommand="RadGrid2_UpdateCommand" AutoGenerateEditColumn="true"> <MasterTableView EditMode="InPlace"> </MasterTableView></telerik:RadGrid>C#:
protected void Page_Load(object sender, EventArgs e){ if (Session["data"] == null) { double[][] criterios = new double[][] { new double[] {1,5,0.33333333,1}, new double[] {0,1,0.2,0.5}, new double[] {0,0,1,3}, new double[] {0,0,0,1} }; Session["data"] = criterios; //populate some data in the Session["data"] }}protected void RadGrid2_NeedDataSource(object sender, GridNeedDataSourceEventArgs e){ RadGrid2.DataSource = GetDataTableFromArray((double[][])Session["data"]); //Use Session["data"] to generate Datasource for the grid}public static DataTable GetDataTableFromArray(double[][] array){ DataTable dataTable = new DataTable(); if (array.Length > 0) { for (int c = 0; c < array[0].Length; c++) { dataTable.Columns.Add(); } } foreach (double[] row in array) { DataRow dataRow = dataTable.NewRow(); for (int i = 0; i < row.Length; i++) dataRow[i] = row[i]; dataTable.Rows.Add(dataRow); } return dataTable;}protected void RadGrid2_UpdateCommand(object sender, GridCommandEventArgs e){ double[][] data = (double[][])Session["data"]; //get the double array from the session object int row = e.Item.ItemIndex; for (int col = 0; col < data[row].Length; col++) { data[row][col] = double.Parse((e.Item.Controls[col + 3].Controls[0] as TextBox).Text); //Note that the column index abouve is "+3" because of the autogenerated controls from edit column //save edited values to the double array }}Kind regards,
Vasil
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.