private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
string ACconnStr="server=XCH;uid=sa;pwd=;database=aaa";//定义数据库连接字符串
SqlConnection ACconn=new SqlConnection(ACconnStr); //创建连接对像
SqlCommand ACcomm=new SqlCommand(ACsql,ACconn);//创建Command对像
try
{
ACconn.Open();//打开连接
mysql = "Select id,name,sex,class,tel ,email from Table1";
//设置SQL语句,即查询数据库中所有内容
mycmd.Fill(dt);
//填充数据,即在内存中生成DataSet模型数据库
DataGrid1.DataSource = dt.Tables(0);
//为DataGrid1控件指定数据源
DataGrid1.DataBind();
//执行绑定
}
catch
{
Response.Write("程序出错,信息描述如下:<br>" & ex.Message);
Finally
ACconn.Close();
End Try;
End Sub;
}
}private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
{
Handles DataGrid1.PageIndexChanged;
DataGrid1.CurrentPageIndex = e.NewPageIndex;
getdata();}
帮我改改 我刚学2天 谢谢啦
{
// 在此处放置用户代码以初始化页面
string ACconnStr="server=XCH;uid=sa;pwd=;database=aaa";//定义数据库连接字符串
SqlConnection ACconn=new SqlConnection(ACconnStr); //创建连接对像
SqlCommand ACcomm=new SqlCommand(ACsql,ACconn);//创建Command对像
try
{
ACconn.Open();//打开连接
mysql = "Select id,name,sex,class,tel ,email from Table1";
//设置SQL语句,即查询数据库中所有内容
mycmd.Fill(dt);
//填充数据,即在内存中生成DataSet模型数据库
DataGrid1.DataSource = dt.Tables(0);
//为DataGrid1控件指定数据源
DataGrid1.DataBind();
//执行绑定
}
catch
{
Response.Write("程序出错,信息描述如下:<br>" & ex.Message);
Finally
ACconn.Close();
End Try;
End Sub;
}
}private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
{
Handles DataGrid1.PageIndexChanged;
DataGrid1.CurrentPageIndex = e.NewPageIndex;
getdata();}
帮我改改 我刚学2天 谢谢啦
解决方案 »
- 区域管理
- asp.net导出excel部署后无法下载的问题
- CS0135: “Str”与声明“classroom_teaching_table_list.Str”冲突
- 高手帮助!!!!!!!!很紧急的问题,asp.net如何获取客户端的登陆用户名?
- 上传小问题!散分了!!(急!急!急)
- 使用asp.net进行多关键字查询的例子
- 欢迎加入C#菜鸟学习群!
- 请问有没有ASP的微软自带中文帮助.
- 要定位在服务器某目录下,在创建一个新目录的办法???
- 各位救命了,暂时没有分了,我会补上的,在后台中定义的数组在脚本块中使用?
- asp.net中上传图片的问题
- 开发手机WAP手机网站我用Sql2005可以吗?
{
DataGrid1.PageIndex = e.NewPageIndex;
getdata();
}
{
DataGrid1.PageIndex = e.NewPageIndex;
getdata();
}
public void getdata()
{
string ACconnStr= "server=XCH;uid=sa;pwd=;database=aaa ";//定义数据库连接字符串
SqlConnection ACconn=new SqlConnection(ACconnStr); //创建连接对像
SqlCommand ACcomm=new SqlCommand(ACsql,ACconn);//创建Command对像
try
{
ACconn.Open();//打开连接
mysql = "Select id,name,sex,class,tel ,email from Table1 ";
//设置SQL语句,即查询数据库中所有内容
mycmd.Fill(dt);
//填充数据,即在内存中生成DataSet模型数据库
DataGrid1.DataSource = dt.Tables(0);
//为DataGrid1控件指定数据源
DataGrid1.DataBind();
}
其他的没什么问题;
{
}
public void getdata()
{
string ACconnStr= "server=XCH;uid=sa;pwd=;database=aaa ";
SqlConnection ACconn=new SqlConnection(ACconnStr);
SqlCommand ACcomm=new SqlCommand(ACsql,ACconn);
try
{
ACconn.Open();
mysql = "Select id,name,sex,class,tel ,email from Table1 ";
SqlDataAdapter sda = new SqlDataAdapter(s_strsql, conn);
DataSet Dts_Job = new DataSet();
sda.Fill(Dts_Job, "Table1");
DataGrid1.DataSource = Dts_Job.Tables(0); DataGrid1.DataBind();
} protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
DataGrid1.PageIndex = e.NewPageIndex;
getdata();
}
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.Data.Sql;
using System.Data.SqlClient;
using System.Text;public partial class Infomation : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
getdata();
}
public void getdata()
{
string ACconnStr= "server=XCH;uid=sa;pwd=;database=aaa ";
SqlConnection ACconn=new SqlConnection(ACconnStr);
SqlCommand ACcomm=new SqlCommand(ACsql,ACconn);
try
{
ACconn.Open();
mysql = "Select id,name,sex,class,tel ,email from Table1 ";
SqlDataAdapter sda = new SqlDataAdapter(s_strsql, conn);
DataSet Dts_Job = new DataSet();
sda.Fill(Dts_Job, "Table1");
DataGrid1.DataSource = Dts_Job.Tables(0); DataGrid1.DataBind();
} protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
DataGrid1.PageIndex = e.NewPageIndex;
getdata();
}
}
直接覆盖吧……
private void Page_Load(object sender, System.EventArgs e)
{
string ACconnStr= "server=XCH;uid=sa;pwd=;database=aaa ";
SqlConnection ACconn=new SqlConnection(ACconnStr);
SqlCommand ACcomm=new SqlCommand(ACsql,ACconn);
DataTable dt = new DataTable();
try
{
ACconn.Open();
mysql = "Select id,name,sex,class,tel ,email from Table1 ";
mycmd.Fill(dt);
DataGrid1.DataSource = dt.Tables(0);
DataGrid1.DataBind();
}
catch
{
Response.Write( "程序出错,信息描述如下: <br> " & ex.Message);
Finally
ACconn.Close();
End Try;
End Sub;
}
} private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
getdata();
}
<asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 144px; POSITION: absolute; TOP: 112px"
runat="server" Width="331px" Height="152px" PageSize="5" AllowPaging="True" BorderColor="#CCCCCC"
BorderStyle="None" BorderWidth="1px" BackColor="White" CellPadding="3">
<FooterStyle ForeColor="#000066" BackColor="White"></FooterStyle>
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#669999"></SelectedItemStyle>
<ItemStyle ForeColor="#000066"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White" BackColor="#006699"></HeaderStyle>
<PagerStyle HorizontalAlign="Left" ForeColor="#000066" BackColor="White" Mode="NumericPages"></PagerStyle>
</asp:DataGrid>
)
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.Data.Sql;
using System.Data.SqlClient;
using System.Text; namespace WebApplication7
{
/// <summary>
/// WebForm2 的摘要说明。
/// </summary>
public class WebForm2 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
getdata();
}
public void getdata()
{
string ACconnStr= "server=XCH;uid=sa;pwd=;database=aaa ";
SqlConnection ACconn=new SqlConnection(ACconnStr);
SqlCommand ACcomm=new SqlCommand(ACsql,ACconn);
try
{
ACconn.Open();
mysql = "Select id,name,sex,class,tel ,email from Table1 ";
SqlDataAdapter sda = new SqlDataAdapter(s_strsql, conn);
DataSet Dts_Job = new DataSet();
sda.Fill(Dts_Job, "Table1");
DataGrid1.DataSource = Dts_Job.Tables(0); DataGrid1.DataBind();
}
catch{}
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.DataGrid1.SelectedIndexChanged += new System.EventHandler(this.DataGrid1_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
DataGrid1.PageIndex = e.NewPageIndex;
getdata();
} }
}
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.Data.Sql;
using System.Data.SqlClient;
using System.Text; namespace WebApplication7
{
public class WebForm2 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1; private void Page_Load(object sender, System.EventArgs e)
{
getdata();
}
public void getdata()
{
string ACconnStr= "server=XCH;uid=sa;pwd=;database=aaa ";
SqlConnection ACconn=new SqlConnection(ACconnStr); ACconn.Open();
string mysql = "Select id,name,sex,class,tel ,email from Table1 ";
SqlDataAdapter sda = new SqlDataAdapter(mysql, ACconn);
DataSet Dts_Job = new DataSet();
sda.Fill(Dts_Job, "Table1");
DataGrid1.DataSource = Dts_Job;DataGrid1.DataBind();
} protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
DataGrid1.PageIndex = e.NewPageIndex;
getdata();
} }
}
{
DataGrid1.DataSource = GetSql();
DataGrid1.DataBind();
}
protected DataTable GetSql()
{
string sqlConnStr = "server=XCH;uid=sa;pwd=;database=aaa ";//定义数据库连接字符串
string strSql = "select [id],[name],[sex],[class],[tel],[email] from Table1";
DataTable aTable = new DataTable();
using (SqlConnection sqlConn = new SqlConnection(sqlConnStr))//using 自动会关闭连接
{
using (SqlCommand sqlComm = new SqlCommand(strSql, sqlConn))
{
try
{
sqlConn.Open();
SqlDataAdapter sda = new SqlDataAdapter(sqlComm);
sda.Fill(aTable);
}
catch (SqlException e)
{
throw new Exception(string.Format("程序出错,信息描述如下: <br> {0}", e.Message));
}
}
}
return aTable;
} protected void DataGrid1_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
GetSql();
}
这才是分页。 从新点击一下事件。
Sql在System.Data不存在
找不到类型或命名空间
GridViewPageEventArgs