我将Datagrid嵌到DIV中(目的是可以拉动光标条浏览全部数据),页面为30秒刷新一次,Datagrid中有一个按钮列,我想在点击Datagrid的按钮列的某一行后此行变色,当且在页面刷新后保持此行的状态
请问高手们有什么好办法吗?帮帮我吧
请问高手们有什么好办法吗?帮帮我吧
解决方案 »
- vs2008中在Head中引入(link)样式,不能显示,直接在Head中写样式能正常显示?
- 救急!!!asp.net 引用COM的问题
- asp.net 解决返回上一页刷新问题?
- VS2010 中的 Debug 和 Release 两个模式问题
- 关于不同浏览模式的异同?
- 紧急!!!各位帮忙!!!求正则表达式
- 页面有FarPoint.Web.Spread.FpSpread控件显示数据时就很慢是啥缘故?
- 做程序,高等数学真的很重要吗?
- 想买一个报表控件,麻烦大家推荐一下。清空所有分啊!
- 新手请教:我想从一个表里选择id=5的记录,插入到另一个表里!怎么实现!
- 为什么我发的邮件显示html代码?
- 存储过程问题,急!
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;namespace WebApplication_rd
{
/// <summary>
/// Demostrates how to have a datagrid server control be booked
/// </summary>
public class datagrid : System.Web.UI.Page
{ protected System.Web.UI.WebControls.DataGrid DGProducts;
int bookIndex = 0; // The index of the row that should be scrolled to
int itemCount = 0; // Counter for the amount of items on the page
bool bookMark = true; // Controls whether or not the page is booked
#region DGProducts EventHandlers private void DGProducts_ItemDataBound(object source, DataGridItemEventArgs e) {
if (bookMark) {
LiteralControl anchor = new LiteralControl();
anchor.Text = "<a name=\"" + itemCount.ToString() + "\">";
itemCount ++;
e.Item.Cells[0].Controls.Add(anchor);
}
} private void DGProducts_ItemCommand(object source, DataGridCommandEventArgs e) {
if (e.CommandName == "Select") {
e.Item.BackColor = Color.Blue; if (bookMark) {
bookIndex = e.Item.ItemIndex;
this.InsertScriptBlock();
}
}
}
#endregion #region EventHandlers
private void Page_Load(object sender, System.EventArgs e)
{ this.Bind(); } #endregion #region User Defined private void InsertScriptBlock() {
System.Text.StringBuilder jScript = new System.Text.StringBuilder();
jScript.Append("<script language=\"JavaScript\">");
jScript.Append("location.href=\"#");
jScript.Append(this.bookIndex.ToString());
jScript.Append("\";");
jScript.Append("</script>"); this.RegisterClientScriptBlock("Book", jScript.ToString());
}
private void Bind()
{
DGProducts.DataSource = this.CreateDataSource(1000);
DGProducts.DataBind();
}
private DataTable CreateDataSource(int count) {
DataTable table = new DataTable();
DataColumn column = null;
DataRow row = null; // Create 5 columns
for (int iCol = 0; iCol < 5; iCol++) {
column = new DataColumn("Column: " + iCol.ToString(), typeof(string));
table.Columns.Add(column); } //Create Rows based on count variable
for (int iRows = 0; iRows < count; iRows ++) {
row = table.NewRow();
for (int iCol = 0; iCol < 5; iCol ++) {
row[iCol] = "Value: " + iCol.ToString();
} table.Rows.Add(row);
}
return table;
}
#endregion #region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.DGProducts.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DGProducts_ItemCommand);
this.DGProducts.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.DGProducts_ItemDataBound);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion
}}
然后,在page load 的时候,检测session,如果有你存的那个值,则让datagrid 的selected index = session里的值
over