新接触vs2005,关于gridview控件有太多的不明白。
需要解决的问题如下:
一、在gridview绑定字段的时候,如果字段太长,如何截取该字段的前十五个字符显示?且在运行时当鼠标处在该字段的某行位置时,用title属性绑定并显示该行的完整内容!!
二、如何实现鼠标滑过时的行变色?
三、在数据库中有一个bool型的字段,绑定时只能true或false,如何把true或false显示为"成功"和“失败”!!麻烦大家给点提示!!
需要解决的问题如下:
一、在gridview绑定字段的时候,如果字段太长,如何截取该字段的前十五个字符显示?且在运行时当鼠标处在该字段的某行位置时,用title属性绑定并显示该行的完整内容!!
二、如何实现鼠标滑过时的行变色?
三、在数据库中有一个bool型的字段,绑定时只能true或false,如何把true或false显示为"成功"和“失败”!!麻烦大家给点提示!!
解决方案 »
- sql求纠正
- 请问asp分页函数如何分成1,2,3,4,5。。。之关的样式
- 图标出现问号是怎么回事?
- 如何让页面上的DataGrid不显示数据库中的列名啊?
- 关于Session的过期问题
- 晕,看了“asp.net中DataGrid性能测试”觉得datagrid太那个了!不知道是不是真这样???
- 如何实现HTML页面可视化编辑。
- 《ASP.NET 2.0 Unleashed》有中文版吗?
- 高分求各省市数据库文件,以及dropdownlist联动代码
- 100分求用 C# 写的滚动新闻源码
- 哥哥帮忙测试论坛,听棠SPL + FCKeditor + cnveryBBS完美结合
- 谁在用"Visual Studio Express Edition Beta 2 中文版",请问一些问题
http://dev.yesky.com/msdn/453/2078453.shtml
protected string GetStr(string s)
{
if(s.Length>15)return s.SubString(0,15)+"...";
return s;
}
2.变色
void changeRowColor(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
//如果是数据项并且是交替项
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
//添加自定义属性,当鼠标移过来时设置该行的背景色为"6699ff",并保存原背景色
e.Item.Attributes.Add("onmouseover","currentcolor=this.style.backgroundColor;this.style.backgroundColor='#6699ff'");
//添加自定义属性,当鼠标移走时还原该行的背景色
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=currentcolor"); }
}
将tooptip属性绑定到title字段
2。没试过,应该和datagrid相同吧
3。在dataBinding中判断
#region 截取字符
static public string Left(string str, int L)
{
string tmpStr;
tmpStr = str;
if (str.Length > L)
{ tmpStr = str.Substring(0, L) + "...";
}
return tmpStr;
} #endregion
引用:
<%#Left(Convert.ToString(Eval("字段名")),8)%>
这里的8你可以改成15或任意的你喜欢的长度
3:
在sql里写:
(case bool字段 when 'true' then '成功' when 'false' then '失败' End) as ??
http://dev.csdn.net/author/ChengKing/1dd69a7460004eb8aa03eb0a599c74d2.html
未解决的:
1、
第一个问题:根据楼上的sql函数substring()在select语句中报错
报错提示:IErrorInfo.GetDescription 因 E_FAIL(0x80004005) 而失败。 我的语句:string sql = "select id,adminName,adminPwd,LoginTime,loginIp,substring(userInfo,1,15) as userInfo,isLogin from adminLog";如果根据asp.net中的substirng,不知道该如何绑定到gridview,还请麻烦再提示一下!!而且gridivew中也好像没有tooltip属性2、case bool字段 when 'true' then '成功' when 'false' then '失败' End) as ??
这句语句该怎么写?该不会用存储过程吧?我只是上面一个语句?
还请大家帮忙!!
在你的GridView的RowDataBound事件中编写:
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#6699ff'");
e.Row.Attributes.Add
("onmouseout", "this.style.backgroundColor=c");
比如你写的:select aa from ??
如果aa内容太长就要以...代替,而光标移上去又得把aa的内容全部显示,则:<ItemTemplate>
<span title='<%#Eval("aa")%>'>
<%#Left(Convert.ToString(Eval("aa")),8)%>
</span>
</ItemTemplate>
在某个模板列里放一个隐藏控件HiddenField
前台:
<ItemTemplate>
<asp:Label ID="labTip" runat="server"></asp:Label> <asp:HiddenField ID="hiduserid" runat="server" Value='<%#Eval("bool字段")%>' />
</ItemTemplate>后台:
protected void gvUserList_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label labtip = (Label)e.Row.Cells[1].FindControl("labTip");
HiddenField hid_userid = (HiddenField)e.Row.Cells[1].FindControl("hiduserid");
if (hid_userid.Value.ToString() == "true") // {
labtip.Text = "成功";
}
else
{
labtip.Text = "失败";}
}
}
protected string GetStr(string s)
{
if(s.Length>15)return s.SubString(0,15)+"...";
return s;
}
2.变色
void changeRowColor(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
//如果是数据项并且是交替项
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
//添加自定义属性,当鼠标移过来时设置该行的背景色为"6699ff",并保存原背景色
e.Item.Attributes.Add("onmouseover","currentcolor=this.style.backgroundColor;this.style.backgroundColor='#6699ff'");
//添加自定义属性,当鼠标移走时还原该行的背景色
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=currentcolor"); }
}