[VB.NET] GridView avec une datatable stockée en cache
Bonjour,
J'ai une gridview avec plusieurs champs TemplateField pour les modifier.
J'utilise une datatable stockée dans le cache pour alimenter ma gridview.
Ma datatable se remplit correctement = 3 lignes par exemple.
Mais lorsque j'essaie de la lier à la gridview, celle-ci ne m'affiche que la dernière ligne ?! Les 2 premières n'apparaîssent pas :(
Avez-vous une idée ?
Pour vous aider voici mon code :
GridView :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| <asp:GridView ID="gvwCategories" runat="server" AutoGenerateColumns="False" AllowPaging="true" CellPadding="4" DataKeyNames="IDCAT">
<Columns>
<asp:BoundField HeaderText="Désignation" DataField="DESIGNATION"/>
<asp:TemplateField HeaderText="Client">
<ItemTemplate>
<asp:TextBox ID="txtClient" Text='<%#DataBinder.Eval(Container.DataItem,"CLIENT")%>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Seuil">
<ItemTemplate>
<asp:TextBox ID="txtSeuil" Text='<%#DataBinder.Eval(Container.DataItem,"SEUIL")%>' runat="server" MaxLength="3" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Coefficient">
<ItemTemplate>
<asp:TextBox ID="txtCoefficient" Text='<%#DataBinder.Eval(Container.DataItem,"COEFFICIENT")%>' runat="server" MaxLength="3" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView> |
Voici ma datatable :
Code:
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
|
Dim dttCategories As New DataTable
dttCategories = Cache.Get("dttCat" & Session.SessionID)
'Si les données sont chargées pour la première fois
If insertData = True Then
Dim myDataRow As DataRow
Dim myCon As New clsDatabase("MABASE")
Dim dtsCategories As DataSet = myCon.createDataSet("SELECT * FROM CATEGORIE ORDER BY DESIGNATION", "tabCat")
Dim dtvCatRef As DataView = dtsCategories.Tables("tabCat").DefaultView
'On complète la dataTable en fonction des catégories sélectionnées
For Each myItem As ListItem In chlCategories.Items
'Si la catégorie est sélectionnée
If myItem.Selected = True Then
'1. On vérifie qu'elle n'existe pas dans la datable
Dim dtvCatSel As DataView = dttCategories.DefaultView
dtvCatSel.RowFilter = "IDCAT = '" & myItem.Value & "'"
'Si elle n'existe pas, on l'ajoute à la DataTable
If dtvCatSel.Count = 0 Then
'2. On ajoute la catégorie à la DataTable
dtvCatRef.RowFilter = "IDCAT = '" & myItem.Value & "'"
For Each myRow As DataRowView In dtvCatRef
myDataRow = dttCategories.NewRow
myDataRow("IDCAT") = myRow("IDCAT")
myDataRow("DESIGNATION") = myRow("DESIGNATION")
myDataRow("SEUIL") = myRow("SEUIL")
myDataRow("COEFFICIENT") = myRow("COEFFICIENT")
dttCategories.Rows.Add(myDataRow)
Next
End If
End If
Next
Cache.Insert("dttCat" & Session.SessionID, dttCategories)
End If
gvwCategories.DataSource = dttCategories
gvwCategories.DataBind() |
Voilà. J'espère que vous pourrez m'aider. Merci. :hola: