J'ia finalement réussi a peupler mon datagrid cependant depuis un ou deux jours j'essaie de modifier la largeur des colonne ainsi que le text sur la premiere ligne.(qui est le nom des colonne de la db SQL)
Comme vous pouvez le voir j'ai esseyer de metre une couleur en arrière plan mais sa ne fonctionne pas.
Voici le code :
Voila j'aimerais savoir comment je peux modier la longeur des colonnes ainsi que le titre de chaque colonne.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73 using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Data.SqlClient; namespace infosalvage { /// <summary> /// Summary description for CopartCarList. /// </summary> public class CopartCarList : System.Web.UI.Page { protected System.Web.UI.WebControls.DataGrid DataGrid1; protected System.Web.UI.WebControls.Label Label1; private void Page_Load(object sender, System.EventArgs e) { string strConnexion = "Data Source=SERVER\\SQLSERVER;user id=SERVER\\USERNAMEWIN;Integrated Security=SSPI;"+"Initial Catalog=DBNAME;password=PASSWORD"; SqlConnection oConnection = new SqlConnection(strConnexion); SqlDataAdapter CopListDataAdapter = new SqlDataAdapter("SELECT item, auctid, lot, year, make, model, vin, odo FROM vehcopart",strConnexion); try { oConnection.Open(); Label1.Text = "There is the car listing for copart."; } catch (Exception ex) { Label1.Text = "Un Problême est survenu, svp contacter l'administrateur du site internet"+ ex.ToString(); return; } DataSet CopartDataSet = new DataSet(); CopListDataAdapter.Fill(CopartDataSet,"ListingCar"); oConnection.Close(); DataGrid1.DataSource = CopartDataSet.Tables["ListingCar"]; // Mise en page du DataGrid1 DataGrid1.HeaderStyle.BackColor = Color.LightBlue; DataGrid1.HeaderStyle.HorizontalAlign = HorizontalAlign.Center; DataGrid1.HeaderStyle.Font.Bold = true; DataGrid1.BackColor = Color.LightGray; DataGrid1.DataBind(); } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load); } #endregion } }
Pour voir le résultat : http://infosalvage.wiredlinux.ca/infosalvage/
Partager