我有这个C#函数返回一个列表,该函数存在于.dll文件中。如何在ASPX页面上显示列表。我是ASP.Net的新手并尝试将其绑定到网格但它不起作用。
public static List<string>[] Select()
{
server = "localhost";
database = "cdl";
uid = "root";
password = "password";
string connectionString;
connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
connection = new MySqlConnection(connectionString);
connection.Open();
string query = "SELECT * FROM caleiddevice";
//Create a list to store the result
List<string>[] list = new List<string>[3];
list[0] = new List<string>();
list[1] = new List<string>();
list[2] = new List<string>();
//Open connection
// if (this.OpenConnection() == true)
// {
//Create Command
MySqlCommand cmd = new MySqlCommand(query, connection);
//Create a data reader and Execute the command
MySqlDataReader dataReader = cmd.ExecuteReader();
// MySqlDataAdapter myDataAdapter = new MySqlDataAdapter(query, connection);
//Read the data and store them in the list
while (dataReader.Read())
{
list[0].Add(dataReader["device_id"] + "");
list[1].Add(dataReader["status"] + "");
list[2].Add(dataReader["timestamp"] + "");
}
//close Data Reader
dataReader.Close();
//close Connection
// this.CloseConnection();
//return list to be displayed
return list;
//}
//else
//{
// return list;
// }
}
答案 0 :(得分:0)
If (!IsPostBack)
{
gridView1.DataSource=select();
gridView1.DataBind();
}
把它放在页面加载中,它可以正常工作