Bonjour à tous,

Je dois reprendre un site existant et le modifier, actuellement je travaille sur un gridview qui affiche des éléments. J'aimerais qu'il soit triable en cliquant sur l'entête de la colonne.

J'ai trouvé qu'il fallait mettre je l'ai fais mais ça n'a rien donné.

Vu qu'il y a déjà pas mal de choses dans la balise ouvrante du gridview il y a surement quelque chose qui parasite cette propriété.

Code asp : 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
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ListeTicket.ascx.cs" Inherits="ListeTicket" %>
<asp:GridView ID="GV_LISTETIC" runat="server" AllowPaging="False" AutoGenerateColumns="False"
    HorizontalAlign="Center" OnRowDataBound="GridView1_RowDataBound" Width="800px" Height="136px" 
	OnPageIndexChanging="GV_LISTETIC_PageIndexChanging" OnDataBound="GV_LISTETIC_DataBound" allowsorting="true" 
	EnableSortingAndPagingCallbacks="True" PageSize="150">
    <Columns>
        <asp:BoundField DataField="Coul_Prio" />
        <asp:BoundField DataField="ID_TIC">
            <ControlStyle Width="40px" />
            <ItemStyle HorizontalAlign="Center" Width="30px" Font-Size="Small" />
            <HeaderStyle BackColor="Silver" HorizontalAlign="Center" />
        </asp:BoundField>
...
      </Columns>
    <PagerSettings PageButtonCount="150" />
</asp:GridView>

et si besoin, mon ListeTicket.ascx.cs

Code C# : 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
 
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
 
public partial class ListeTicket : System.Web.UI.UserControl
{
 
    public string Tech,Etat;
    protected void Page_Load(object sender, EventArgs e)
    {
        cmTicket MonTicket = new cmTicket();
        if (Etat == "O")
        {
            if (Tech == "all")
            {
                GV_LISTETIC.DataSource = MonTicket.ListeTicketEnCours();
            }
 
        }
        else
        {
            if (Tech == "all")
            {
                GV_LISTETIC.DataSource = MonTicket.ListeTicket();
            }
 
        }
        GV_LISTETIC.DataBind();
        MonTicket.FermerConnexion();
    }
 
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
 
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            cmTicket monTicket = new cmTicket();
            e.Row.Cells[6].Text = "<b>" + monTicket.NbSuivi(int.Parse(e.Row.Cells[1].Text)) + "</b>";
            if (GV_LISTETIC.Columns[5].Visible)
            {
 
 
                string Resp = e.Row.Cells[5].Text;
                if (Resp == "-1")
                {
                    e.Row.Cells[5].Text = "<b>Non Attribué!</b>";
                }
                if (monTicket.GetResp(int.Parse(e.Row.Cells[1].Text)) == "-1")
                {
 
                    e.Row.Cells[1].Text = "<img src='img/warning.gif' alt='Aucun responsable pour ce ticket!'> " + e.Row.Cells[1].Text;
                }
 
            }
            else
            {
 
 
                if (monTicket.GetResp(int.Parse(e.Row.Cells[1].Text)) == "-1")
                {
 
                    e.Row.Cells[1].Text = "<img src='img/warning.gif' alt='Aucun responsable pour ce ticket!'> " + e.Row.Cells[1].Text;
                }
 
            }
 
 
 
            string Desc = e.Row.Cells[3].Text;
            if (Desc.Length > 150)
            {
                e.Row.Cells[3].Text = Desc.Substring(0, 150) + "...";
            }
            e.Row.BackColor = GetColor(e.Row.Cells[0].Text);
            e.Row.Cells[7].BackColor = GetColor(e.Row.Cells[0].Text);
 
        }
 
    }
    protected Color GetColor(string color)
    {
 
        int R = int.Parse(color.Substring(1, 2), System.Globalization.NumberStyles.HexNumber);
        int G = int.Parse(color.Substring(3, 2), System.Globalization.NumberStyles.HexNumber);
        int B = int.Parse(color.Substring(5, 2), System.Globalization.NumberStyles.HexNumber);
        Color Ocolor = Color.FromArgb(R, G, B);
        return Ocolor;
    }
    protected void GV_LISTETIC_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GV_LISTETIC.PageIndex = e.NewPageIndex;
        GV_LISTETIC.DataBind();
 
    }
    protected void GV_LISTETIC_DataBound(object sender, EventArgs e)
    {
        GV_LISTETIC.Columns[0].Visible = false;
        GV_LISTETIC.Columns[7].ItemStyle.BackColor = Color.Gainsboro;
    }
 
}