前台和后台代码。这个是用来经过和点击变色。我想在点击行的时候触发LoadUpData( Business.Load( Convert.ToInt32( e.Row.Cells[ 0 ].Text ) ) );这是我写的查询方法。意思就是每次点击行的时候获取userID来查询东西。请问这个怎么写。现在GridView列为userID、name。如果可以的话顺便告诉怎么影藏userid这列,但是我需要他的值。
script type="text/javascript">
var prevselitem = null;
function selectx(row) {
if (prevselitem != null) {
prevselitem.style.backgroundColor = '';
}
row.style.backgroundColor = '#75BAFF';
prevselitem = row;
}
</script> protected void GV_DATA_RowDataBound( object sender, GridViewRowEventArgs e )
{
if( e.Row.RowType == DataControlRowType.DataRow )
{
e.Row.Attributes.Add( "onmouseover", "if(this!=prevselitem){this.style.backgroundColor='#Efefef'}" );
e.Row.Attributes.Add( "onmouseout", "if(this!=prevselitem){this.style.backgroundColor=''}" );
e.Row.Attributes.Add( "onclick", e.Row.ClientID.ToString() + ".checked=true;selectx(this)" );
e.Row.Attributes[ "style" ] = "Cursor:hand";
}
}
script type="text/javascript">
var prevselitem = null;
function selectx(row) {
if (prevselitem != null) {
prevselitem.style.backgroundColor = '';
}
row.style.backgroundColor = '#75BAFF';
prevselitem = row;
}
</script> protected void GV_DATA_RowDataBound( object sender, GridViewRowEventArgs e )
{
if( e.Row.RowType == DataControlRowType.DataRow )
{
e.Row.Attributes.Add( "onmouseover", "if(this!=prevselitem){this.style.backgroundColor='#Efefef'}" );
e.Row.Attributes.Add( "onmouseout", "if(this!=prevselitem){this.style.backgroundColor=''}" );
e.Row.Attributes.Add( "onclick", e.Row.ClientID.ToString() + ".checked=true;selectx(this)" );
e.Row.Attributes[ "style" ] = "Cursor:hand";
}
}
<script type="text/javascript" language="javascript"> function rowStyleChange(id, value) { if (document.getElementById("oldRow").value == "") {
document.getElementById("oldStyle").value = document.getElementById(id).runtimeStyle.cssText;
document.getElementById("oldRow").value = id;
document.getElementById(id).runtimeStyle.cssText = "background-color:#e6c5fc";
}
else {
document.getElementById(document.getElementById("oldRow").value).runtimeStyle.cssText = document.getElementById("oldStyle").value;
document.getElementById("oldStyle").value = document.getElementById(id).runtimeStyle.cssText;
document.getElementById("oldRow").value = id;
document.getElementById(id).runtimeStyle.cssText = "background-color:#e6c5fc";
} document.getElementById("clickId").value = value;
document.getElementById("btnSearch").click(); }
</script>aspx--->
<input type="hidden" id="oldRow" name="oldRow" runat="server" />
<input type="hidden" id="oldStyle" name="oldStyle" runat="server" />
<input type="hidden" id="clickId" name="clickId" runat="server" />
<asp:Button ID="btnSearch" runat="server" OnClick="btn_Click" />[code=C#]
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (oldRow.Value != "" && oldRow.Value.Equals(e.Row.ClientID))
{
e.Row.Attributes.Add("style", "background-color:#e6c5fc");
}
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
{
e.Row.Attributes.Add("onclick", string.Format("rowStyleChange('{0}','{1}','1')", e.Row.ClientID, e.Row.Cells[0].Text));
}
}
}[/code]
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (oldRow.Value != "" && oldRow.Value.Equals(e.Row.ClientID))
{
e.Row.Attributes.Add("style", "background-color:#e6c5fc");
}
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
{
e.Row.Attributes.Add("onclick", string.Format("rowStyleChange('{0}','{1}','1')", e.Row.ClientID, e.Row.Cells[0].Text));
}
}
}思路是 在RowDataBound注册事件,可以通过e 来取得你要的任何GirdView的Cell的值。
然后在Javascript 的function中 触发隐藏按钮的事件。或者触发你的LoadUpData事件(JS 直接触发也可以<% LoadUpData() %> ) 但是 LoadUpData必须是Public
这个Btn是隐藏的,JS直接触发了, 你可以把LoadUpData 写在这个按钮的事件里
如果不愿意,直接声明Public方法, 用<% LoadUpData() %> 这种方式执行
页面不是有clickId 这个隐藏控件么?
LoadUpData( Business.Load( Convert.ToInt32(clickId.Value ) ) ); 不就可以了么。你要什么值,就在隐藏控件传什么值就可以了啊