I'm making a pretty simple polling app. Users text a certain number with the values 'yes' or 'no' and the results show up live via AJAX on a projector. There are five different items to vote on (all yes or no).
Right now I have a SQL View that returns [poll_name, vote_value, value_count] where vote_value is either 'yes' or 'no'.
Using RadHtmlChart, I'm trying to display a stacked BarChart with a bar for each poll_name, a red bar for no votes and a blue bar for yes votes. I tried to alter the code from the BarChart example and merge it with the SqlDataSource example:
<asp:SqlDataSource ID="sqlResults" runat="server" ConnectionString="<%$ ConnectionStrings:MyDB %>"
SelectCommand="select poll_name, vote_value, value_count from vw_sms_pollResults order by poll_id" />
<tel:RadScriptManager runat="server" ID="rsmScriptManager" />
<tel:RadAjaxPanel runat="server" ID="rapPanel" LoadingPanelID="ralpLoadingPanel" EnableAJAX="true">
<tel:RadHtmlChart runat="server" ID="rhcResults" Width="800" Height="500" Transitions="true" DataSourceID="sqlResults">
...
<PlotArea>
<Appearance>
<FillStyle BackgroundColor="White" />
</Appearance>
<XAxis DataLabelsField="poll_name">
<MajorGridLines Visible="false" />
<MinorGridLines Visible="false" />
</XAxis>
<YAxis AxisCrossingValue="0">
<MajorGridLines Visible="false" />
<MinorGridLines Visible="false" />
</YAxis>
<Series>
<tel:BarSeries Stacked="true" DataFieldY="value_count">
<Appearance FillStyle-BackgroundColor="Red" />
</tel:BarSeries>
</Series>
</PlotArea>
</tel:RadHtmlChart>
</tel:RadAjaxPanel>
Unfortunately, I end up with twice as many bars as I want: a 'yes' and a 'no' for each poll_name, they're all the same color (obviously), and they're not stacked. Ideally I would be able to tell it create a new BarSeries for each value of (ie, group by) vote_value.
How should I go about either massaging the data or changing my markup to fix this? In the future I'd like to allow an arbitrary number of responses, so I'm loathe to changing my query to simply have a 'yes_count' and 'no_count' columns, but I may have to in the meantime.
To stack series, you need at least two: http://demos.telerik.com/aspnet-ajax/htmlchart/examples/functionality/stackedseries/defaultcs.aspx
One should have the YES votes for its values (i.e., the field provided in the DataFieldY property should have that number for each item on the x-axis). The other should provide the same for the NO votes.
Thus, you should have something like:
<Series>
<tel:BarSeries Stacked="true" DataFieldY="value_count_Yes">
<Appearance FillStyle-BackgroundColor="Red" />
</tel:BarSeries>
<tel:BarSeries Stacked="true" DataFieldY="value_count_No">
<Appearance FillStyle-BackgroundColor="Blue" />
</tel:BarSeries>
</Series>
I am not sure how your data is structured, so I am not sure how you can obtain this data. Perhaps you can generate a dynamic field in the SQL query itself that subtracts the yes votes from the total votes if that's what you have.
Related
I've been utilizing what I call, "drag, drop and configure" programming for years to create very simple ASP.net forms to collect data for my organization. Basically, I'll drag a datasource into my design view, configure it, and then I'll drag a gridview into the design view and then configure it, etc., etc.
Yesterday, I encountered a behavior I have never seen. My gridview is set to allow row selection. Everything seemed to be working normally until I happened to click on a row that didn't "select" (didn't highlight itself, etc.). And, then I started clicking on other rows and found more that couldn't be selected. Again -- it's not all the rows...just some. i.e. some can be selected and others can't.
After a lot of troubleshooting, the only thing I've been able to determine is that above a certain datakey value -- rows won't select. In this case, its datakeys with values around and > 40,000. Anything below that, and the rows select and the other parts of the form load just fine. The fact that it works for all records with datakeys below a certain value is really stumping me as to what rock to look under next -- hence, actually creating a stackoverflow account and posing the question.
Code for the gridview is below. It does live within an update panel if that matters. Also provided the code behind, though it's not really doing anything of consequence.
Note:
The datakey that seems to be controlling the behavior is a unique identifier for an application within a set of applications. It's not an incremental identity. --- if that helps.
The form is hooked into a database for the select statement and is pulling records from a view to populate the grid.
I'm tempted to show all of my code including the database side and stored procs -- thinking maybe I'm making rookie mistakes with data typing, etc. --- BUT --- I'm pausing there because the gridview selection IS WORKING -- just not above datakeys around and above 40,000
Lastly, when you attempt to select an item with a key > 40,000 the grid will no longer sort by columns or allow you to click a different page. Similarly, if you sort the grid FIRST by applicationID (the datakey) -- all the pages with datakeys > 40,000 are not clickable i.e. pagination for those pages do not work
EDIT --- DANG IT!!! I posted the wrong code behind. I replaced it with the right one. UPDATE: It looks like it's related to the panels. When I comment them out --- it works. When they are included -- the rows in question (keys > 40000) aren't selectable. All this code does is control visibility of panels. How could visibility properties make this kind of impact....weird
Pic of Issue:
<ContentTemplate>
<strong>
<asp:ScriptManager ID="ScriptManager2" runat="server">
</asp:ScriptManager>
Select AIT by using search box below or by sorting and paging through AIT table.<br />
<br />
Search: </strong> <asp:TextBox ID="TxtAITSearch" runat="server"></asp:TextBox>
<asp:Button ID="btn_Search" runat="server" OnClick="btn_Search_Click" Text="Search" />
<em>
<br />
*wildcard searches for AIT number, AIT Name or AIT Manager may be used</em><asp:HiddenField ID="hdnApl_ID" runat="server" />
<asp:HiddenField ID="hdn_StandardID" runat="server" />
<asp:HiddenField ID="Hdn_AlignmentID" runat="server" />
<asp:HiddenField ID="hdn_Attribute" runat="server" />
<br />
<asp:GridView ID="gvAITSelect" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" CellPadding="3" DataKeyNames="applicationID" DataSourceID="DSGetSearchView" GridLines="Vertical" OnSelectedIndexChanged="gvAITSelect_SelectedIndexChanged" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px">
<AlternatingRowStyle BackColor="#DCDCDC" />
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="applicationID" HeaderText="App ID" SortExpression="applicationID" />
<asp:BoundField DataField="fullName" HeaderText="Application" SortExpression="fullName" />
<asp:BoundField DataField="Alignment" HeaderText="Alignment" SortExpression="Alignment" />
<asp:BoundField DataField="AlignmentID" HeaderText="AlignmentID" SortExpression="AlignmentID" Visible="False" />
<asp:BoundField DataField="status" HeaderText="Status" SortExpression="status" />
<asp:BoundField DataField="relatedAssociates_2_displayName" HeaderText="App Mgr" SortExpression="relatedAssociates_2_displayName" />
<asp:BoundField DataField="relatedAssociates_3_displayName" HeaderText="Tech Exec" SortExpression="relatedAssociates_3_displayName" />
</Columns>
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#0000A9" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#000065" />
</asp:GridView>
protected void gvAITSelect_SelectedIndexChanged(object sender, EventArgs e)
{
lbl_Alignment.Text = gvAITSelect.SelectedRow.Cells[3].Text;
Hdn_AlignmentID.Value = gvAITSelect.SelectedRow.Cells[4].Text;
string strAITvalue = gvAITSelect.SelectedRow.Cells[1].Text;
hdnApl_ID.Value = strAITvalue.ToString();
//panel_RoleDetails.Visible = true;
//panel_AITAlignment.Visible = true;
//panel_NoteDetails.Visible = true;
}
Ok -- I figured it out. And, the answer is, I'm a big dummy. Further, the fact that the grid stopped working around in and around 40000 should have been a big flashlight to me pointing the way. Pic of the issues
If you look at the pic I uploaded -- in the course of troubleshooting an earlier and unrelated issue -- I set the DbType (highlighted row) to Int16. In the available selections I don't see an unsigned Int16 -- so, this appears to be signed---Annnnnnnnnnnnnnnnd, of course, good developers know Int16s hold values up to 32,767. Guess what happened when I changed it back to the default "Object"? Yup. It worked. So the problem not at all weird or strange. Instead, very much a rookie mistake.
All this said -- good learning experience. Additionally, #Albert D. Kallal and #fnostro you both gave me some good understanding on some things for the future. I appreciate both of you trying to help me. And, now I also, have a stackoverflow account :)
Thanks again.
It should be so freakin' easy, but why is my data not displaying? I even used the AccessDataSource wizard to configure the datasource and I still can't get it to show what is there. Here is my markup:
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/TravelJoansDB.mdb"
SelectCommand="SELECT ID, Destinations FROM [Destinations]">
</asp:AccessDataSource>
<asp:Label ID="CurrentDestLabel" runat="server" Text="What is currently displayed:" />
<br />
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Destinations") %>'/>
I don't get any errors or anything, just nothing displays for my "Label1". Any thoughts?
I am not quite sure, but I think you try to show a whole List in a single label...
perhaps your command need something like "Select top 1 Destinations FROM [Destinations]"
So you make sure, that you have only one Element selected...
Make sure to include any databound controls in a DetailsView, FormView, Gridview, etc...
I am implementing IListServer. Everything works fine except GetTotalSummary. All examples that I've been able to find show the implementation of GetTotalSummary returning a Dictionary of items. In version 12, the interface for IListServer has changed and no longer returns a dictionary. Instead, it returns a List<objects>.
An example implementation of the interface is given here, but unfortunately the specific method that I need is not implemented.
I don't know how to fill this returning list so that I can see my records' count in grid footer. Any help is really appreciated :)
And here is my ascx for the dynamic grid I am filling:
<dx:ASPxGridView runat="server" Width="100%" ID="grdMain" ClientInstanceName="grid"
KeyFieldName="ID" AutoGenerateColumns="false" EnableRowsCache="false"
OnAutoFilterCellEditorCreate="grid_AutoFilterCellEditorCreate" OnAutoFilterCellEditorInitialize="grid_AutoFilterCellEditorInitialize" OnProcessColumnAutoFilter="grid_ProcessColumnAutoFilter">
<settingsbehavior allowfocusedrow="true" allowclienteventsonload="false" AllowGroup="false" autoexpandallgroups="true"
enablerowhottrack="True" columnresizemode="Control" />
<settings showverticalscrollbar="true" verticalscrollableheight="500" showgrouppanel="false"
showfilterrow="true" ShowHorizontalScrollBar="True" showfooter="True"/>
<styles>
<AlternatingRow Enabled="true" />
<Row Cursor="pointer" />
</styles>
<clientsideevents init="SGEntityListScript.OnInit" endcallback="SGEntityListScript.OnEndCallback" />
<SettingsBehavior EnableCustomizationWindow="true" />
<TotalSummary>
<dx:ASPxSummaryItem FieldName="ID" SummaryType="Count"/>
</TotalSummary>
</dx:ASPxGridView>
The last parameter of the IListServer.Apply method is the list of total summary descriptions requested by the control. Save them locally or immediately evaluate and save results. The GetTotalSummary method should return array of total summary values in the same order as they were requested in the Apply method.
I have a Dev express grid - is there anything else i need to code that would control the size of the cells? they are way too large, like 2 inches wide. But I reduce the width here and it makes no Change.
</DataItemTemplate>
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="PAYSOURCE" VisibleIndex="1" Caption="Paysource" Width="20%">
<CellStyle HorizontalAlign="Left"></CellStyle>
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="GROUPING" VisibleIndex="2" Caption="Grouping" Width="20%">
<CellStyle HorizontalAlign="Left"></CellStyle>
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn VisibleIndex="3" FieldName="OTC_NON_COVER" Caption="OTC Non-Cover" Width="10%">
<PropertiesTextEdit DisplayFormatString="C"></PropertiesTextEdit>
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn VisibleIndex="4" FieldName="RX_NON_COVER" Caption="Rx Non-Cover" Width="10%">
<PropertiesTextEdit DisplayFormatString="C"></PropertiesTextEdit>
</dx:GridViewDataTextColumn>
<dx:GridViewDataColumn VisibleIndex="5" FieldName="APPLY_NON_COVERED_RULES" Caption="Apply Non Covered Rule" Width="10%">
<CellStyle HorizontalAlign="Center"></CellStyle>
</dx:GridViewDataColumn>
I read on Dev Express that you'll have to resize the container as a whole to make those columns narrower. Can't post the link, it is secure link, just google dev express Grid View and you should get the online documentation for it.
There should be a way to set the column headings statically in the grid, then you can name them as you please and make them as short as you need.
You can use the GridView.BestFitColumns() method.
More
I am using ListView control in ASP.NET to retrieve data from my database. I studied web form codes for my ListView control and figured out that it basically makes labels to show my data retrieved from the database. I wonder how I can manipulate the label. I can easily change the font color of the label, but I cannot make the label to truncate and show "(..more)" if its length goes more than 10 without resorting to C# code. (I could not find the labels in .cs page.) Is there anyway I can manipulate the C# codes of the labels automaticaly generated by ListView control? Pease let me know. Thanks in advance!
Below is my ListView control in C#
<asp:ListView ID="Posts" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
<span>
<asp:Label ID="subjectLabel" runat="server" Font-Bold="True" Font-Size="Large" Text='<%# Eval("subject") %>' />
<br />
<asp:Label ID="contentsLabel" runat="server" Font-Size="Small" ForeColor="#666699" Text='<%# Eval("contents") %>' />
<br />
<br /></span>
</ItemTemplate>
If you really want to avoid doing it in code, you could always do it in the SQL that provides the data:
SELECT CASE WHEN Len(contents) > 10 THEN Left(contents, 10) + '...' ELSE contents END
FROM YourTable
WHERE whatever
But you can do it in the databinding Eval() using the ternary operator if you don't want to use code-behind.
in the code behind page u need to bind the listview control with the datatable which u are fetching like,
Posts.Datasource=dt;
Posts.Databind();
where dt is the datatable which u are fetching using sql query.can give more explanation once u write the question more elaborately