SelectedValue de mon gridView vide
Bonjour,
J'ai un problème qui m'échappe avec mon GridView.
Lorsque je sélectionne une ligne de celui ci la valeur noLIEU qui est l'ID de chaque objet et qui est dans DataKeyName du GridView est vide.
De plus, ensuite j'obtiens la valeur de l'ID de la première ligne sur laquelle j'ai cliqué en cliquant sur une autre et ainsi de suite, tout est décalé.
Voici mes codes :
PAGE ADMINLIEU.ASPX
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 47 48
| <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="AdminLieu.aspx.vb" Inherits="QPO.AdminLieu" MasterPageFile="~/MasterPage.master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="cp1" Runat="Server">
<u><b>Liste des lieux :</b></u> <br /><br />
<font size="1">
Le champs marqués d'une étoile sont obligatoire.<br />
</font><br />
<font size="2">
<asp:Gridview ID="gv_lieu" Runat="server" Width="545px" Height="175px"
AutoPostBack="True" AutoGenerateColumns="False" DataKeyNames="noLIEU"
AllowPaging="True" PageSize="5" GridLines="Vertical">
<Columns>
<asp:BoundField DataField="noLIEU" HeaderText="ID" />
<asp:BoundField DataField="descriptionLIEU" HeaderText="Description" />
<asp:BoundField DataField="lienLIEU" HeaderText="Lien" />
<asp:BoundField DataField="descriptionREGION" HeaderText="Région" />
<asp:CommandField ShowSelectButton="True" />
</Columns>
<SelectedRowStyle BackColor="#446573" />
</asp:Gridview>
</font>
<br />
<table>
<tr>
<td><font size="2">Description*:</font></td>
<td><asp:TextBox ID="TBDesc" runat="server" style="width:250px; Height:auto; margin-left:15px"></asp:TextBox></td>
</tr>
<tr>
<td><font size="2">Lien*:</font></td>
<td><asp:TextBox ID="TBLien" runat="server" style="width:250px; Height:auto; margin-left:15px"></asp:TextBox></td>
</tr>
<tr>
<td><font size="2">Région*:</font></td>
<td><asp:DropDownList ID="DDLReg" runat="server" style="width:250px; Height:auto; margin-left:15px"></asp:DropDownList></td>
</tr>
</table>
<br />
<asp:Button ID="btn_addUser" runat="server" Text="Ajouter" Style="margin-left:15px" />
<asp:Button ID="btn_updateUser" runat="server" Text="Mettre à jour" Style="margin-left:15px" />
<asp:Button ID="btn_deleteUser" runat="server" Text="Supprimer" Style="margin-left:15px" /> <br /> <br />
<asp:Button ID="btn_saveAction" runat="server" Text="Sauvegarder" Style="margin-left:15px" />
<asp:Button ID="btn_cancel" runat="server" Text="Annuler" Style="margin-left:15px" /> <br /> <br />
</asp:Content> |
CODE SOURCE VB
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 47 48 49 50 51 52 53 54 55 56 57 58
| Public Partial Class AdminLieu
Inherits System.Web.UI.Page
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Actualiser()
End If
End Sub
Private Sub Actualiser()
Dim lieu As New sw_Lieu.Lieu
Dim region As New sw_Region.Region()
DDLReg.DataSource = region.GetListeRegion
DDLReg.DataValueField = "noREGION"
DDLReg.DataTextField = "descriptionREGION"
DDLReg.DataBind()
DDLReg.Items.Insert(0, "")
gv_lieu.DataSource = lieu.GetListeLieu()
gv_lieu.DataBind()
End Sub
Private Sub gv_lieu_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gv_lieu.PageIndexChanging
gv_lieu.PageIndex = e.NewPageIndex
Actualiser()
End Sub
Private Sub gv_lieu_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gv_lieu.RowCreated
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(sender, "Select$" & e.Row.RowIndex.ToString))
End If
End Sub
Private Sub gv_lieu_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles gv_lieu.SelectedIndexChanging
Dim lieu As New sw_Lieu.Lieu
Dim ds As New DataSet
ds = lieu.GetLieu(gv_lieu.DataKeys(0).Item("noLIEU"))
TBDesc.Text = gv_lieu.SelectedValue
'TBDesc.Text = ds.Tables(0).Rows(0).Item("descriptionLIEU")
'TBLien.Text = ds.Tables(0).Rows(0).Item("descriptionLIEU")
'DDLReg.SelectedValue = ds.Tables(0).Rows(0).Item("descriptionREGION")
Actualiser()
End Sub
End Class |