没有数据时显示消息 [英] Display message when there is no data

查看:87
本文介绍了没有数据时显示消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有弹出的显示图表的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 = > @ < span class =code-string> [ + x.Name + @ + x.cnt + ]
.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(< span class =code-string>' 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 + @"""," + x.cnt + "]")
         .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 =


这篇关于没有数据时显示消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆