Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
private void button1_Click(object sender, EventArgs e)
        {


            DataTable tab = new DataTable();
            tab.Columns.Add("matricule", Type.GetType("System.Int32"));
            tab.Columns.Add("nom", Type.GetType("System.String"));
            tab.Columns.Add("part", Type.GetType("System.Int32"));
            for (int i = 0; i <= dg.Rows.Count - 1; i++)
            {

                DataRow dr = tab.NewRow();
                dr[0] = dg.Rows[i].Cells[0].Value;
                dr[1] = dg.Rows[i].Cells[1].Value;
                dr[2] = dg.Rows[i].Cells[2].Value;
                tab.Rows.Add(dr);
            }

                DataRow mdr = tab.NewRow();
                mdr[0] = t1.Text;
                mdr[1] = t2.Text;
                mdr[2] = t3.Text;
                tab.Rows.Add(mdr);


                dg.DataSource = tab;
            
           
        }

Bonjour

j'ai un probleme de chargement Data GridView sans base ,l’exécution me donne just un seule ligne si je veut ajouter un nouveau ligne ne se realise pas avec un erreur que je ne le sais pas .

merci pou l'aide

[Translation courtesy of Google translate:]
Hello

I have a problem loading GridView Data without basis, the execution gives me just a single line if I want to add a new line will not be realized with an error that I do not know.

thank you for your help
Posted
Updated 23-Mar-14 8:04am
v2
Comments
CHill60 23-Mar-14 14:04pm    
Quel était le message d'erreur? What was the error message?

1 solution

Il vous manque la liaison de données.

C#
private void Button1_Click(object sender, EventArgs e)
{
    DataTable tab = new DataTable();
    tab.Columns.Add("matricule", Type.GetType("System.Int32"));
    tab.Columns.Add("nom", Type.GetType("System.String"));
    tab.Columns.Add("part", Type.GetType("System.Int32"));
    for (int i = 0; i <= dg.Rows.Count - 1; i++)
    {

        DataRow dr = tab.NewRow();
        dr[0] = dg.Rows[i].Cells[0].Text;
        dr[1] = dg.Rows[i].Cells[1].Text;
        dr[2] = dg.Rows[i].Cells[2].Text;
        tab.Rows.Add(dr);
    }

    DataRow mdr = tab.NewRow();
    mdr[0] = Server.HtmlEncode(t1.Text);
    mdr[1] = Server.HtmlEncode(t2.Text);
    mdr[2] = Server.HtmlEncode(t3.Text);
    tab.Rows.Add(mdr);

    dg.DataSource = tab;
    dg.DataBind();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900