- 爱易网页
-
C#教程
- gridview单元格编辑刷新有关问题
日期:2014-05-18 浏览次数:20919 次
gridview单元格编辑刷新问题
就是单击gridview的单元格进行编辑时,每单击一次单元格进行编辑时,页面都会刷新一次,怎样使单击单元格页面不再刷新
后台代码如下:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.Data.SqlClient;
public partial class Rdlcs_rp_nmjbqk : System.Web.UI.Page
{
Ref.DAL.T_refugee_total DAL_T_refugee_total = new Ref.DAL.T_refugee_total();
Ref.Model.T_refugee_total Mod_T_refugee_total = new Ref.Model.T_refugee_total();
public string Report_ID
{
get
{
if (ViewState["Report_ID"] != null)
{
return ViewState["Report_ID"].ToString();
}
else
{
ViewState.Add("Report_ID", "");
return ViewState["Report_ID"].ToString();
}
}
set
{
ViewState["Report_ID"] = value;
}
}
int _firstEditCellIndex = 2;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
InitPageInfo();
}
}
private void InitPageInfo()
{
if (Report_ID.ToString() == "")
{
}
else
{
Report_ID = Request.QueryString["id"].ToString();
DataSet ds = new DataSet();
string sql = "select * from T_refugee_total where Report_ID='" + Report_ID + "'";
ds = Ref.DAL.DbHelperSQL.Query(sql);
this.GridView1.DataSource = ds;
this.GridView1.DataBind();
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton _singleClickButton = (LinkButton)e.Row.Cells[0].Controls[0];
string _jsSingle = ClientScript.GetPostBackClientHyperlink(
_singleClickButton, "");
for (int columnIndex = _firstEditCellIndex; columnIndex <
e.Row.Cells.Count; columnIndex++)
{
string js = _jsSingle.Insert(_jsSingle.Length - 2,
columnIndex.ToString());
e.Row.Cells[columnIndex].Attributes["onclick"] = js;
e.Row.Cells[columnIndex].Attributes["style"] +=
"cursor:pointer;cursor:hand;";
}
}
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
switch (e.CommandName)
{
case ("SingleClick"):
int _rowIndex = int.Parse(e.CommandArgument.ToString());
int _columnIndex = int.Parse(Request.Form["__EVENTARGUMENT"]);
this.GridView1.SelectedIndex = _rowIndex;