aspgridview绑定mysql,webform 中Gridview绑定sql数据库,怎么实时刷新

webform 中Gridview绑定sql数据库,如何实时刷新?

功能介绍:Gridview是绑定sql中“学生信息”表的,现在我可以通过新建→插入来影响表中的内容,但是插入之后页面中Gridview中数据没有显示。

请问:如何单击“插入”按钮就可以实时展示表中内容?

页面形式:

14405719.jpg

布局代码:

html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

DataKeyNames="学号" DataSourceID="SqlDataSource1">

SortExpression="学号" />

ConnectionString=""

SelectCommand="SELECT * FROM [学生信息]">

Visible="False" />

后台代码:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data.SqlClient;

using System.Data;

namespace WebApplication15

{

public partial class WebForm1 : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

string str = "server=.;database=学生信息管理系统;uid=sa;pwd=***";

SqlConnection conn;

conn = new SqlConnection(str);

conn.Open();

if (conn.State == ConnectionState.Open)

{

Label1.Text = "连接成功";

}

/* SqlCommand cmd = new SqlCommand("select * from dbo.学生信息", conn);

SqlDataAdapter sda = new SqlDataAdapter();

sda.SelectCommand = cmd;

DataSet ds = new DataSet();

sda.Fill(ds, "cs");

GridView1.DataSource = ds.Tables[0]; */

}

protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)

{

}

protected void Button1_Click(object sender, EventArgs e)

{

Label2.Visible = true; Label3.Visible = true; Label4.Visible = true; Label5.Visible = true; Label6.Visible = true;

TextBox1.Visible = true; TextBox2.Visible = true; TextBox3.Visible = true; TextBox4.Visible = true; TextBox5.Visible = true;

Button2.Visible = true;

}

protected void Button2_Click(object sender, EventArgs e)

{

string str = "server=.;database=学生信息管理系统;uid=sa;pwd=***";

SqlConnection conn;

conn = new SqlConnection(str);

conn.Open();

SqlCommand cmd= new SqlCommand("Insert into 学生信息 (学号,姓名,年级,名次,性别)   values(  '"+TextBox1.Text+"','"+TextBox2.Text+"','"+TextBox3.Text+"','"+TextBox4.Text+"','"+TextBox5.Text+"')", conn);

cmd.ExecuteNonQuery();

}

}

}

------解决思路----------------------

在你插入完信息的这个操作后面再绑定GridView一次,

相当于每次操作后都绑定它一次就OK了

14405720.gif

------解决思路----------------------

ajax定时器 SignalR websocket..

------解决思路----------------------

重新绑定数据……

------解决思路----------------------

在Page_Load里面调用绑定的事件,每次页面刷新,数据就刷新了,

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值