请告诉我如何将数据集绑定到gridview
string indno = dsRasisePo.Tables[0].Rows[0]["indno"].ToString();
for (int i = 0; i < arry.Count; i++)
{
string prodid = arry[i].ToString();
string tid = RaisePurOrder.GetTid(indno, prodid);
Dataset dsQuotation=RaisePurOrder.Bindquotation(tid);
}
gvSelectQuotation.DataSource = dsQuotation;
gvSelectQuotation.DataBind();
缩进不是常见的只是因为我给了我想要通过数组计数循环它并传递函数我可能在数据集中获得多行现在问题是只有最后一行数据集是绑定在gridview但剩余的行还没有绑定
答案 0 :(得分:3)
那么,这将概述如何将数据与数据集绑定到网格视图....
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string connectionString = “server=SYS2;” + “integrated security=SSPI;” +
“database=ERPFinAccounting”;
SqlConnection myConnection;
string str_Account_Select = “SELECT * FROM AccountsTable”;
SqlCommand myCommand;
DataSet myDataSet;
myConnection = new SqlConnection(connectionString);
myConnection.Open();
myCommand = new SqlCommand(str_Account_Select, myConnection);
SqlDataAdapter mySQLDataAdapter;
myDataSet = new DataSet();
mySQLDataAdapter = new SqlDataAdapter(myCommand);
mySQLDataAdapter.Fill(myDataSet, “AccountsTable”);
GridView1.DataSource = myDataSet;
GridView1.DataBind();
}
}
我希望它会帮助你