I have a datagride that is bound to a DataTable for it's source. When clicking the column heading to sort the data I need to rebuild the DataTable and rebind that to the datagrid.
The reason for this is that one of the columns in the DataTable is a ranking based on the value selected.
COLUMN1 COLUMN2 RANKING
-------------------------------------
100 42
271 72
67 92
My stored procedure will apply the ranking column if I pass in the column name.
67 92 3
100 42 2
271 72 1
To complicate things, the datagrid is on a webTab along with a MSChart and a dropdown to select the month of the data. Ultimatly, what I woudl like to have happen is
1) user selects the Month from the drop down and the correct default data set loads (working now)
2) user selects a column and the dataset reloads, showing the new ranking, and the chart refreshes. All still on the selected month. (not working)
Here is some code:
protected void ddSelectMonth_SelectedIndexChanged(object sender, EventArgs e)
{
loadContent("", ddSelectMonth.SelectedValue);
}
private void loadContent(string sort_order, string selected_month)
using (SqlConnection conn = new SqlConnection(dsn_dashboard))
DataSet ds = new DataSet();
string sSQL = @"exec getReportPowerUtilizationRanking '" + sort_order + "'," + selected_month;
lblTest.Text = sSQL;
using (SqlCommand cmd = new SqlCommand(sSQL, conn))
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
ds.Load(dr, LoadOption.OverwriteChanges, new string[] { "Global Data", "Region Data", "Center Data" });
conn.Close();
chart_centers.DataSource = ds.Tables[2];
chart_centers.DataBind();
dataGrid_centers.DataSource = ds.Tables[2];
dataGrid_centers.DataBind();
protected void dataGrid_centers_ColumnSorted(object sender, Infragistics.Web.UI.GridControls.SortingEventArgs e)
string str = dataGrid_centers.Columns[e.Column.Index].Key;
loadContent(str, ddSelectMonth.SelectedValue);
Hi Troy,
Thank you for posting in our forum.
From the provided details I am not able to understand what is exactly your setup and what you are trying to achieve. Can you please clarify your scenario? Also, is would be very helpful if you could attach an isolated sample, demonstrating the issue, so I can run and debug it. Thanks.
Have attached a zip file with functioning aspx and cs files in it.
I repalced the database call with three funtions that build local data tables. You should be able to run this on your server and see exactly what I am seeing.
Please let me know if you have more questions.
Thank you for the sample. However, I still don't understand what you are trying to achieve.
"1) user selects the Month from the drop down and the correct default data set loads (working now)" - I don't see a dropdown on the page. Do you want to set different data source for the grid depending on the selection in this dropdown?
"2) user selects a column and the dataset reloads, showing the new ranking, and the chart refreshes. All still on the selected month. (not working)" - What do you mean "select a column"? Clicking on the header to sort the column? What should happen after this? What is "the selected month"? What exactly should happen that is not working?
Hello Troy,
If you need any additional assistance with this case feel free to contact me.
I will keep this case open for another three days while I am waiting for your response. If at that time you haven't responded, I will close it.
Please note that closed cases may be reopened within thirty days of closure.
Thank you for choosing Infragistics components.