永发信息网

C# 方法调用,刷新界面

答案:5  悬赏:70  手机版
解决时间 2021-04-01 05:15
  • 提问者网友:鼻尖触碰
  • 2021-03-31 20:00
C# 方法调用,刷新界面
最佳答案
  • 五星知识达人网友:醉吻情书
  • 2021-03-31 20:27
C#刷新界面有五种方法:
第一:
private void Button1_Click( object sender, System.EventArgs e )
{
Response.Redirect( Request.Url.ToString( ) );
}

第二:
private void Button2_Click( object sender, System.EventArgs e )
{
Response.Write( "
" );
}

第三:
private void Button3_Click( object sender, System.EventArgs e )
{
Response.AddHeader( "Refresh","0" );
}

第四:
private void Button6_Click( object sender, System.EventArgs e )
{
//Response.Write( "
" );
}

第五:(需替换<>)
LEFT: 408px;
POSITION: absolute;
TOP: 232px" ms_positioning="text2D">
自动刷新页面

全部回答
  • 1楼网友:醉吻情书
  • 2021-03-31 22:27
把load里边的代码写成一个函数调用
  • 2楼网友:duile
  • 2021-03-31 21:57
你要刷新可以把绑定数据库写到一个方法里啊!
然后重新绑定就可以的
  • 3楼网友:千夜
  • 2021-03-31 20:50
主页面:using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using JH.Game.ServiceLibrary.Bll;
using JH.Game.ServiceLibrary.Model;
using System.Data.SqlClient;
using JH.Game.ServiceLibrary;
public partial class Manage_Examin_FillBlankManage : System.Web.UI.Page
{
private int moduleid = 12;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (this.Session["UserName"] == null)
{
Response.Write(" ");
}
else
{
this.form1.Visible = false;
Authority(moduleid);
}
Bind();
Bind1();
Session.Remove("newdb");
}
}
public void Authority(int moduleid)
{
Userinfo users = new Userinfo();
UserinfoBll usersbll = new UserinfoBll();
string UserName = Session["UserName"].ToString();
users = usersbll.GetModelByName(UserName);
int uid = users.id;
UserRole usersrole = new UserRole();
UserRoleBll usersrolebll = new UserRoleBll();
usersrole = usersrolebll.GetModelByUser(uid);
if (usersrole == null)
{
Response.Write("");
}
else
{
string rid = usersrole.urroleid.ToString();
RoleuserAuth roleuAuth = new RoleuserAuth();
RoleuserAuthBll roleuAuthBll = new RoleuserAuthBll();
roleuAuth = roleuAuthBll.GetModelById(Convert.ToInt32(rid), moduleid);
if (roleuAuth == null)
{
Response.Write("");
}
else
{
string flag = roleuAuth.flag.ToString();
if (flag.Equals("0"))
{
this.form1.Visible = true;
Bind();
}
else
{
Response.Write("");
}
}
}
}
FillBlankProblem fillbleanproblem = new FillBlankProblem();
FillBlankProblemBll fillbleanproblemBll = new FillBlankProblemBll();
public void Bind()
{
DataSet da = fillbleanproblemBll.Gets();
da.AcceptChanges();
this.GvExamin.DataSource = da;
this.GvExamin.DataBind();
this.ddlCurrentPage.Items.Clear();
for (int i = 1; i <= this.GvExamin.PageCount; i++)
{
this.ddlCurrentPage.Items.Add(i.ToString());
}
this.ddlCurrentPage.SelectedIndex = this.GvExamin.PageIndex;
if (da.Tables[0].Rows.Count == 0)
{
this.notxt.Text = "没有相关数据!";
}
}
public void Bind1()
{
CourseBll courseBll = new CourseBll();
DataSet da = courseBll.Gets();
this.ddlCourse.DataSource = da;
ddlCourse.DataValueField = "ID";
ddlCourse.DataTextField = "Name";
ddlCourse.DataBind();
ddlCourse.Items.Insert(0, new ListItem("--请选择--", ""));
}

protected void ddlCourse_SelectedIndexChanged(object sender, EventArgs e)
{
//ddlCourse.Items.Remove(ddlCourse.Items.FindByText("--请选择--"));
DataSet res;
string id = this.ddlCourse.SelectedValue;
if (this.ddlCourse.SelectedIndex == 0)
{
res = fillbleanproblemBll.Gets();
}
else
{
res = fillbleanproblemBll.GetByID(int.Parse(id));
}
this.GvExamin.DataSource = res;
this.GvExamin.DataBind();
string newdb = "123";
Session.Add("newdb", newdb);
this.ddlCurrentPage.Items.Clear();
for (int i = 1; i <= this.GvExamin.PageCount; i++)
{
this.ddlCurrentPage.Items.Add(i.ToString());
}
if (this.GvExamin.Rows.Count != 0)
{
this.ddlCurrentPage.SelectedIndex = this.GvExamin.PageIndex;
}
else
{
this.notxt.Text = "没有相关数据!";
}
}
protected void GvExamin_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GvExamin.PageIndex = e.NewPageIndex;
GvExamin.DataBind();
Bind();
}
protected void GvExamin_RowDataBound(object sender, GridViewRowEventArgs e)
{
this.lblCurrentPage.Text = string.Format("当前第{0}页/总共{1}页", this.GvExamin.PageIndex + 1, this.GvExamin.PageCount);
//遍历所有行设置边框样式
foreach (TableCell tc in e.Row.Cells)
{
tc.Attributes["style"] = "border-color:Black";
}
//用索引来取得编号
if (e.Row.RowIndex != -1)
{
int id = GvExamin.PageIndex * GvExamin.PageSize + e.Row.RowIndex + 1;
e.Row.Cells[0].Text = id.ToString();
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
//鼠标移动到每项时颜色交替效果
e.Row.Attributes.Add("OnMouseOut", "this.style.backgroundColor='White';this.style.color='#003399'");
e.Row.Attributes.Add("OnMouseOver", "this.style.backgroundColor='#bfe2ff';this.style.color='#8C4510'");
e.Row.Attributes["style"] = "Cursor:hand";
}
//如果是绑定数据行
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
{
((LinkButton)e.Row.Cells[6].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除吗?')");
}
}
}
protected void ddlCurrentPage_SelectedIndexChanged(object sender, EventArgs e)
{
this.GvExamin.PageIndex = this.ddlCurrentPage.SelectedIndex;
Bind();
if (Session["newdb"] == "123")
{
ddlCourse_SelectedIndexChanged(sender, e);
}
}
protected void lnkbtnFrist_Click(object sender, EventArgs e)
{
this.GvExamin.PageIndex = 0;
Bind();
if (Session["newdb"] == "123")
{
ddlCourse_SelectedIndexChanged(sender, e);
}
}
protected void lnkbtnPre_Click(object sender, EventArgs e)
{
if (this.GvExamin.PageIndex > 0)
{
this.GvExamin.PageIndex = this.GvExamin.PageIndex - 1;
Bind();
if (Session["newdb"] == "123")
{
ddlCourse_SelectedIndexChanged(sender, e);
}
}
}
protected void lnkbtnNext_Click(object sender, EventArgs e)
{
if (this.GvExamin.PageIndex < this.GvExamin.PageCount)
{
this.GvExamin.PageIndex = this.GvExamin.PageIndex + 1;
Bind();
if (Session["newdb"] == "123")
{
ddlCourse_SelectedIndexChanged(sender, e);
}
}
}
protected void lnkbtnLast_Click(object sender, EventArgs e)
{
this.GvExamin.PageIndex = this.GvExamin.PageCount;
Bind();
if (Session["newdb"] == "123")
{
ddlCourse_SelectedIndexChanged(sender, e);
}
}
protected void GvExamin_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int ID = Convert.ToInt32(GvExamin.DataKeys[e.RowIndex].Value.ToString());
int res = fillbleanproblemBll.Delete(ID);
if (res > 0)
{
GvExamin.EditIndex = -1;
Bind();
}
}
}
添加页面:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using JH.Game.ServiceLibrary.Bll;
using JH.Game.ServiceLibrary.Model;
using System.Data;
public partial class Manage_Examin_FillBlankAdd : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bind1();
}
}
public void Bind1()
{
CourseBll courseBll = new CourseBll();
DataSet da = courseBll.Gets();
this.ddlCourse.DataSource = da;
this.ddlCourse.DataValueField = "ID";
this.ddlCourse.DataTextField = "Name";
this.ddlCourse.DataBind();
ddlCourse.Items.Insert(0, new ListItem("--请选择--", ""));
}
protected void btnSave_Click(object sender, EventArgs e)
{
FillBlankProblem param = new FillBlankProblem();
FillBlankProblemBll fillblankProblemBll = new FillBlankProblemBll();
int id = Convert.ToInt32(this.ddlCourse.SelectedValue);
param.FrontTitle = txtFrontTitle.Text.ToString();
param.Answer = txtAnswer.Text.ToString();
param.CourseID = id;
int res = fillblankProblemBll.Add(param);
if (res > 0)
{
MessageBox.Show(this.btnSave, "添加成功");
this.txtFrontTitle.Text = "";
this.txtAnswer.Text = "";
}
else
{
MessageBox.Show(this.btnSave, "添加失败");
Bind1();

}
}
protected void btnClen_Click(object sender, EventArgs e)
{
this.txtFrontTitle.Text = "";
this.txtAnswer.Text = "";
}
protected void ddlCourse_SelectedIndexChanged(object sender, EventArgs e)
{
ddlCourse.Items.Remove(ddlCourse.Items.FindByText("--请选择--"));
}
}
  • 4楼网友:佘樂
  • 2021-03-31 20:36
public void Bind()
{
this.selectStr = "select * from RoomType "; ;
this.sqlConnection = new SqlConnection(HotelSystem.Connection.ConnString);
try
{
if (this.sqlConnection.State == ConnectionState.Closed)
this.sqlConnection.Open();
DataSet ds = new DataSet();
SqlDataAdapter sda = new SqlDataAdapter(selectStr, sqlConnection);
sda.Fill(ds);
int i;
for (i = 0; i < ds.Tables[0].Rows.Count; i++)
{
dataGridView1.Rows.Add();
dataGridView1.Rows[i].Cells[0].Value = ds.Tables[0].Rows[i]["RoomType"].ToString();
dataGridView1.Rows[i].Cells[1].Value = ds.Tables[0].Rows[i]["Area"].ToString();
dataGridView1.Rows[i].Cells[2].Value = ds.Tables[0].Rows[i]["Bed"].ToString();
dataGridView1.Rows[i].Cells[3].Value = ds.Tables[0].Rows[i]["Price"].ToString();
dataGridView1.Rows[i].Cells[4].Value = ds.Tables[0].Rows[i]["AC"].ToString();
dataGridView1.Rows[i].Cells[5].Value = ds.Tables[0].Rows[i]["TV"].ToString();
dataGridView1.Rows[i].Cells[6].Value = ds.Tables[0].Rows[i]["Phone"].ToString();
dataGridView1.Rows[i].Cells[7].Value = ds.Tables[0].Rows[i]["BR"].ToString();
}
}
catch (System.Exception E)
{
Console.WriteLine(E.ToString());
this.sqlConnection.Close();
}
finally
{
this.sqlConnection.Close();
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
try
{
if (this.sqlConnection2.State == ConnectionState.Closed)
this.sqlConnection2.Open();
this.sqlCommand1.ExecuteNonQuery();
MessageBox.Show("新建成功!");
Bind();
}catch()
{
return;
}
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯