sharpcn的专栏

路,在脚下曲折的延伸,我执著的走着,为了心中不变的理想.

朱邵ID:sharpcn
29060次访问,排名3921好友0人,关注者0
sharpcn的文章
原创 42 篇
翻译 2 篇
转载 1 篇
评论 7 篇
sharpcn的公告
mail:
sharpcn@msn.com
site:
明天家园
给我留言


最近评论
hdnero:wow power leveling
hdnero:wow power leveling
风一样的汉子:不错
有见解
有的地方值得一读
ds:fsd
zxccvvbbn:sasdghjhku
文章分类
收藏
    相册
    相册
    我的链接
    偶的链接(RSS)
    坚强2004(RSS)
    灵感之源(RSS)
    笑望人生专栏(RSS)
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    原创 在DataGrid中对内容的截取[Come From WindowsBoy]收藏

    新一篇: 独孤求败-程序人生 | 旧一篇: 从零开始

    在使用DataGrid时经常遇到单元格中的内容过长而导致文本的换行,这样使本来简洁的页面看上去非常乱。下面的方法可以解决这个问题。
    当单元格的内容超出指定的长度后,截去多余的字,然后在鼠标停留在某个单元格上时,就显示全部的内容。
    此方法有个缺点:每个单位格都是指定长度的。
      //某个datagrid的ItemDataBound事件。
      //上半部分设置鼠标悬停时的背景色
      //下半部分才起作用
      public void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
      {
       if(e.Item.ItemType==ListItemType.Item || e.Item.ItemType==ListItemType.AlternatingItem)
       {
        Color color = this.DataGrid1.SelectedItemStyle.ForeColor;
        string foreColor = string.Format("#{0:X2}{1:X2}{2:X2}", color.R, color.G, color.B);
        color = this.DataGrid1.SelectedItemStyle.BackColor;
        string backColor = string.Format("#{0:X2}{1:X2}{2:X2}", color.R, color.G, color.B);
        // 如果没有设置选中项的颜色,则不设置鼠标效果
        if(foreColor != "#000000" || backColor != "#000000")
        {
         e.Item.Attributes.Add("onmouseover", string.Format("oldItemForeColor=this.style.color;this.style.color='{0}';oldItemBackColor=this.style.backgroundColor;this.style.backgroundColor='{1}'", foreColor, backColor));
         e.Item.Attributes.Add("onmouseout", "this.style.color=oldItemForeColor;this.style.backgroundColor=oldItemBackColor;");
        }
        e.Item.Cells[1].Text = "<div style='text-overflow : ellipsis; overflow : hidden;width:80px;' title='"+e.Item.Cells[1].Text+"'><nobr>" + e.Item.Cells[1].Text + "</nobr></div>";
        e.Item.Cells[2].Text = "<div style='text-overflow : ellipsis; overflow : hidden;width:80px;' title='"+e.Item.Cells[2].Text+"'><nobr><a class=lan href='"+this.Request.ApplicationPath+@"/UpLoadFile/"+System.IO.Path.GetFileName(e.Item.Cells[7].Text)+"'>" + e.Item.Cells[2].Text + "</a></nobr></div>";
        e.Item.Cells[3].Text = "<div style='text-overflow : ellipsis; overflow : hidden;width:80px;' title='"+e.Item.Cells[3].Text+"'><nobr>" + e.Item.Cells[3].Text + "</nobr></div>";
        e.Item.Cells[4].Text = "<div style='text-overflow : ellipsis; overflow : hidden;width:80px;' title='"+e.Item.Cells[4].Text+"'><nobr>" + e.Item.Cells[4].Text + "</nobr></div>";
        e.Item.Cells[5].Text = "<div style='text-overflow : ellipsis; overflow : hidden;width:90px;' title='"+e.Item.Cells[5].Text+"'><nobr>" + e.Item.Cells[5].Text + "</nobr></div>";
        e.Item.Cells[6].Text = "<div style='text-overflow : ellipsis; overflow : hidden;width:90px;' title='"+e.Item.Cells[6].Text+"'><nobr>" + e.Item.Cells[6].Text + "</nobr></div>";
       }
      }

    发表于 @ 2004年10月19日 14:19:00|评论(loading...)|编辑

    新一篇: 独孤求败-程序人生 | 旧一篇: 从零开始

    评论:没有评论。

    发表评论  


    当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
    Csdn Blog version 3.1a
    Copyright © sharpcn