I am trying to draw a chart from SQL-Data, which currently looks like this:
This is the table db.GetTable(cmdGraph) returns:
How do I manage to change the labeling of the pie-parts to display the value of the field Count so that it looks like this?
This is the code that I use to draw the chart:
private void UpdateEvaluation(SqlCommand cmdGraph)
{
chPie.DataSource = db.GetTable(cmdGraph);
chPie.Series["Series1"].XValueMember = "Value";
chPie.Series["Series1"].YValueMembers = "Count";
chPie.DataBind();
}
And this is how it gets called:
UpdateEvaluation(new SqlCommand("SELECT Value, Count(*) as Count " +
"FROM DV.dbo.tbDefender " +
"WHERE Class LIKE 'Operating System' " +
"AND Type LIKE 'Caption' " +
"GROUP BY Value " +
"ORDER BY Count DESC "));
I found it out myself:
chPie.Series["Series1"].IsValueShownAsLabel = true;
The value IsValueShownAsLabel has to be set. Either programatically or through the Designer (In Properties under Chart Series and then look for IsValueShownAsLabel under Label)
Related
I have a DataGrid that is generated from a MySQL query. I would like to to be able to edit the database directly by modifying the DataGrid. Basically what I need is to generate a string like this after user has finished editing a cell:
pseudocode:
"UPDATE current_table SET current_column_name=new_cell_value WHERE id=number that is in the hidden first cell of the edited row"
What would be the most simple way to achieve this?
I've tried looking at the DataGrid properties and events but so far I could not find any "CellEditEnded" events nor can I find how to get the new value or the id that's in the first cell of the row.
EDIT:
Ok, I've made some progress, I am now able to get the id and the column name, but the problem is that I am unable to get the new cell value. I think the problem is that this code fires in CellEditEnding-event, so the change hasn't been commited yet. How can I fix this?
DataRowView dataRow = (DataRowView)gameDatagrid.SelectedItem;
int index = gameDatagrid.CurrentCell.Column.DisplayIndex;
string columnName = gameDatagrid.CurrentCell.Column.Header.ToString();
string cellValue = dataRow.Row.ItemArray[index].ToString();
string id = dataRow.Row.ItemArray[0].ToString();
MessageBox.Show(id + " : " + columnName + " : " + cellValue);
Thanks to a helpful comment I was able to solve this. The full code is as follows:
private void gameDatagrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
{
TextBox t = e.EditingElement as TextBox;
DataRowView dataRow = (DataRowView)gameDatagrid.SelectedItem;
int index = gameDatagrid.CurrentCell.Column.DisplayIndex;
string columnName = gameDatagrid.CurrentCell.Column.Header.ToString();
string newValue = t.Text;
int id = (int)dataRow.Row.ItemArray[0];
string query = "UPDATE table_name SET " + columnName + "=\"" + newValue + "\" WHERE id=" + id;
}
I have an ASP.NET gridview within which i have a template column which hosts a dropdown. the dropdown is bound from server side code. I am attaching the following JavaScript:
dl.Attributes.Add("onchange", "return UpdateTaskDetail(" + dl.ClientID + ",'" + u.TaskID + "','" + "');");
I am able to execute the JavaScript function name UpdateTaskDetail.
The issue in want to get the selected value of the dropdown for which i have been trying the following
var taskstatusid = $("#" + ctr.name + " option:selected").val();
This line does not fetch the value.
Can someone please tell me what might be incorrect?
In your UpdateTaskDetail function you can do something like this:
function UpdateTaskDetail(control, task, other ){
var taskstatusidVal = $("#" + control).val();//For selected value. remove "option:selected"
var taskstatusidText = $("#" + control + " option:selected").text();//For selected Text
alert(taskstatusidVal + taskstatusidText);//Test
}
string filter = string.Empty;
if (checkboxBalkon.Checked== true)
{
filter = "Balkon LIKE '%" + checkboxBalkon.Checked + "%'"; //???
}
I have search form. The code above is supposed to print down all fields from table that has checkbox checked. I compare it, but i don't know how to print it? I need some bool? How to do it?
I believe the answer you are looking for is something like this:
filter = "Balkon = " + checkboxBalkon.Checked;
Cenario:
I have a GridView bound to a DataSource, every column is sortable.
my main query is something like:
select a, b, c, d, e, f from table order by somedate desc
i added a filter form where i can define values to each one of the fields and get the results of a where form. As a result from this, i had to do a custom sorting so that when i sort by a field, i am sorting the filtered query and not the main one.
Now i have to do custom paging, for the same reason, but i don't understand the philosophy of it: I want to guarantee that i can:
filter the results
sort by a column
when i click on page 2, i get page two of the filtered and sorted results
I don't know what i have to do, so i can bind the GV with this. My sorting Method, that is working just fine looks something like:
string condition = GetConditions(); //gets a string like " where a>1 and b>2" depending on the filter the user defines
string query = "select a, b, c, d, e, f from table ";
string direction = (e.SortDirection == SortDirection.Ascending)? "asc": "desc";
string order = " order by " + e.SortExpression + " " + direction;
UtilizadoresDataSource.SelectCommand = query + condition + order;
i've never done custom paging, i am trying:
GetConditions() //no problem here
How can i find out how the GridView is sorted (by what field and sortingorder)?
thank you very much
You can use ROW_NUMBER to get the number of rows that a query is returning and then filter only those element that will be visible for the given page. For example you should add ROW_NUMBER function in the select clause and add the filtering in the where cause.
string condition = GetConditions(); //gets a string like " where a>1 and b>2" depending on the filter the user defines
string query = "select ROW_NUMBER() OVER(ORDER BY " + order + ") a, b, c, d, e, f from table ";
string direction = (e.SortDirection == SortDirection.Ascending)? "asc": "desc";
string order = " order by " + e.SortExpression + " " + direction;
condition = condition + " RowNo BETWEEN ((#Page - 1) * #PageSize + 1) AND (#Page * #PageSize) "
UtilizadoresDataSource.SelectCommand = query + condition + order;
You can find a more detailed example here.It also contains a sample project with binding a grid.
P.S. I would suggest you to create a stored procedure and pass the parameters from the code behind. This can increase the speed and also it easier to maintain.
I have created a multicolumn custom field and deployed it in SharePoint. To be able to use the field values from my custom field I also deployed an event receiver to copy the three values from my custom field to three separate regular text fields. If the three text fields do not exist I create them with XML in code. I also make sure the fields have the right visibility settings even if the field exist.
Creating the field in xml:
string fieldXml = string.Format("<Field ID=\"{0}\" " +
"Type=\"{1}\" " +
"Name=\"{2}\" " +
"StaticName=\"{2}\" " +
"DisplayName=\"{2}\" " +
"Required=\"{3}\" " +
"ShowInEditForm=\"TRUE\" " +
"ShowInNewForm=\"TRUE\" " +
"ShowInDisplayForm=\"TRUE\" " +
"ShowInListSettings=\"TRUE\" " +
"ShowInViewForms=\"TRUE\" " +
"ShowInVersionHistory=\"TRUE\" " +
"ShowInFileDlg=\"TRUE\"" +
"></Field>",
Guid.NewGuid(),
fieldType,
fieldName,
required);
list.Fields.AddFieldAsXml(fieldXml, true, SPAddFieldOptions.Default);
Make sure visibility settings OK when the field already exist:
field.ShowInEditForm = true;
field.ShowInNewForm = true;
field.ShowInDisplayForm = true;
field.ShowInListSettings = true;
field.ShowInViewForms = true;
field.ShowInVersionHistory = true;
field.Update();
list.Update();
I found no way of setting the ShowInFileDlg property programmatically once the field was created.
The thing is that this code works great up until I open a document in MS Word and the three text fields all have text assigned in the list but in Word they are empty!
Have anybody seen this before, what am I doing wrong!?
To be able to open a field in DIP (document information panel at the top in word documents) you need to add the SourceId property to the field:
SourceID="http://schemas.microsoft.com/sharepoint/v3"
For more information see here (msdn).