| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1765 人关注过本帖
标题:[求助]GridView选择行问题
只看楼主 加入收藏
Liu018
Rank: 1
等 级:新手上路
帖 子:61
专家分:0
注 册:2007-5-28
收藏
 问题点数:0 回复次数:6 
[求助]GridView选择行问题
为何增加一个datarowbound事件(就是在一行中任意地方能选中),但edit功能却变得无效了。
若只是简单的一个选择列edit就正常了。怎么做到增加一个datarowbound事件edit有效
搜索更多相关主题的帖子: GridView 选择 
2007-09-14 12:13
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:0 
你在datarowbound里面写的什么?

飘过~~
2007-09-14 12:27
Liu018
Rank: 1
等 级:新手上路
帖 子:61
专家分:0
注 册:2007-5-28
收藏
得分:0 

protected void gviewEmployee_SelectedIndexChanged(object sender, EventArgs e)
{
Label txtMsg = new Label();
switch (gviewEmployees.Rows[gviewEmployees.SelectedIndex].RowState)
{
case DataControlRowState.Selected:
txtMsg.Text = "你选择奇数行,行状态为" + gviewEmployees.Rows[gviewEmployees.SelectedIndex].RowState + ": " +
gviewEmployees.Rows[gviewEmployees.SelectedIndex].Cells[3].Text;
break;
case DataControlRowState.Alternate|DataControlRowState.Selected:
txtMsg.Text="你选择偶数行,行状态为"+gviewEmployees.Rows[gviewEmployees.SelectedIndex].RowState+": "+gviewEmployees.Rows[gviewEmployees.SelectedIndex].Cells[3].Text;
break;
}
Page.Controls.Add(txtMsg);
}


protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
PostBackOptions myPostBackOptions = new PostBackOptions(this);
myPostBackOptions.AutoPostBack = false;
myPostBackOptions.RequiresJavaScriptProtocol = true;
myPostBackOptions.PerformValidation = false;

String evt = Page.ClientScript.GetPostBackClientHyperlink(sender as System.Web.UI.WebControls.GridView, "Select$" + e.Row.RowIndex.ToString());

if (e.Row.RowType == DataControlRowType.DataRow)
{
//单击事件
e.Row.Attributes.Add("onclick", evt);
e.Row.Attributes["style"] = "Cursor:hand";

}
}

2007-09-14 12:33
Liu018
Rank: 1
等 级:新手上路
帖 子:61
专家分:0
注 册:2007-5-28
收藏
得分:0 
当单击edit时也同样只是激发了GridView1_RowDataBound事件,而edit则无效了。点解?
2007-09-14 12:35
Liu018
Rank: 1
等 级:新手上路
帖 子:61
专家分:0
注 册:2007-5-28
收藏
得分:0 
为何把button转换为link就可以了。郁闷...
2007-09-14 13:05
Liu018
Rank: 1
等 级:新手上路
帖 子:61
专家分:0
注 册:2007-5-28
收藏
得分:0 

原来最好的办法是这样:
//建立奇数行与偶数行的onmouseover及onmouseout的颜色变换
if (Convert.ToInt16(ViewState["LineNo"]) == 0)
{
e.Row.BackColor = Color.FromArgb(255, 251, 214);
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFBD6';this.style.color='blue'");
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#C0C0FF';this.style.color='#ffffff'");

ViewState["LineNo"] = 1;
}
else
{
e.Row.BackColor = Color.White;
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF';this.style.color='blue'");
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#C0C0FF';this.style.color='#ffffff'");

ViewState["LineNo"] = 0;
}

break;

2007-09-14 17:30
Liu018
Rank: 1
等 级:新手上路
帖 子:61
专家分:0
注 册:2007-5-28
收藏
得分:0 

原来最好的办法是这样:
//建立奇数行与偶数行的onmouseover及onmouseout的颜色变换
if (Convert.ToInt16(ViewState["LineNo"]) == 0)
{
e.Row.BackColor = Color.FromArgb(255, 251, 214);
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFBD6';this.style.color='blue'");
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#C0C0FF';this.style.color='#ffffff'");

ViewState["LineNo"] = 1;
}
else
{
e.Row.BackColor = Color.White;
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF';this.style.color='blue'");
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#C0C0FF';this.style.color='#ffffff'");

ViewState["LineNo"] = 0;
}

break;

2007-09-14 17:32
快速回复:[求助]GridView选择行问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.025217 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved