没有数据时显示消息

编程入门 行业动态 更新时间:2024-10-28 06:26:45
本文介绍了没有数据时显示消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有弹出的显示图表的webmethod和jquery ..所以当我有数据时点击搜索按钮然后工作正常但是当没有数据时我想在标签中显示消息NO Data。当没有数据我怎么做的时候也不能显示pop .. 我尝试了什么: 检查我试试这个代码

[WebMethod] public static string GetVo(DateTime fromdate,DateTime todate , string region) { string data2 = [; 尝试 { T1 DB = new T1(); var rea =( from vv in DB.tblVeh join rv 在 DB.tblRen vv.MID等于rv。 ID join re rv.RID上的DB.tblRei等于re.RID 其中 re.Region == region &&(vv.Name!= )&& re.StartDate > = fromdate && re.EndDate < = todate group vv by vv.Name into g 选择 new { Name = g.Key, cnt = g.Select(t = > t.Name).Count()})。ToList(); data2 + = rea.ToList()。选择(x = > @ [ + x.Name + @ , + xt + ]) .Aggregate((a,b)= > a + , + b); data2 + = ]; } catch (例外情况) { throw new Exception(); } return data2; }

和jquery

< script type = text / javascript> var strarr = [[ h , 9 ],[ t , 3 ],[ y , 1 ],[ y(束), 1 ]]; $( function (){ $(' [ID * = search_data]')。on(' click', function (){ var fromdate = $(' [ID * = fromdate]')。val(); var todate = $(' [ID * = todate]')。val(); var region = $(' [ID * = regiondrop]选项:选择') [ 0 ]。value; var obj = {}; ob j.fromdate = fromdate; obj.todate = todate; obj.region = region; Getdata(obj); return false ; }); }); function Getdata(obj){ $ .ajax({ type: POST, url: WebForm1.aspx / GetVo,数据: JSON .stringify(obj), contentType: application / json; charset = utf-8, dataType: json, async: true , cache: false ,成功: function (结果){ strarr = result .d; var myarr = strarr; Drewchart(myarr); },错误: function (错误){ alert( 错误); // $(#divcontainer)。hide(); } }); } function Drewchart(结果){ console .log ( JSON .stringify(result, null , 2 )); $(' #container')。highcharts({ chart:{ 类型:' pie', options3d:{ enabled : true , alpha: 45 } }, title:{ text:' 图表内容 } ,副标题:{ text:' Highcharts的3D甜甜圈 }, plotOptions:{馅饼:{ innerSize: 100 ,深度: 45 } },系列:[{ name:' 已交付金额', data: JSON .parse(result)}] }); } < / script> < div id = divcontainer style = display:none align = 中心> < div id = container class = cont_charts> < / div >

和弹出窗口

< script type = text / javascript> $( function (){ $( #divcontainer)。dialog({ modal: true , autoOpen: false , title: Chart,宽度: 600 , height: 450 }); $( #search_data)。click( function (){ $( #divcontainer)。对话框(' open'); }); } ); < / script>

解决方案

( function (){

(' [ID * = search_data]')。on(' click', function (){ var fromdate =

(' [ID * = fromdate]')。val(); var todate =

I have webmethod and jquery for display chart in pop up for this .. so when i click on search button when there is data then working fine but when there is no data i want to display message "NO Data" in label .. and also pop must not display when there is no data how i do this .. What I have tried: check i try this code

[WebMethod] public static string GetVo(DateTime fromdate, DateTime todate, string region) { string data2 = "["; try { T1 DB = new T1(); var rea = (from vv in DB.tblVeh join rv in DB.tblRen vv.MID equals rv.ID join re in DB.tblRei on rv.RID equals re.RID where re.Region == region && (vv.Name != "") && re.StartDate >= fromdate && re.EndDate <= todate group vv by vv.Name into g select new { Name = g.Key, cnt = g.Select(t => t.Name).Count() }).ToList(); data2 += rea.ToList().Select(x => @"[""" + x.Name + @"""," + xt + "]") .Aggregate((a, b) => a + "," + b); data2 += "]"; } catch (Exception ex) { throw new Exception(); } return data2; }

and jquery

<script type="text/javascript"> var strarr = [["h", 9], ["t", 3], ["y", 1],["y (bunch)", 1]]; $(function () { $('[ID*=search_data]').on('click', function () { var fromdate = $('[ID*=fromdate]').val(); var todate = $('[ID*=todate]').val(); var region = $('[ID*=regiondrop] option:selected') [0].value; var obj = {}; obj.fromdate = fromdate; obj.todate = todate; obj.region = region; Getdata(obj); return false; }); }); function Getdata(obj) { $.ajax({ type: "POST", url: "WebForm1.aspx/GetVo", data: JSON.stringify(obj), contentType: "application/json; charset=utf-8", dataType: "json", async: true, cache: false, success: function (result) { strarr = result.d; var myarr = strarr; Drewchart(myarr); }, error: function (error) { alert("error"); //$("#divcontainer").hide(); } }); } function Drewchart(result) { console.log(JSON.stringify(result, null, 2)); $('#container').highcharts({ chart: { type: 'pie', options3d: { enabled: true, alpha: 45 } }, title: { text: 'Contents of Charts' }, subtitle: { text: '3D donut in Highcharts' }, plotOptions: { pie: { innerSize: 100, depth: 45 } }, series: [{ name: 'Delivered amount', data: JSON.parse(result) }] }); } </script> <div id="divcontainer" style="display: none" align = "center"> <div id="container" class="cont_charts"> </div>

and for pop up

<script type="text/javascript" > $(function () { $("#divcontainer").dialog({ modal: true, autoOpen: false, title: "Chart", width: 600, height: 450 }); $("#search_data").click(function () { $("#divcontainer").dialog('open'); }); }); </script>

解决方案

(function () {

('[ID*=search_data]').on('click', function () { var fromdate =

('[ID*=fromdate]').val(); var todate =

更多推荐

没有数据时显示消息

本文发布于:2023-10-30 22:15:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1544157.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:消息   数据

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!