IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

ASP.NET Discussion :

[C#] Tutoriel DataGrid (WebMatrix)


Sujet :

ASP.NET

Vue hybride

bendj [C#] Tutoriel DataGrid... 21/07/2005, 10h24
bendj C'est bon, vous pouvez me... 21/07/2005, 10h39
pmithrandir alors : deja, y a un tuto... 21/07/2005, 11h16
bendj Je cherche depuis ce matin,... 21/07/2005, 14h38
pmithrandir est ce que tu as une ligne de... 21/07/2005, 14h49
bendj J'ai : protected... 21/07/2005, 14h54
pmithrandir c lacquelle la ligne 121? 21/07/2005, 15h00
bendj La ligne 121 de quel fichier... 21/07/2005, 15h05
pmithrandir celle la : 21/07/2005, 15h08
bendj :?: :?: :?: 21/07/2005, 15h10
pmithrandir en gros, dans ton item... 21/07/2005, 15h14
bendj En fait, l'erreur se produit... 21/07/2005, 15h14
pmithrandir si tu remplace ton... 21/07/2005, 15h23
bendj Tu confonds pas le C# et le... 21/07/2005, 15h25
pmithrandir bah je pense pas, t a aussi... 21/07/2005, 15h28
bendj Tu as raison. J'ai trouvé un... 21/07/2005, 15h37
pmithrandir je t avoue que je ne sais... 21/07/2005, 15h41
bendj ItemDataBound, c'ext un... 21/07/2005, 16h05
bendj J'ai mis ça, et ce qui suit... 22/07/2005, 09h54
Nesmontou On dirait qu'il ne trouve pas... 22/07/2005, 10h02
bendj Ma page ASPX : ... 22/07/2005, 10h13
Nesmontou et l'erreur, il te la renvoie... 22/07/2005, 10h23
bendj Il me la fait après ... 22/07/2005, 10h30
pmithrandir findcontrol n'est pas une... 22/07/2005, 10h42
bendj J'ai essayé aussi ... 22/07/2005, 10h44
pmithrandir e.item(numeroDeLigne).findCont... 22/07/2005, 10h54
bendj Quand je fais : ... 22/07/2005, 10h54
Nesmontou Bon, on dirait qu'il ne... 22/07/2005, 10h55
bendj Response.Write(e.Item.Cont... 22/07/2005, 11h12
Nesmontou Peut-être qu'il faut... 22/07/2005, 11h15
Nesmontou :idea: Je viens de voir un... 22/07/2005, 11h17
bendj J'ai déjà essayé, et j'ai... 22/07/2005, 11h17
Nesmontou On s'est croisé, regarde le... 22/07/2005, 11h18
bendj OK !! Il y a du nouveau...... 22/07/2005, 11h41
pmithrandir If... 22/07/2005, 11h44
Nesmontou Quand tu bind ton datagrid,... 22/07/2005, 11h47
bendj :idea: :idea: :idea: ... 22/07/2005, 11h50
Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    59
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 59
    Par défaut [C#] Tutoriel DataGrid (WebMatrix)
    Bonjour,

    J'utilise WebMatrix, et je souhaite créer une datagrid avec des webcontrols dedans. Sur ma page aspx, j'ai mis ce qu'il y a dans la FAQ :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    <asp:DataGrid id="tabCells" runat="server">
                <Columns>
                    <asp:TemplateColumn>
                        <ItemTemplate>
                            <asp:DropDownList id="titi" runat="server"></asp:DropDownList>
                        </ItemTemplate>
                    </asp:TemplateColumn>
                </Columns>
            </asp:DataGrid>
    Je remplis la datagrid en code-behind avec :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    myAL = GenCells();
    tabCells.DataSource=myAL[0];
    tabCells.DataBind();
    Ma requete sort en réponse un seul champs. Je m'attendais à ce que ma DDL se remplisse, mais j'ai message d'erreur :
    Control 'tabCells__ctl2_titi' of type 'DropDownList' must be placed inside a form tag with runat=server.
    Au final, je pense que j'ai besoin d'un bon tutoriel, pour savoir comment créer proprement ma DataGrid, et surtout comment l'interfacer.

  2. #2
    Membre averti
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    59
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 59
    Par défaut
    C'est bon, vous pouvez me fouettez...

    WebMatrix avait placé ma DataGrid après la balise </form>, d'où le message d'erreur incomprehensible, par rapport à mon problème...

    Aussi, j'ai compris que je devais utiliser
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    DataBinder.Eval(Container.DataItem,  "MonChamps")
    Ca veut dire que je dois déclarer tous mes webcontrols dans le code-behind de ma page aspx, et ensuite leur appliquer ce bout de code ?

    Comment fait-on si on ne connait pas à l'avance le nombre de champs, et leurs noms ? (Exemple d'un DataGrid générique)

  3. #3
    Membre Expert
    Avatar de pmithrandir
    Homme Profil pro
    Responsable d'équipe développement
    Inscrit en
    Mai 2004
    Messages
    2 419
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Responsable d'équipe développement
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2004
    Messages : 2 419
    Par défaut
    alors :

    deja, y a un tuto de datagrid qui existe pour la base ;-)

    ensuite, y a pleins de post(dont quelques un de moi) avec des exemple de code de datagrid. ca devrais t aider...(oubli pas de corriger els bug, ca serais dommage)

    et pour ton truc, tu as soit des <asp:boundcollumn qui associe avec des datafield, docn que tu dois pouvoir creer dynamiquement., plus simple surement.

    t a accés a des truc avec les numeros aussi..
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    datagrid.items.item(varLigne).cells(varColonne)
    voili voilou

  4. #4
    Membre averti
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    59
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 59
    Par défaut
    Je cherche depuis ce matin, et je tourne en rond !!

    Voici le code de ma page ASPX :
    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
     
                <asp:DataGrid id="tabCells" runat="server" ShowFooter="false" onItemDataBound="dgPersonnes_ItemDataBound" AutoGenerateColumns="false">
                    <Columns>
                        <asp:TemplateColumn HeaderText="CID">
                            <ItemTemplate>
                                <asp:Label id="dgLabCID" runat="server" text='<%# DataBinder.Eval(Container.DataItem,  "cid") %>' />
                            </ItemTemplate>
                        </asp:TemplateColumn>
                        <asp:TemplateColumn HeaderText="StandardIndicator">
                            <ItemTemplate>
                                <asp:DropDownList id="dgDDLSI" runat="server" />
                            </ItemTemplate>
                        </asp:TemplateColumn>
                    </Columns>
                </asp:DataGrid>
    Et celui de mon code-behind :
    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
     
            public void ButtonIntegrer_Click(Object sender, EventArgs e){
                WebRAM toto = new WebRAM();
                ArrayList myAL = new ArrayList();
     
                myAL = toto.GenCellsCreationSite();
     
     
                tabCells.DataSource=myAL[0];
                tabCells.DataBind();
     
                //dgDDLSI.SelectedValue=DataBinder.Eval(Container.DataItem,  "StandardIndicator").ToString();
     
            }
     
            public void dgPersonnes_ItemDataBound(Object sender, System.Web.UI.WebControls.DataGridItemEventArgs e){
                WebRAM toto = new WebRAM();
                ArrayList myAL = new ArrayList();
     
                DropDownList dgDDLSI = (DropDownList)tabCells.FindControl("dgDDLSI");
                myAL=toto.GetStandardIndicator();
     
                dgDDLSI.DataSource=myAL[0];
                dgDDLSI.DataTextField=myAL[1].ToString();
                dgDDLSI.DataBind();
     
                dgDDLSI.SelectedValue = tabCells.Items[1].ToString();
     
            }
    J'ai toujours la même erreur !!
    Object reference not set to an instance of an object.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:


    [NullReferenceException: Object reference not set to an instance of an object.]
    WebRAMSES.claCreationSite.dgPersonnes_ItemDataBound(Object sender, DataGridItemEventArgs e) +121
    System.Web.UI.WebControls.DataGrid.OnItemDataBound(DataGridItemEventArgs e) +84
    System.Web.UI.WebControls.DataGrid.CreateItem(Int32 itemIndex, Int32 dataSourceIndex, ListItemType itemType, Boolean dataBind, Object dataItem, DataGridColumn[] columns, TableRowCollection rows, PagedDataSource pagedDataSource) +181
    System.Web.UI.WebControls.DataGrid.CreateControlHierarchy(Boolean useDataSource) +1130
    System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e) +48
    System.Web.UI.WebControls.BaseDataList.DataBind() +10
    WebRAMSES.claCreationSite.ButtonIntegrer_Click(Object sender, EventArgs e) +109
    System.Web.UI.WebControls.Button.OnClick(EventArgs e) +83
    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +58
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
    System.Web.UI.Page.ProcessRequestMain() +1258




    --------------------------------------------------------------------------------
    Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573
    Je ne sais plus quoi faire... Si vous pouviez me donner une piste...

    Merci.

  5. #5
    Membre Expert
    Avatar de pmithrandir
    Homme Profil pro
    Responsable d'équipe développement
    Inscrit en
    Mai 2004
    Messages
    2 419
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Responsable d'équipe développement
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2004
    Messages : 2 419
    Par défaut
    est ce que tu as une ligne de ce genre :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    protected withevents tablecells as datagrid
    en haut de ta page?

  6. #6
    Membre averti
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    59
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 59
    Par défaut
    J'ai :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    protected System.Web.UI.WebControls.DataGrid tabCells;
    Ta syntaxe est en VB.NET. Je ne trouve pas l'équivalent en C#.

  7. #7
    Membre Expert
    Avatar de pmithrandir
    Homme Profil pro
    Responsable d'équipe développement
    Inscrit en
    Mai 2004
    Messages
    2 419
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Responsable d'équipe développement
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2004
    Messages : 2 419
    Par défaut
    c lacquelle la ligne 121?

  8. #8
    Membre averti
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    59
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 59
    Par défaut
    Citation Envoyé par pmithrandir
    c lacquelle la ligne 121?
    La ligne 121 de quel fichier ? Car si c'est celui du code behind, ça ne correspond à rien.

  9. #9
    Membre Expert
    Avatar de pmithrandir
    Homme Profil pro
    Responsable d'équipe développement
    Inscrit en
    Mai 2004
    Messages
    2 419
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Responsable d'équipe développement
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2004
    Messages : 2 419
    Par défaut
    celle la :
    WebRAMSES.claCreationSite.dgPersonnes_ItemDataBound(Object sender, DataGridItemEventArgs e) +121

  10. #10
    Membre averti
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    59
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 59
    Par défaut
    : : :

  11. #11
    Membre Expert
    Avatar de pmithrandir
    Homme Profil pro
    Responsable d'équipe développement
    Inscrit en
    Mai 2004
    Messages
    2 419
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Responsable d'équipe développement
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2004
    Messages : 2 419
    Par défaut
    en gros, dans ton item databound, tu dois avoir une ligne qui deconne, la 121 je dirais...

  12. #12
    Membre averti
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    59
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 59
    Par défaut
    En fait, l'erreur se produit sur :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    dgDDLSI.DataSource=myAL[0];
    Pour lui, dgDDLSI n'est pas un objet instancié, alors qu'il l'est juste au dessus !!

    Je comprends pas...

  13. #13
    Membre Expert
    Avatar de pmithrandir
    Homme Profil pro
    Responsable d'équipe développement
    Inscrit en
    Mai 2004
    Messages
    2 419
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Responsable d'équipe développement
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2004
    Messages : 2 419
    Par défaut
    si tu remplace ton tabcell.findcontrol par :
    e.Item.FindControl

    ca marche pas mieu?

  14. #14
    Membre averti
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    59
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 59
    Par défaut
    Tu confonds pas le C# et le VB.NET ?

  15. #15
    Membre Expert
    Avatar de pmithrandir
    Homme Profil pro
    Responsable d'équipe développement
    Inscrit en
    Mai 2004
    Messages
    2 419
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Responsable d'équipe développement
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2004
    Messages : 2 419
    Par défaut
    bah je pense pas, t a aussi un parametre e, je suppose qu il sert a la meme chose quelque soit le language...

    aprés c'est peut etre aps exactement e.items.findcontrol, y a peut etre des probleme de casse entre autre, mais ca doit etre dans le genre...

  16. #16
    Membre averti
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    59
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 59
    Par défaut
    Tu as raison. J'ai trouvé un exemple en C# sur http://64.233.183.104/search?q=cache...datagrid&hl=fr

    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
    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
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
     
    The essential part of the DropDown.aspx file is the following:
     
    <asp:DropDownList id="DropDownList1" runat="server"
    DataSource="<%#  GetCategory() %>"
    DataTextField="categoryname"
    DataValueField="categoryid"
    SelectedIndex='<%# GetCategoryID((string)DataBinder.Eval(Container.DataItem, "categoryname")) %>' 
    />
     
    In second line, we set the datasource of the dropdownlist control to a function 'GetCategory()', this function fetches the Category records from database and returns a datatable. In the last line, we set the SelectedIndex to a funciton 'GetCategoryID', this function takes the current Categoryname as its argument, and returns the locaiton(an integer) of the Categoryname, this enables the DorpDownList control to display the correct Categoryname for the current record.
     
    The following is the C# code:
     
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Data.OleDb;
    using System.Configuration;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
     
    namespace Management
    {
     
    	public class DropDown : System.Web.UI.Page
    	{
    		protected System.Web.UI.WebControls.DataGrid ProductGrid;
    		protected DataTable _category;
     
    		//new a database class to get records, ProductDb is a public class 
    		//containing several functions
    		protected ProductDb pdb=new ProductDb();
     
    		public DropDown()
    		{
    			Page.Init += new System.EventHandler(Page_Init);
    		}
     
    		private void Page_Load(object sender, System.EventArgs e)
    		{
    			if(!IsPostBack)
    			{
    				BindProduct();
     
    			}
    		}
     
    		private void Page_Init(object sender, EventArgs e)
    		{
    			InitializeComponent();
    		}
     
    		void BindProduct()
    		{
    			//pdb.GetProduct() returns a datatable to Product's datagrid
    			ProductGrid.DataSource=pdb.GetProduct();
    			ProductGrid.DataBind();
    		}
     
    		protected void Product_Edit(object sender, DataGridCommandEventArgs e)
    		{
     
    			BindCategory();
    			((DataGrid)sender).EditItemIndex=e.Item.ItemIndex;
    			BindProduct();
     
    		}
     
    		protected void Product_Cancel(object sender, DataGridCommandEventArgs e)
    		{
    			ProductGrid.EditItemIndex=-1;
    			BindProduct();
     
    		}
    		protected void Product_Update(object sender, DataGridCommandEventArgs e)
    		{
    			//get the currnet product name
    			string pname=e.Item.Cell[1].Controls[0].Text;
    			//get the current product price
    			string price=e.Item.Cell[2].Controls[0].Text;
    			//get the current categoryid
    	DropDownList ddl=(DropDownList)e.Item.Cells[3].FindControl("DropDownList1");
    			string categoryid=ddl.SelectedItem.Value;
    			//get the current productid
    			string pid=e.Item.Cell[4].Controls[0].Text;
     
    			//call pdb's update function
    			pdb.update(pid,pname,price,categoryid);
     
    			ProductGrid.EditItemIndex=-1;
    			BindProduct();
     
     
    		}
    		void BindCategory()
    		{
    			//pdb.FetchCategory() returns a datatable
    			_category=pdb.FetchCategory();
     
    		}
     
    		protected DataTable GetCategory()
    		{
    			return _category;
    		}
     
    		protected int GetCategoryID(string cname)
    		{
    			for(int i=0;i<_category.DefaultView.Count;i++)
    			{
    			if (_category.DefaultView[i]["categoryname"].ToString()==cname)
    				{
    					return i;
    				}
    			}
    			return 0;
     
    		}
     
     
     
    		#region Web Form Designer generated code
    		/// 
    		/// Required method for Designer support - do not modify
    		/// the contents of this method with the code editor.
    		/// 
    		private void InitializeComponent()
    		{    
    			this.Load += new System.EventHandler(this.Page_Load);
     
    		}
    		#endregion
     
     
    	}
    }
     
    The key points of this C# file are:
     
    1.In Product_Edit() function, you have to call BindCategory() to set the _category datatable first, and then set the EditItemIndex for the datagrid, and at last, call BindProduct() function. The DropDownList control will not display anyting if you reverse this order. Because once you set the EditItemIndex, the datagrid begings rendering records, and at the same time, the DropDownList control access the function 'GetCategory()' to get the data source, if 'GetCategory()' returns nothing, you will not get anything of course. Just remember: before setting EditItemIndex of datagrid, set the data source of the control.
     
    2.In Product_Update() function, You have no access to the DropDownList control directly which is embeded in the datagrid, the solution of getting the selected value of DropDownList control is the 'FindControl()' function. This function takes the DropDownList control's name as its argument, and return the DropDownList control it found, so that you can use the return control to get the selected value. Just remember: use FindControl() function to return any control you want to find in the datagrid, such as text box, text area, label, calendar.
    En fait, tous les exemples que je trouve permette de passer d'une "vue" Label à une "vue" DropDownList en mode Edit. Est-il possible d'avoir des DropDownList intégré à la DataGrid en vue normale, sans passer par l'édition d'un enregistrement ?

  17. #17
    Membre Expert
    Avatar de pmithrandir
    Homme Profil pro
    Responsable d'équipe développement
    Inscrit en
    Mai 2004
    Messages
    2 419
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Responsable d'équipe développement
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2004
    Messages : 2 419
    Par défaut
    je t avoue que je ne sais meme pas ce qu'est le mode edition d'une datagrid...

    (si on m annonce que y a un truc pour editer automatqieuement les lignes avec synchro avec la base de donnée, je GRRR trés fort)

    et oui tu peux avoir une drop down dans un datagrid.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    <asp:TemplateColumn HeaderText="Unité temps">
    						<ItemTemplate>
    							<asp:dropdownlist runat="server" ID="temps"></asp:dropdownlist>
    						</ItemTemplate>
    					</asp:TemplateColumn>
    par exemple...

    et je la remplie dans le item data bound ;-)

  18. #18
    Membre averti
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    59
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 59
    Par défaut
    ItemDataBound, c'ext un événement de DataGrid ? Il se déclenche quand ?

    Peux-tu me montrer un exemple de code là-dessus stp ?

    Merci...

  19. #19
    Membre averti
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    59
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 59
    Par défaut
    Citation Envoyé par pmithrandir
    je t avoue que je ne sais meme pas ce qu'est le mode edition d'une datagrid...

    (si on m annonce que y a un truc pour editer automatqieuement les lignes avec synchro avec la base de donnée, je GRRR trés fort)

    et oui tu peux avoir une drop down dans un datagrid.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    <asp:TemplateColumn HeaderText="Unité temps">
    						<ItemTemplate>
    							<asp:dropdownlist runat="server" ID="temps"></asp:dropdownlist>
    						</ItemTemplate>
    					</asp:TemplateColumn>
    par exemple...

    et je la remplie dans le item data bound ;-)
    J'ai mis ça, et ce qui suit dans mon code-behind :
    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
     
            protected void Product_Update(object sender, DataGridItemEventArgs e)
          {
                WebRAM toto = new WebRAM();
                ArrayList myAL = new ArrayList();
     
                DropDownList ddl=(DropDownList)e.Item.Cells[1].FindControl("dgDDLSI");
     
                myAL=toto.GetStandardIndicator();
                ddl.DataSource=myAL[0];
                ddl.DataTextField=myAL[1].ToString();
                ddl.DataBind();
     
                ddl.SelectedValue = e.Item.Cells[1].ToString();
     
     
          }
    et j'ai toujours la même erreur.
    Object reference not set to an instance of an object.
    L'object en question est la DropDownList...

  20. #20
    Membre Expert
    Avatar de Nesmontou
    Homme Profil pro
    Architecte logiciel
    Inscrit en
    Septembre 2004
    Messages
    1 612
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Architecte logiciel
    Secteur : Finance

    Informations forums :
    Inscription : Septembre 2004
    Messages : 1 612
    Par défaut
    On dirait qu'il ne trouve pas ta DropDownList. Tu es sûr qu'elle est dans la cellule 1 : N'oublie pas que les index commencent à 0, on a vite fait de sauter un indice

+ Répondre à la discussion
Cette discussion est résolue.
Page 1 sur 2 12 DernièreDernière

Discussions similaires

  1. ListView, datagrid, tutoriels
    Par HENRYC dans le forum C#
    Réponses: 2
    Dernier message: 27/04/2007, 11h08
  2. Outils, cours et NOUVEAUX tutoriels pour Borland C++Builder
    Par hiko-seijuro dans le forum C++Builder
    Réponses: 10
    Dernier message: 12/03/2006, 22h33

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo