Jquery+ajax请求data显示在GridView上(asp.net)_jquery
程序员文章站
2024-01-12 21:32:28
...
AJAXLoadProgressForm.aspx:
GetGridViewByConditionForm.aspx:
protected void Page_Load(object sender, EventArgs e)
{
if (Request["id"] != null)
{
SqlConnection conn=null;
SqlCommand cmd = null;
SqlDataAdapter adapter = null;
try
{
conn = new SqlConnection();
conn.ConnectionString = ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
conn.Open();
cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
String cmdStr = "select * from dbo.Customers";
if (Request["id"].ToString()!=String.Empty)
{
cmdStr += " where CustomerID= '" + Request["id"].ToString() + "'";
}
cmd.CommandText = cmdStr;
adapter = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adapter.Fill(ds);
this.gvData.DataSource = ds;
this.gvData.DataBind();
}
catch
{
Response.Write("Error happend!");
Response.Flush();
Response.End();
}
finally
{
if (adapter != null)
{
adapter.Dispose();
}
if (cmd != null)
{
cmd.Dispose();
}
if ((conn != null) && (conn.State == ConnectionState.Open))
{
conn.Close();
}
}
}
}
复制代码 代码如下:
GetGridViewByConditionForm.aspx:
复制代码 代码如下:
protected void Page_Load(object sender, EventArgs e)
{
if (Request["id"] != null)
{
SqlConnection conn=null;
SqlCommand cmd = null;
SqlDataAdapter adapter = null;
try
{
conn = new SqlConnection();
conn.ConnectionString = ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
conn.Open();
cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
String cmdStr = "select * from dbo.Customers";
if (Request["id"].ToString()!=String.Empty)
{
cmdStr += " where CustomerID= '" + Request["id"].ToString() + "'";
}
cmd.CommandText = cmdStr;
adapter = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adapter.Fill(ds);
this.gvData.DataSource = ds;
this.gvData.DataBind();
}
catch
{
Response.Write("Error happend!");
Response.Flush();
Response.End();
}
finally
{
if (adapter != null)
{
adapter.Dispose();
}
if (cmd != null)
{
cmd.Dispose();
}
if ((conn != null) && (conn.State == ConnectionState.Open))
{
conn.Close();
}
}
}
}
上一篇: Nginx环境停Php安装