GridView选取当前行 选取当前行颜色变掉,还想拿第一行,第一列的值.谁能给点详细点的代码. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 private void DataView1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item) { e.Item.Attributes.Add("onclick","return setItemBackColor(this)"); } }JS代码function setItemBackColor(obj) { var Curr_TR=document.all.tags("tr"); for(var i=1;i<Curr_TR.length;i++) { if (Curr_TR[i].style.backgroundColor =="#ccccff") { Curr_TR[i].style.backgroundColor="white"; } } obj.style.backgroundColor="#ccccff"; } 前台: <script language="javascript"> function doPostBack(a,b) { document.getElementById("div2").innerHTML=a+" <br>"+b; } </script> 后台: protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Attributes.Add("onClick", "javascript:doPostBack('" + e.Row.Cells[0].Text + e.Row.Cells[1].Text + e.Row.Cells[2].Text + "','Select$" + e.Row.RowIndex + "');"); } //e.Row.Cells[0]当前行第一列//GridView1.Rows[0].Cells[0].Text 第一行第一列 } protected void gridvie1_rowdatabound(Object serder,GridViewEventArgs e){ //双击事件 if(e.RowType=DataControlsRowType.DataRow) { if(e.rows.cells[21].text.ToString().length<=0||e.rows.cells[22].text.Tostring().length<1) e.Attributes.Add("onclick","return confirm('不能选取或修改非手动录入记录?');"); } e.Attribute.Add("ondblclick","gridview_dbclik("+e.Rows.cells[0]).text.Trim()+","+e.Rows.cells[1].text.Trim()+....+e.Rows.cells[n].text.Trim()+");"); // e.Attribute.Add("");//添加鼠标样式不记得了 // GridView1.Rows[i].Attrivutes.Add("ondbclick","window.open('FlowStationEdit.aspx?ID="+ID+"','FS_Left','')");导航至另一个页面 } } 客户端脚本:gridview1_dblclick(meterid,recordertime,,,,,,,,,,,,,userid){ window.document.forms[0].tblPoliceID.value=meterid; window.document.forms[0].Police1.value = recordertime; window.document.forms[0].tblPoliceName.value=userid; window.document.forms[0].tblPoliceMobie.value=PoliceMobie; } 客户端脚本: gridview1_dblclick(meterid,recordertime,,,,,,,,,,,,,userid) { window.document.forms[0].tblPoliceID.value=meterid; window.document.forms[0].Police1.value = recordertime; window.document.forms[0].tblPoliceName.value=userid; window.document.forms[0].tblPoliceMobie.value=PoliceMobie; //这个是前台赋值 } protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e){ //选中行高亮显示 if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#00bfff'"); e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor"); }}//GridView1.Rows[0].Cells[0].Text 第一行第一列 asp.net邮箱验证功能,,跪求各位大哥大姐帮忙 gridview数据导出excel button控件的使用 插入数据(自增列)报错 初学问个关于字符串的问题 一个菜鸟的问题...? 请问 用户控件 如何使用 Server.Transfer 转页面 关于设置DataGrid输出到EXCEL时单元格格式的设置问题 请问只匹配中文,英文,数字的正则表达式如何写呢。谢谢。 如何添加外网的cookie Asp.net 到出excel 出现的问题 .截图重发下了.大家帮忙看下了啊 .解决两个帖子一起结. 怎么判断asp.net网站是否有内存泄露
private void DataView1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
e.Item.Attributes.Add("onclick","return setItemBackColor(this)");
}
}JS代码function setItemBackColor(obj)
{
var Curr_TR=document.all.tags("tr");
for(var i=1;i<Curr_TR.length;i++)
{
if (Curr_TR[i].style.backgroundColor =="#ccccff")
{
Curr_TR[i].style.backgroundColor="white";
}
}
obj.style.backgroundColor="#ccccff";
}
<script language="javascript">
function doPostBack(a,b)
{
document.getElementById("div2").innerHTML=a+" <br>"+b;
}
</script> 后台:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onClick", "javascript:doPostBack('" + e.Row.Cells[0].Text + e.Row.Cells[1].Text + e.Row.Cells[2].Text + "','Select$" + e.Row.RowIndex + "');");
}
//e.Row.Cells[0]当前行第一列
//GridView1.Rows[0].Cells[0].Text 第一行第一列
}
{ //双击事件
if(e.RowType=DataControlsRowType.DataRow)
{
if(e.rows.cells[21].text.ToString().length<=0||e.rows.cells[22].text.Tostring().length<1)
e.Attributes.Add("onclick","return confirm('不能选取或修改非手动录入记录?');"); }
e.Attribute.Add("ondblclick","gridview_dbclik("+e.Rows.cells[0]).text.Trim()+","+e.Rows.cells[1].text.Trim()+....+e.Rows.cells[n].text.Trim()+");");
// e.Attribute.Add("");//添加鼠标样式不记得了
// GridView1.Rows[i].Attrivutes.Add("ondbclick","window.open('FlowStationEdit.aspx?ID="+ID+"','FS_Left','')");导航至另一个页面
}
}
客户端脚本:
gridview1_dblclick(meterid,recordertime,,,,,,,,,,,,,userid)
{
window.document.forms[0].tblPoliceID.value=meterid; window.document.forms[0].Police1.value = recordertime; window.document.forms[0].tblPoliceName.value=userid; window.document.forms[0].tblPoliceMobie.value=PoliceMobie;
}
gridview1_dblclick(meterid,recordertime,,,,,,,,,,,,,userid)
{
window.document.forms[0].tblPoliceID.value=meterid; window.document.forms[0].Police1.value = recordertime; window.document.forms[0].tblPoliceName.value=userid; window.document.forms[0].tblPoliceMobie.value=PoliceMobie;
//这个是前台赋值
}
{
//选中行高亮显示
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#00bfff'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
}
}//GridView1.Rows[0].Cells[0].Text 第一行第一列