Click here to Skip to main content
15,922,894 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello everyone, I am tried most of the thing but didn't got the perfect solution if you can all can help

What I have tried:

int id = Convert.ToInt32(Session["UserID"]);
        string connection = ConfigurationManager.AppSettings["Connection"].ToString();

        using (SqlConnection con = new SqlConnection(connection))
        {
            con.Open();
            using (SqlCommand cmd = new SqlCommand("Score_Page", con))
            {

                cmd.Parameters.AddWithValue("@ID", id);
                DataTable cop = new DataTable();
                SqlDataAdapter sad = new SqlDataAdapter(cmd);
                cmd.CommandType = CommandType.StoredProcedure;
                sad.Fill(cop);
                int sco = (int)cop.Rows[0][0];
                int scr = percentage();
                int sro = (int)((sco * 100) / scr);
                //int.TryParse(cop.Rows[0][0].ToString(), out sro);
                con.Close();
                GridView1.DataSource = sro;
                GridView1.DataBind();
Posted
Updated 10-Jul-17 0:30am

GridView1.DataSource = cop;
 
Share this answer
 
Comments
Member 11644373 10-Jul-17 6:25am    
here em trying to get percentage using int sro = (int)((sco * 100) / scr);

as sco contain 3 value and scr contain 5 so sro= 60% and i want to show this as result if i use GridView1.DataSource = cop; it will return 3 as result as according to select query
Karthik_Mahalingam 10-Jul-17 6:39am    
 DataTable dt = new DataTable();
            dt.Columns.Add("ColumnHeader");
            dt.Rows.Add(sro);
            GridView1.DataSource = dt;
            GridView1.DataBind();
Maciej Los 11-Jul-17 2:13am    
5!
Karthik_Mahalingam 11-Jul-17 2:20am    
Thank you Maciej
Without knowing exactly what you want the GridView to show it's impossible to help. If you only want the GridView so show a single value do this

GridView1.DataSource = new List<int>{ sro };
 
Share this answer
 
Comments
Member 11644373 10-Jul-17 6:34am    
here em trying to get percentage using int sro = (int)((sco * 100) / scr);

as sco contain 3 value and scr contain 5 . So sro= 60% and i want to show this as result if i use GridView1.DataSource = cop; it will return 3 as result as according to select query
Member 11644373 10-Jul-17 6:39am    
Thankyou its working, But i want to ask why was it showing Data source is an invalid type. It must be either an ilistsource, ienumerable, or idatasource. Error
F-ES Sitecore 10-Jul-17 6:47am    
The GridView is designed to show a list of items, ie more than one, so its DataSource property has to be set to some kind of collection. If you want to force it to show one item you need to make a list that contains just the one item you want to show.

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