Total records in gridview
Hej jeg har problemer med at lave så jeg kan tælle alle records i mit gridview og få det vist i en labelher er kode til gridviewet:
// Create Sql Command and execute it whit MyReader
SqlCommand myCommand = new SqlCommand("SELECT SN, WhoInScan, DTIn, StockStatus, Type FROM TblInOut WHERE StockStatus = 'In stock' ORDER BY DTIn DESC", myConnection);
MyReader = myCommand.ExecuteReader();
DataTable dt = new DataTable(); // table to hold each record
dt.Columns.Add(new DataColumn("Serial NO.", typeof(string))); // Create a string column dynamically
dt.Columns.Add(new DataColumn("Type", typeof(string))); // Create a string column dynamically
dt.Columns.Add(new DataColumn("Who", typeof(string))); // Create a string column dynamically
dt.Columns.Add(new DataColumn("Date/Time", typeof(string))); // Create a string column dynamically
dt.Columns.Add(new DataColumn("Stock Status", typeof(string))); // Create a string column dynamically
while (MyReader.Read())
{
DataRow dr = dt.NewRow(); // create a row object of table's type defined above
dr["Serial NO."] = MyReader[0].ToString();
dr["Type"] = MyReader[4].ToString();
dr["Who"] = MyReader[1].ToString();
dr["Date/Time"] = MyReader[2].ToString();
dr["Stock Status"] = MyReader[3].ToString();
dt.Rows.Add(dr);// add the row to the table
}
//Close MyReader
MyReader.Close();
/**/
// get data into the gridview
gvResults.DataSource = dt.DefaultView;
gvResults.DataBind();
gvResults.Visible = true;
/**/