如何在Gridview中更改所选行的背景颜色 [英] How Do I Change The Background Color Of Selected Row In Gridview
问题描述
我正在使用网格视图..在其中,我使用javascript重定向页面..如果用户点击gridview的一行,页面将重定向到自身,某些按钮在重定向上可见..所以当一个页面被重定向时,我希望所选行的背景颜色为蓝色...我已经尝试过下面的代码但是它不起作用..任何人都可以帮助我吗???
< pre lang =cs> protected void GridViewJobList_RowDataBound( object sender,GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string primaryKey = DataBinder。 Eval(e.Row.DataItem, Entry_No)+ ;
if (e.Row.DataItem == primarykey)
{
e.Row.BackColor = System.Drawing。 Color.Blue;
}
}
}
使用ajax hovermenuextender参考以下链接中的文件
https://docs.google.com/file/d/0B6KVMR-4BUaFdXB0MnV2cFNNdlU/edit [ ^ ]
嗨杰克。
您可以尝试这样。
1)使用<$ c从gridview获取主键
之后$ c> javascript ,你可以在url
例子中传递主键查询字符串
(window.location = '你的url.aspx?键='你的钥匙')
2)并在页面加载
方法您可以检查特定键
的查询字符串,如下所示。
string _primaryKey = ;
受保护 void Page_Load( object sender,EventArgs e)
{
if (!Page.IsPostBack)
{
_primaryKey = Request.QueryString [ key];
}
}
受保护 void GridViewJobList_RowDataBound( object sender,GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string primaryKey = DataBinder.Eval(e.Row.DataItem, Entry_No)+ 跨度>;
if (primaryKey == _primaryKey)
e.Row.BackColor = System.Drawing.Color.Blue;
}
}
I am using a grid view.. In it, i am using a javascript to redirect page.. if user clicks on a row of a gridview, the page is redirected to itself with certain buttons made visible on redirect.. so when a page is redirected, i want the background color of the row selected to be blue... i had tried the code below but it does not works.. can anyone help me???
protected void GridViewJobList_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string primaryKey = DataBinder.Eval(e.Row.DataItem, "Entry_No") + "";
if (e.Row.DataItem == primarykey)
{
e.Row.BackColor = System.Drawing.Color.Blue;
}
}
}
use ajax hovermenuextender refer document on following link
https://docs.google.com/file/d/0B6KVMR-4BUaFdXB0MnV2cFNNdlU/edit[^]
Hi Jack.
You can try like this.
1) After getting theprimary key
from gridview usingjavascript
, you can pass the primarykey asquery string
in the url
example ( window.location = ' your url.aspx?Key='your key' )
2) And in thepage load
method you can check the query string for that particularkey
as below.
string _primaryKey = ""; protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { _primaryKey = Request.QueryString["key"]; } } protected void GridViewJobList_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { string primaryKey = DataBinder.Eval(e.Row.DataItem, "Entry_No") + ""; if (primaryKey == _primaryKey) e.Row.BackColor = System.Drawing.Color.Blue; } }
这篇关于如何在Gridview中更改所选行的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!