[英]Gridview table not being displayed in asp.net webform
我只想显示一些特定查询的gridview。 我在下面尝试过。 当在查询中传递了错误的参数时,此代码显示“没有数据匹配”,但是即使参数正确也不显示任何内容。 我是asp.net的新手。请告诉我,什么重要的行,我不见了
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewState["Filter"] = "ALL";
BindGrid();
}
}
private void BindGrid()
{
DataTable dt = new DataTable();
String strConnString = System.Configuration.ConfigurationManager.ConnectionStrings["NorthwindConnectionString1"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
SqlDataAdapter sda = new SqlDataAdapter();
string query = "SELECT ContactName, City, Country, PostalCode FROM Customers";
SqlCommand cmd = new SqlCommand("SELECT ContactName, City, Country, PostalCode FROM Customers WHERE Country='UK'" );
cmd.Connection = con;
sda.SelectCommand = cmd;
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.