Gridview选中某行,和设定某行某列的一个值的链接?

wesleyluo 2008-11-10 01:10:49
我现在用Gridview连接了一个数据库,显示了数据。
如何实现我的鼠标移动到某行某行就呈现选中状态,移动到某行某列的一个值上时,此值就呈现出下划线并可以点击链接到相关页面?
就想CSDN论坛那样。
...全文
436 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
wesleyluo 2008-11-11
  • 打赏
  • 举报
回复
来个人给我讲讲啊,上面15的代码是怎么回事啊?
wesleyluo 2008-11-10
  • 打赏
  • 举报
回复
我把"pice"改成了我数据项目中有的"title",然后再运行,但是,在这一行它又出现了另外一个错误, 输入字串格式不正确。 将字串转换为DateTime时,请先将字串修改为可正确剖析的日期格式,再将个别变数指向DateTime物件。
到底是怎么回事呢?
谁给我解释下啊。
wesleyluo 2008-11-10
  • 打赏
  • 举报
回复
我在RowBind()事件里写事件代码,但是我运行的时候,提示没有"pice"的属性?要怎么修改啊?
以下为我copy的代码:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//将满足特定条件的行标为高亮
if (e.Row.RowType == DataControlRowType.DataRow)//判定当前的行是否属于datarow类型的行
{
int pice= Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "pice"));//取当前行的列值,就是在这句提示没有"pice"的属性
if (pce<10)
e.Row.BackColor = Color.Red;
}
//加入鼠标滑过的高亮效果
if (e.Row.RowType == DataControlRowType.DataRow)//判定当前的行是否属于datarow类型的行
{
//当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色
e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='yellow',this.style.fontWeight='';");
//当鼠标离开的时候 将背景颜色还原的以前的颜色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
}
//单击行改变行背景颜色
if (e.Row.RowType == DataControlRowType.DataRow)
{
  e.Row.Attributes.Add("onclick","this.style.backgroundColor='#99cc00'; this.style.color='buttontext';this.style.cursor='default';");
}

birdlonger 2008-11-10
  • 打赏
  • 举报
回复
无聊瞎写.

显示连接举例;
DataGridViewLinkColumn column = new DataGridViewLinkColumn();
column.Name = "Link";
column.UseColumnTextForLinkValue = true;
column.Text = "詳細閲覧";
column.LinkBehavior = LinkBehavior.HoverUnderline;
column.TrackVisitedState = true;
DataGridView1.Columns.Add(column);
连接事件中处理:
private void DataGridView1_CellContentClick(object sender,
DataGridViewCellEventArgs e)
{
DataGridView dgv = (DataGridView)sender;
if (dgv.Columns[e.ColumnIndex].Name == "Link")
{
MessageBox.Show(e.RowIndex.ToString() +" ");

DataGridViewLinkCell cell =
(DataGridViewLinkCell)dgv[e.ColumnIndex, e.RowIndex];
cell.LinkVisited = true;

}
}

zjybushiren88888 2008-11-10
  • 打赏
  • 举报
回复
会提示 也有效果 建议你动态添加JS
zjybushiren88888 2008-11-10
  • 打赏
  • 举报
回复
会提示 也有效果 建议你动态添加JS
wesleyluo 2008-11-10
  • 打赏
  • 举报
回复
我在ASPX页面的Gridview里面写
<asp:DataGrid onMouseOver="over(event.srcElement)" onMouseOut="out(event.srcElement)" onclick="click1(event.srcElement) ...>
为什么提示onMouseOver,onMouseOut,onclick不是Gridview的有效属性,所以好像没有作用啊?
zjybushiren88888 2008-11-10
  • 打赏
  • 举报
回复
更改下 在ROWCOMMAND里面写
zjybushiren88888 2008-11-10
  • 打赏
  • 举报
回复
在RowBind()事件里动态写JS就可以了 需要什么效果
wsg13793257207 2008-11-10
  • 打赏
  • 举报
回复
我这个虽然有点跟你的不一样,可是你可以改下···
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int us = int.Parse(((DataRowView)e.Row.DataItem)["h_jd_id"].ToString());
switch (us%2)
{
case 0:
e.Row.Cells[0].Text = " <a href='http://www.baidu.com'><font color='red'>" + ((DataRowView)e.Row.DataItem)["h_jd_id"].ToString() + "元 </font></a>";
break;
case 1:
e.Row.Cells[0].Text = " <font color='blue'>" + ((DataRowView)e.Row.DataItem)["h_jd_id"].ToString() + "万 </font>";
break;
}
}

}
蓝色木 2008-11-10
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 whitechololate 的回复:]
在gridview 中添加

HTML code
<asp:DataGrid onMouseOver="over(event.srcElement)" onMouseOut="out(event.srcElement)" onclick="click1(event.srcElement) ...>




.css文件中添加

CSS code

.tr1 td {
border-top:solid 1px #fff;
height:22px;
background:#EBEBEB;
padding-left:10px;
}
.tr1 td a:link {
color:#333;
text-decoration:underline;
}
.tr1 td a:visit…
[/Quote]


顶这个
whitechololate 2008-11-10
  • 打赏
  • 举报
回复
在gridview 中添加

<asp:DataGrid onMouseOver="over(event.srcElement)" onMouseOut="out(event.srcElement)" onclick="click1(event.srcElement) ...>


.css文件中添加


.tr1 td {
border-top:solid 1px #fff;
height:22px;
background:#EBEBEB;
padding-left:10px;
}
.tr1 td a:link {
color:#333;
text-decoration:underline;
}
.tr1 td a:visited {
color:#333;
text-decoration:underline;
}
.tr1 td a:hover {
color:#4086BB;
text-decoration:underline;
}
.tr1 td a:active {
color:#333;
text-decoration:none;
}
.tr2 td {
border-top:solid 1px #fff;
height:22px;
background:#D0E3F0;
padding-left:10px;
}
.tr3 td {
border-top:solid 1px #fff;
height:22px;
background:#AAD0EB;
padding-left:10px;
}


javascript中添加

function over(obj) {
if (obj.tagName == 'TD')
if ((obj.parentElement.className != 'tit_list_01') &&(obj.parentElement.className != 'tr3'))
obj.parentElement.className = 'tr2';
}


实现鼠标移过显示选中效果
wesleyluo 2008-11-10
  • 打赏
  • 举报
回复
有没有例子代码啊?帮忙写段看看,我新手都不懂啊。
好人帮帮我吧。
shuyisheng 2008-11-10
  • 打赏
  • 举报
回复
至于链接用那个自定义模板<a href=''>链接</a>
shuyisheng 2008-11-10
  • 打赏
  • 举报
回复
用databind事件,绑定js属性到onmouseover onmouseout来改变背景
搜索一下,这些代码很多的,我比较懒就不写了。
Fibona 2008-11-10
  • 打赏
  • 举报
回复
设置对应的样式(CSS)就行
wuyq11 2008-11-10
  • 打赏
  • 举报
回复
设置css样式,如hover,超链接可用<a href或hyperlink

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧