How to make customize GridView in

I created aboutcodes data base having reportcard table as show below

Now go to aspx page and create GridView as show below

For customize GraidView make AutoGenerateColumns to False and DataField
 Must be same as column name of reportcard table

Now go to aspx.cs page and create a function called reportdisplay

Click here to make connection between mysql and

private void reportdisplay()
        string MyConString = "SERVER=localhost;" +
                   "DATABASE=aboutcodes;" +
                   "UID=root;" +

        using (MySqlConnection connection = new MySqlConnection(MyConString))


                string cmdtText = "SELECT * FROM `reportcard`";
                //string cmdtText = "SELECT `idnumber`,`student`,`subject`,`markes` FROM `reportcard`";
                MySqlCommand cmde = new MySqlCommand(cmdtText, connection);
                MySqlDataAdapter da = new MySqlDataAdapter(cmde);
                DataSet ds = new DataSet();
                GridView1.DataSource = ds;

            }//end of try
            catch (Exception)
                Label1.Text= "Error In Connection";

            }//end of catch
        }//end of use

    }// end of reportdisplay function

Call reportdisplay function in Page_Load function

You also can use below statement

string cmdtText = "SELECT * FROM `reportcard`";

For below code you can use same reportdisplay function that’s means DataField is very important for GridView

The table looks like this

Leave reply

Add your comments here

Back to Top