Dou*_*cil 6 asp.net data-binding gridview
我有一个Windows aspx表单,我有一个TextBox,Button和一个GridView.将TextBox被存储为变量@subschedule并传递到一个存储过程.我想做的是将该程序的结果填充到我的程序中GridView.有谁能建议这样做的方法?
谢谢
您需要使用该DataSource属性:
DataTable dt = new DataTable();
// Open the connection
using (SqlConnection cnn = new SqlConnection(
"Data Source=.\sqlexpress;Initial Catalog=AcmeRentals;Integrated Security=True"))
{
cnn.Open();
// Define the command
using (SqlCommand cmd = new SqlCommand())
{
cmd.Connection = cnn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = storedProcedureName;
// Define the data adapter and fill the dataset
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
da.Fill(dt);
}
}
}
// This is the key code; you can set the DataSource to "collection"
gridView.DataSource = dt.DefaultView;
gridView.DataBind();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18687 次 |
| 最近记录: |