Click here to Skip to main content
15,885,992 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a datatable with the values (1.0,0.98,0.78,0.8549996).I had created a dropdownlist for these values to be binded to the gridview. In the gridview the values are displayed as (100,98,78,85).

So My problem is everything works fyn for me except 100 & 85..At this case(100,85) gridivew is not ddl is not displayed to my gridview.
C#
public void bindddlscore()
       {
           try
           {
               DataTable dtscore = (DataTable)Session["GrdSearch"];
               DataTable dtscore1 = new DataTable();
               dtscore1.Columns.Add("DisplayMember", typeof(int));
               dtscore1.Columns.Add("ValueMember", typeof(float));
               foreach (DataRow item in dtscore.Rows)
               {
                   dtscore1.Rows.Add(Convert.ToString(Convert.ToInt32(Convert.ToDecimal(item["Score"]) * 100)), item["Score"]);
               }
               ddlscore.DataSource = dtscore1.DefaultView.ToTable(true, "DisplayMember", "ValueMember");
               ddlscore.DataTextField = "DisplayMember";
               //ddlscore.DataTextFormatString = "{0:N}";
               ddlscore.DataValueField = "ValueMember";
               ddlscore.DataBind();
               ddlscore.Items.Insert(0, "All");
           }
           catch (Exception ex)
           {
               throw ex;
           }
       }
Posted
Updated 26-Jul-15 20:14pm
v2
Comments
Michael_Davies 27-Jul-15 2:21am    
Notice your column ValueMember is type of float, why not decimal if that is what you want? Float has unpredictable results in my experience.
Member 11833198 27-Jul-15 2:39am    
Thanks alot..Ur idea helped me with my issue....thank alot :-)
Afzaal Ahmad Zeeshan 27-Jul-15 2:22am    
I can say the code is working correctly. You are multiplying the values to 100 (and maybe casting them to int that is why decimal place values are lost). So, what is the problem with 100 or 85? The code is OK.

Finally, what did you mean by GridView is not DDL?
Member 11833198 27-Jul-15 2:32am    
the code is working fyn for other values.But when i click on 100 & 85 my dropdownlist is not getting binded to gridview.
Whereas the values in gridiview are displayed as (100,98,78,85) ...but in my datatable i have my values as (1.0,0.98,0.78,0.854999)
Member 11833198 27-Jul-15 2:43am    
Thnkx alot for every1.Finally i got the desired o/p by replacing float to decimal :-)

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