Click here to Skip to main content
15,917,731 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a radiobutton list and a datalist... I am using both of these to form a chart using chart.js...

The chart is created on clicking the link button in the data list based on radio button value provided... I am getting the chart, but the problem is that the data table that is used to form the chart is derived based on the value of the radio button selected... The problem is that the system takes the default value selected in the radio button for binding the chart. Even if I select another value the chart shows data from the default radio button... How to pass the radio button value on loading the page to the web service...??? Also how to clear the chart when the next link button is clicked...???

Regards,

Sajin A
VB
<WebMethod()> _
        Private Shared Function GetZoneSalesData(ByVal rbtlSales As String) As String()
        Dim clsSales As New TS.Corporate.SalesGenerateBarChart
        Dim dTable As New DataTable
        Dim strReportHeading As String = ""

        dTable = clsSales.ZoneSalesValue(rbtlSales)
        Dim resultdata = From d In dTable.AsEnumerable()
        Dim data(dTable.Rows.Count - 1) As String
        For i As Integer = 0 To dTable.Rows.Count - 1
            Dim item As DataRow = dTable.Rows(i)
            data(i) = (String.Format("{0}-{1}", item("zone"), item("zoneTotal")))
        Next
        Return data
    End Function


HTML
<script type="text/javascript">
       <script type="text/javascript">
    $(function() {
        $("[id*=dlstZone] [id*=lbtnZone]").click(function() {
            var row = $(this).closest('tr');
            var branchId = $(row).find('[id*=hfBranchId]').val();

            var rbtlSales = document.getElementById("<%= rbtlSales.ClientID%>");

            alert(rbtlSales);
            $.ajax({
                url: '<%=ResolveUrl("~/Corporate/Sales.aspx/GetZoneData") %>',
                data: "{'rbtlSales':'" + rbtlSales + "'}",
                dataType: "json",
                type: "POST",
                contentType: "application/json; charset=utf-8",
                success: function(data) {
                    var labels = [];
                    var datas = [];
                    $.each(data.d, function(i, item) {
                        var l = item.split('-')[0];
                        var d = item.split('-')[1];
                        labels.push(l);
                        datas.push(d);
                    });
                    var barChartLocData =
            {
                labels: labels,
                datasets:
                [
                    {
                        fillColor: "green",
                        highlightFill: "lightgreen",
                        data: datas
                    }
                ]
            };

                    var ctx = document.getElementById("canvas").getContext("2d");
                    new Chart(ctx).HorizontalBar(barChartLocData, {
                        responsive: true
                    });
                },
                error: function(response) {
                    alert(response.responseText);
                },
                failure: function(response) {
                    alert(response.responseText);
                }
            });
        });
    });
</script>


My radio button is as below...

ASP.NET
<asp:radiobuttonlist id="rbtlSales" runat="server" font-bold="True" cellpadding="1" repeatlayout="Flow" xmlns:asp="#unknown">
<asp:listitem value="today" selected="True">Today's Sales</asp:listitem>
<asp:listitem value="yesterday">Yesterday's Sales</asp:listitem>
<asp:listitem value="mtd">MTD</asp:listitem>
<asp:listitem value="prevmonth">Previous Month Sales</asp:listitem>
<asp:listitem value="ytd">YTD</asp:listitem>
</asp:radiobuttonlist>
Posted
Updated 3-Dec-15 1:03am
v3
Comments
Sinisa Hajnal 3-Dec-15 6:46am    
You're not showing your HTML so I don't know if your radio button list is run at server or client. Anyhow, you could change GetZoneData method to take radio button value as parameter and send it in ajax.data ...
SajinAboo 3-Dec-15 6:51am    
Hi,

I have made some changes... Please look at the above... But I am still not getting the value of the radio button...

SajinAboo 4-Dec-15 4:23am    
Hi,

I have another doubt, I learned from this how to take the value from a radio button list... Same way I want to pass the value from a datalist on clicking a link button inside the datalist...

Regards,
Sajin

1 solution

Get the selected value like this instead

var rbtlSales = $("#<%= rbtlSales.ClientID%>");

var selectedValue = rbtlSales.find("input:checked").val();

alert(selectedValue);


Then use

JavaScript
data: "{'rbtlSales':'" + selectedValue + "'}",
 
Share this answer
 
Comments
Sinisa Hajnal 3-Dec-15 7:19am    
Beat me to it. :)
Original poster should note: alert is for testing, should be removed...add null check instead
SajinAboo 3-Dec-15 8:00am    
Thanks for all your help... I have checked with it...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900