zoukankan      html  css  js  c++  java
  • asp.net gridview 鼠标悬浮提示信息

    使用场景:

    gridview绑定数据,某列数据太多,故超过一定字符,隐藏起来,同时鼠标移到指定列显示其明细信息;

    知识点:

    1,oderListTbl_DataBound事件中,添加,oderListTbl.Attributes.Add("style", "word-break:break-all;word-wrap:break-word");

    2,web控件ToolTip属性,显示;

    前台代码:

      1 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="addairevent.aspx.cs" Inherits="web.airchange.addairevent" %>
      2 
      3 <%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
      4 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      5 <html xmlns="http://www.w3.org/1999/xhtml">
      6 <head id="Head1" runat="server">
      7     <title></title>
      8     <link href="/css/default.css" rel="stylesheet" type="text/css" />
      9     <link href="/css/jquery.ui.all.css" rel="stylesheet" type="text/css" />
     10     <script type="text/javascript" src="/js/jquery-1.9.1.js"></script>
     11     <script type="text/javascript" src="/js/jquery.ui.core.js"></script>
     12     <script type="text/javascript" src="/js/jquery.ui.widget.js"></script>
     13     <script type="text/javascript" src="/js/jquery.ui.mouse.js"></script>
     14     <script type="text/javascript" src="/js/jquery.ui.draggable.js"></script>
     15     <script type="text/javascript" src="/js/jquery.ui.position.js"></script>
     16     <script type="text/javascript" src="/js/jquery.ui.resizable.js"></script>
     17     <script type="text/javascript" src="/js/jquery.ui.button.js"></script>
     18     <script type="text/javascript" src="/js/jquery.ui.dialog.js"></script>
     19     <script type="text/javascript" src="/js/jquery.ui.datepicker.js"></script>
     20     <script type="text/javascript" src="/js/common.js?r=20140613"></script>
     21     <script type="text/javascript" src="/js/jquery.validate.js"></script>
     22 </head>
     23 <body>
     24     <form id="orderform" runat="server">
     25     <div class="container">
     26         <div class="title">
     27             <span>【事件航变】<label style="color: purple;"></label></span>
     28         </div>
     29         <div class="content">
     30             <div class="cPanel pbg">
     31                 <div class="detailPanel">
     32                     <table cellpadding="0" cellspacing="0" class="oderAdmin" width="80%">
     33                         <tbody>
     34                             <tr>
     35                                 <th>
     36                                     航司:
     37                                 </th>
     38                                 <td>
     39                                     <asp:TextBox ID="txtairname" runat="server" MaxLength="3"></asp:TextBox>
     40                                 </td>
     41                                 <th>
     42                                     航班号:
     43                                 </th>
     44                                 <td>
     45                                     <asp:TextBox ID="txtflightno" runat="server"></asp:TextBox>
     46                                 </td>
     47                             </tr>
     48                             <tr>
     49                                 <th>
     50                                     出发:
     51                                 </th>
     52                                 <td>
     53                                     <asp:TextBox ID="txtstartcity" runat="server" MaxLength="3"></asp:TextBox>
     54                                 </td>
     55                                 <th>
     56                                     到达:
     57                                 </th>
     58                                 <td>
     59                                     <asp:TextBox ID="txtreachcity" runat="server" MaxLength="3"></asp:TextBox>
     60                                 </td>
     61                             </tr>
     62                             <tr>
     63                                 <th>
     64                                     航变原因:
     65                                 </th>
     66                                 <td>
     67                                     <%--                            <select id="ddlchangereason" name="ddlchangereason" runat="server">
     68                                 <option value="1">航班取消</option>
     69                                 <option value="2">航班延误</option>
     70                                 <option value="3">航班提前</option>
     71                                                                 <option value="4">航班号变更</option>
     72                                 <option value="5">舱位变更</option>
     73                                 <option value="6">直飞变中转</option>
     74                                 <option value="7">起降地变更</option>
     75                                 <option value="9">中转变直飞</option>
     76                                 <option value="10">航变回原订单时间</option>
     77                                 <option value="8">未知</option>
     78                             </select>--%>
     79                                     <asp:DropDownList ID="ddlchangereason" runat="server">
     80                                         <asp:ListItem Value="" Text=""></asp:ListItem>
     81                                         <asp:ListItem Value="1" Text="航班取消"></asp:ListItem>
     82                                         <asp:ListItem Value="2" Text="航班延误"></asp:ListItem>
     83                                         <asp:ListItem Value="3" Text="航班提前"></asp:ListItem>
     84                                     </asp:DropDownList>
     85                                 </td>
     86                                 <th>
     87                                     &nbsp;
     88                                 </th>
     89                                 <td>
     90                                     &nbsp;
     91                                 </td>
     92                             </tr>
     93                             <tr>
     94                                 <th>
     95                                     开始日期:
     96                                 </th>
     97                                 <td>
     98                                     <asp:TextBox ID="txtrangestartdate" runat="server" rel="datetime"></asp:TextBox>
     99                                 </td>
    100                                 <th>
    101                                     结束日期:
    102                                 </th>
    103                                 <td>
    104                                     <asp:TextBox ID="txtrangeenddate" runat="server" rel="datetime"></asp:TextBox>
    105                                 </td>
    106                             </tr>
    107                             <tr>
    108                                 <th>
    109                                     事件内容:
    110                                 </th>
    111                                 <td>
    112                                     <asp:TextBox ID="txtremark" runat="server" rel="datetime" Height="135px" TextMode="MultiLine"
    113                                         Width="456px" MaxLength="2048"></asp:TextBox>
    114                                 </td>
    115                             </tr>
    116                             <tr>
    117                                 <td colspan="5">
    118                                     <asp:Button ID="btnsearch" runat="server" class="button button-primary" OnClick="btnsearch_Click"
    119                                         Text="搜  索" />
    120                                     &nbsp;&nbsp;
    121                                     <asp:Button ID="btnsave" class="button button-primary" runat="server" Text="保  存"
    122                                         OnClick="btnsave_Click" />
    123                                 </td>
    124                             </tr>
    125                         </tbody>
    126                     </table>
    127                 </div>
    128             </div>
    129             <div class="cPanel">
    130                 <div class="detailPanel">
    131                     <asp:GridView ID="oderListTbl" GridLines="None" runat="server" CellSpacing="0" BorderWidth="0"
    132                         CellPadding="0" class="oderListTbl" AutoGenerateColumns="False" OnDataBound="oderListTbl_DataBound"
    133                         OnRowDataBound="oderListTbl_RowDataBound">
    134                         <Columns>
    135                             <asp:TemplateField HeaderText="航司">
    136                                 <ItemStyle />
    137                                 <ItemTemplate>
    138                                     <%# Eval("airname")%>
    139                                 </ItemTemplate>
    140                             </asp:TemplateField>
    141                             <asp:TemplateField HeaderText="出发">
    142                                 <ItemStyle />
    143                                 <ItemTemplate>
    144                                     <%# Eval("starcity")%>
    145                                 </ItemTemplate>
    146                             </asp:TemplateField>
    147                             <asp:TemplateField HeaderText="到达">
    148                                 <ItemStyle />
    149                                 <ItemTemplate>
    150                                     <%# Eval("reachcity")%>
    151                                 </ItemTemplate>
    152                             </asp:TemplateField>
    153                             <asp:TemplateField HeaderText="航班号">
    154                                 <ItemStyle Width="10%" />
    155                                 <ItemTemplate>
    156                                     <%# Eval("flightno")%>
    157                                 </ItemTemplate>
    158                             </asp:TemplateField>
    159                             <asp:TemplateField HeaderText="取消原因">
    160                                 <ItemStyle />
    161                                 <ItemTemplate>
    162                                     <%# GetReasonDesc(Eval("changereason").ToString())%>
    163                                 </ItemTemplate>
    164                             </asp:TemplateField>
    165                             <asp:TemplateField HeaderText="事件内容">
    166                                 <ItemStyle Width="25%" />
    167                                 <ItemTemplate>
    168                                     <%--<%# SubStr(Eval("remark").ToString())%>--%>
    169                                     <%# Eval("remark" )%>
    170                                 </ItemTemplate>
    171                             </asp:TemplateField>
    172                             <asp:TemplateField HeaderText="备注">
    173                                 <ItemStyle Width="15%" />
    174                                 <ItemTemplate>
    175                                     <%# Eval("msg")%>
    176                                 </ItemTemplate>
    177                             </asp:TemplateField>
    178                             <asp:TemplateField HeaderText="创建人">
    179                                 <ItemStyle />
    180                                 <ItemTemplate>
    181                                     <%# Eval("createuserid")%>
    182                                 </ItemTemplate>
    183                             </asp:TemplateField>
    184                             <asp:TemplateField HeaderText="创建时间">
    185                                 <ItemStyle />
    186                                 <ItemTemplate>
    187                                     <%# Eval("createtime")%>
    188                                 </ItemTemplate>
    189                             </asp:TemplateField>
    190                         </Columns>
    191                     </asp:GridView>
    192                     <div class="pager">
    193                         <webdiyer:AspNetPager ID="pager" CssClass="paginator" CurrentPageButtonClass="cpb"
    194                             runat="server" AlwaysShow="True" FirstPageText="首页" LastPageText="尾页" NextPageText="下一页"
    195                             PageSize="20" PrevPageText="上一页" ShowCustomInfoSection="Left" ShowInputBox="Never"
    196                             OnPageChanging="pager_PageChanging" CustomInfoTextAlign="Left" LayoutType="Table"
    197                             CustomInfoHTML="总条数:%RecordCount%  当前页数 %CurrentPageIndex% of %PageCount%">
    198                         </webdiyer:AspNetPager>
    199                     </div>
    200                 </div>
    201             </div>
    202         </div>
    203         <div class="clr">
    204         </div>
    205     </div>
    206     </form>
    207 </body>
    208 </html>
    View Code

    后台代码:

      1 using System;
      2 using System.Collections.Generic;
      3 using System.Linq;
      4 using System.Web;
      5 using System.Web.UI;
      6 using System.Web.UI.WebControls;
      7 using web.code;
      8 using System.Data;
      9 using System.Text;
     10 using webframework.model;
     11 using webframework.bll;
     12 using System.Data.SqlClient;
     13 using System.Transactions;
     14 
     15 namespace web.airchange
     16 {
     17     public partial class addairevent : BasePage //System.Web.UI.Page
     18     {
     19         protected void Page_Load(object sender, EventArgs e)
     20         {
     21             if (!Page.IsPostBack)
     22             {
     23                 PageRender();
     24             }
     25         }
     26 
     27         protected void btnsave_Click(object sender, EventArgs e)
     28         {
     29             if (string.IsNullOrEmpty(ddlchangereason.SelectedValue))
     30             {
     31                 Alert("请选择航班原因");
     32                 ddlchangereason.Focus();
     33                 return;
     34             }
     35             if (string.IsNullOrEmpty(txtstartcity.Text.Trim()) && string.IsNullOrEmpty(txtreachcity.Text.Trim()))
     36             {
     37                 Alert("出发,到达 必须填写其中一项");
     38                 txtstartcity.Focus();
     39                 return;
     40             }
     41             if (string.IsNullOrEmpty(txtrangestartdate.Text.Trim()))
     42             {
     43                 Alert("请选择开始日期");
     44                 txtrangestartdate.Focus();
     45                 return;
     46             }
     47             if (string.IsNullOrEmpty(txtrangeenddate.Text.Trim()))
     48             {
     49                 Alert("请选择结束日期");
     50                 txtrangeenddate.Focus();
     51                 return;
     52             }
     53 
     54             try
     55             {
     56                 DateTime dtnow = DateTime.Now;
     57                 modelt_aireventmain model = new modelt_aireventmain();
     58                 model.airname = txtairname.Text.Trim().ToUpper();
     59                 model.changereason = Convert.ToInt32(ddlchangereason.SelectedValue);
     60                 model.createtime = dtnow;
     61                 model.createuserid = UserOnline.Current.UserName;
     62                 model.flightno = txtflightno.Text.Trim().ToUpper();
     63                 model.starcity = txtstartcity.Text.Trim().ToUpper();
     64                 model.reachcity = txtreachcity.Text.Trim().ToUpper();
     65                 model.remark = txtremark.Text.Trim().ToUpper();
     66                 model.rangestartdate = Convert.ToDateTime(txtrangestartdate.Text.Trim());
     67                 model.rangeenddate = Convert.ToDateTime(txtrangeenddate.Text.Trim());
     68                 model.msg = "";
     69 
     70                 List<modelt_aireventlink> list = new List<modelt_aireventlink>();
     71                 modelt_aireventlink m;
     72                 string ordernos = string.Empty;
     73                 string sql = "SELECT o.id,o.orderno,o.orderstate,o.shopname,o.orderfrom,j.id AS [journeyid],f.startcity,f.endcity,f.takeoffdate,f.carrier,f.flightno " +
     74                 "FROM t_order o INNER JOIN t_journey j ON o.id=j.orderid " +
     75                 "INNER JOIN t_flight f ON o.id=f.orderid AND j.id=f.journeyid " +
     76                 "WHERE takeoffdate>='" + txtrangestartdate.Text.Trim() + "' " +
     77                 "AND takeoffdate<'" + Convert.ToDateTime(txtrangeenddate.Text.Trim()).AddDays(1).ToString("yyyy-MM-dd") + "' ";
     78                 DataTable dt = code.SqlHelper.ExecuteDataTable(code.SqlHelper.ConnectionString, CommandType.Text, sql);
     79                 if (dt != null && dt.Rows.Count > 0)
     80                 {
     81                     foreach (DataRow row in dt.Rows)
     82                     {
     83 
     84                         if (((!string.IsNullOrEmpty(model.starcity) && model.starcity == row["startcity"].ToString().Trim())
     85                                 || string.IsNullOrEmpty(model.starcity))
     86                             && ((!string.IsNullOrEmpty(model.reachcity) && model.reachcity == row["endcity"].ToString().Trim())
     87                                 || string.IsNullOrEmpty(model.reachcity))
     88                             && ((!string.IsNullOrEmpty(model.airname) && model.airname == row["carrier"].ToString().Trim())
     89                                 || string.IsNullOrEmpty(model.airname))
     90                             && ((!string.IsNullOrEmpty(model.flightno) && model.flightno.Contains(row["flightno"].ToString().Trim()))
     91                                 || string.IsNullOrEmpty(model.flightno)))
     92                         {
     93                             if (!ordernos.Contains(row["orderno"].ToString()))
     94                                 ordernos += row["orderno"].ToString() + ",";
     95                             m = new modelt_aireventlink();
     96                             m.orderid = int.Parse(row["id"].ToString());
     97                             m.orderno = row["orderno"].ToString();
     98                             m.shopname = int.Parse(row["shopname"].ToString());
     99                             m.journeyid = int.Parse(row["journeyid"].ToString());
    100                             m.orderfrom = int.Parse(row["orderfrom"].ToString());
    101                             m.noticetime = Convert.ToDateTime("1900-01-01");
    102                             m.creattime = dtnow;
    103                             m.hbid = -1;
    104                             list.Add(m);
    105                         }
    106                     }
    107                     ordernos = ordernos.TrimEnd(',');
    108                 }
    109                 int hbid = -1;
    110                 bllaireventlink bllael = new bllaireventlink();
    111                 using (TransactionScope transaction = new TransactionScope())//使用事务
    112                 {
    113                     using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionString))
    114                     {
    115                         //model.msg = string.Format("匹配订单数量:{0},航班数量:{1},订单号:{2}", list.Select(k => k.orderno).Distinct().ToList().Count, list.Count, string.Join(",", list.Select(k => k.orderno).Distinct().ToList()));
    116                         model.msg = string.Format("匹配订单数量:{0},航班数量:{1}", list.Select(k => k.orderno).Distinct().ToList().Count, list.Count);
    117                         hbid = new bllaireventmain().Add2(model, conn);
    118                         foreach (var l in list)
    119                         {
    120                             l.hbid = hbid;
    121                             bllael.Add1(l, conn);
    122                         }
    123                     }
    124                     transaction.Complete();//就这句就可以了。
    125                     Alert("添加成功");
    126                 }
    127                 PageRender();
    128 
    129 
    130             }
    131             catch (Exception ex)
    132             {
    133                 Alert("出错:" + ex.Message);
    134             }
    135         }
    136         private void PageRender()
    137         {
    138             StringBuilder sb = new StringBuilder("");
    139 
    140             if (!string.IsNullOrEmpty(ddlchangereason.SelectedValue))
    141             {
    142                 sb.Append(" and changereason=" + ddlchangereason.SelectedValue);
    143             }
    144 
    145             if (!string.IsNullOrEmpty(txtstartcity.Text.Trim()))
    146             {
    147                 sb.Append(" and starcity='" + txtstartcity.Text.Trim().ToUpper() + "'");
    148             }
    149             if (!string.IsNullOrEmpty(txtreachcity.Text.Trim()))
    150             {
    151                 sb.Append(" and reachcity='" + txtreachcity.Text.Trim().ToUpper() + "'");
    152             }
    153             if (!string.IsNullOrEmpty(txtairname.Text.Trim()))
    154             {
    155                 sb.Append(" and airname='" + txtairname.Text.Trim().ToUpper() + "'");
    156             }
    157             if (!string.IsNullOrEmpty(txtflightno.Text.Trim()))
    158             {
    159                 sb.Append(" and flightno='" + txtflightno.Text.Trim().ToUpper() + "'");
    160             }
    161             if (!string.IsNullOrEmpty(txtrangestartdate.Text.Trim()))
    162             {
    163                 sb.Append(" and rangestartdate>='" + txtrangestartdate.Text.Trim().ToUpper() + "'");
    164             }
    165             if (!string.IsNullOrEmpty(txtrangeenddate.Text.Trim()))
    166             {
    167                 sb.Append(" and rangeenddate<'" + Convert.ToDateTime(txtrangeenddate.Text.Trim().ToUpper()).AddDays(1).ToString("yyyy-MM-dd") + "'");
    168             }
    169 
    170 
    171 
    172             string sql = code.Q.GetTableByPager("t_aireventmain", "id,rangestartdate,rangeenddate,flightno,airname,remark,starcity,reachcity,changereason,createtime,createuserid,msg", "id desc", sb.ToString(), pager.CurrentPageIndex, base.PageSize);
    173             sql += ";select count(1) from t_aireventmain where 1=1" + sb.ToString();
    174             logclass.Info(sql);
    175             try
    176             {
    177                 DataSet ds = code.SqlHelper.ExecuteDataset(code.SqlHelper.ConnectionString, CommandType.Text, sql);
    178                 oderListTbl.DataSource = ds.Tables[0];
    179                 oderListTbl.DataBind();
    180 
    181                 pager.PageSize = base.PageSize;
    182                 pager.RecordCount = int.Parse(ds.Tables[1].Rows[0][0].ToString());
    183             }
    184             catch (Exception ex)
    185             {
    186                 logclass.Debug("事件航班查询报错:" + ex.TargetSite + "===" + ex.Message);
    187             }
    188         }
    189 
    190         protected void btnsearch_Click(object sender, EventArgs e)
    191         {
    192             pager.CurrentPageIndex = 1;
    193             PageRender();
    194         }
    195 
    196         protected void pager_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    197         {
    198             pager.CurrentPageIndex = e.NewPageIndex;
    199             PageRender();
    200         }
    201 
    202         protected string GetReasonDesc(string reasoncode)
    203         {
    204             string result = "";
    205             switch (reasoncode)
    206             {
    207                 case "1":
    208                     result = "航班取消";
    209                     break;
    210                 case "2":
    211                     result = "航班延误";
    212                     break;
    213                 case "3":
    214                     result = "航班提前";
    215                     break;
    216                 default:
    217                     break;
    218             }
    219             return result;
    220         }
    221 
    222 
    223         protected void oderListTbl_DataBound(object sender, EventArgs e)
    224         {
    225             //数据太长 自动换行
    226             oderListTbl.Attributes.Add("style", "word-break:break-all;word-wrap:break-word");
    227         }
    228 
    229         protected void oderListTbl_RowDataBound(object sender, GridViewRowEventArgs e)
    230         {
    231             if (e.Row.RowType == DataControlRowType.DataRow)
    232             {
    233                 for (int i = 0; i < e.Row.Cells.Count; i++)//获取总列数
    234                 {
    235                     ////鼠标悬浮 显示列标题
    236                     //e.Row.Cells[i].Attributes.Add("title", oderListTbl.HeaderRow.Cells[i].Text.ToString().Trim());
    237                     //e.Row.Cells[i].ToolTip = oderListTbl.HeaderRow.Cells[i].Text.ToString().Trim();
    238 
    239                     //鼠标悬浮 显示列内容
    240                     if (oderListTbl.HeaderRow.Cells[i].Text.ToString().Trim() == "事件内容")
    241                     {
    242                         e.Row.Cells[i].ToolTip = (((DataRowView)e.Row.DataItem)["remark"]).ToString();
    243                     }
    244                 }
    245             }
    246 
    247         }
    248 
    249         protected string SubStr(string str)
    250         {
    251             return str.Length <= 10 ? str : str.Substring(0, 10) + "....";
    252         }
    253     }
    254 }
    View Code

    其他:设置div的title值,提示信息

    1 "<div style='overflow: hidden; white-space: nowrap; text-overflow: clip;90%;' title='" + data.startcitytext + "'>" + data.startcitytext + "</div>";
    View Code
  • 相关阅读:
    Ajax中onreadystatechange函数不执行,是因为放在open()后
    js调用ajax案例2,使用ok
    js调用ajax案例
    通过设置ie的通过跨域访问数据源,来访问本地服务
    Net 4.5 WebSocket 在 Windows 7, Windows 8 and Server 2012上的比较以及问题
    Net 4.5 WebSocket 在 Windows 7, Windows 8 and Server 2012上的比较
    windows 系统纯净版官网下载地址
    iOS:给Git仓库上传代码时,超过100M会被拒绝(例如github和oschina)
    iOS:Xcode8以下真机测试iOS10.0和iOS10.1配置包
    iOS:高德地图的使用
  • 原文地址:https://www.cnblogs.com/systemkk/p/6077911.html
Copyright © 2011-2022 走看看