asp.net中的示例网格视图c# [英] sample grid view in asp.net c#

查看:59
本文介绍了asp.net中的示例网格视图c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>



        <asp:GridView ID="GridView1" runat="server">

        </asp:GridView>



    </div>
    </form>
</body>
</html>









c#









使用System;

使用System.Configuratio n;

使用System.Data;

使用System.Linq;

使用System.Web;

使用System.Web.Security;

使用System.Web.UI;

使用System.Web.UI.HtmlControls;

使用System.Web .UI.WebControls;

使用System.Web.UI.WebControls.WebParts;

使用System.Xml.Linq;

使用System。 Data.SqlClient;





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

{< br $>




protected void Page_Load(object sender,EventArgs e)

{

string strSQLconnection =(@Data Source = .; Initial Catalog = new; Integrated Security = True);



SqlConnection sqlConnection = new SqlConnection(strSQLconnection);



SqlCommand sqlCommand = new SqlCommand(select * from persons,sqlConnection);



sqlConnection.Open( );







SqlDataReader reader = sqlCommand.ExecuteReader();







GridView1.DataSource = reader;



GridView1.DataBind();



}





}





c#




using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;


public partial class _Default : System.Web.UI.Page
{


protected void Page_Load(object sender, EventArgs e)
{
string strSQLconnection = (@"Data Source=.;Initial Catalog=new;Integrated Security=True");

SqlConnection sqlConnection = new SqlConnection(strSQLconnection);

SqlCommand sqlCommand = new SqlCommand("select * from persons", sqlConnection);

sqlConnection.Open();



SqlDataReader reader = sqlCommand.ExecuteReader();



GridView1.DataSource = reader;

GridView1.DataBind();

}


}

推荐答案

本教程帮我创建了gridview



Asp.Net Gridview教程



Eric
This tutorial helped me to create gridview

Asp.Net Gridview tutorial

Eric


尝试此代码,如果它可以解决您的问题

或参考此链接 GridView Databinging演示 [ ^ ]



Try this code if it will solve your problem
or refer this link GridView Databinging demo[^]

string strSQLconnection = (@"Data Source=.;Initial Catalog=new;Integrated Security=True");
SqlConnection sqlConnection = new SqlConnection(strSQLconnection);
SqlCommand sqlCommand = new SqlCommand("select * from persons", sqlConnection);
sqlConnection.Open();
SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCommand);
DataTable dt = new DataTable();
sqlDa.Fill(dt);
sqlConnection.Close();
GridView1.DataSource = dt;
GridView1.DataBind();









OR

string strSQLconnection = (@"Data Source=.;Initial Catalog=new;Integrated Security=True");
SqlConnection sqlConnection = new SqlConnection(strSQLconnection);
sqlConnection.Open();
SqlDataAdapter sqlDa = new SqlDataAdapter();
sqlDa.SelectCommand.Connection = sqlConnection;
sqlDa.SelectCommand.CommandType = CommandType.Text;
sqlDa.SelectCommand.CommandText = "YOUR SELECT QUERY";
DataTable dt = new DataTable();
sqlDa.Fill(dt);
sqlConnection.Close();
GridView1.DataSource = dt;
GridView1.DataBind();


这篇关于asp.net中的示例网格视图c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆