Click here to Skip to main content
15,900,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My Source Wise Gridview Dropdown More Time Display How to Solve this Problem,

My Source is:
C#
private void LoadAdjustLeave()
    {
        SqlCommand cmd = new SqlCommand();
        SqlDataAdapter da;
        cmd.Connection = con;
        cmd.CommandType = CommandType.Text;
        try
        {
            //string sql = " select USER_ID as UserID, LateDays,Leave,Remainingminutes,Month,Year from Accounts_LateEntry_Salary_Deduct where User_ID='" + gvStaffDetails.SelectedRow.Cells[2].Text.ToString().Trim() + "'";
            string sql = "select convert(VARCHAR(12),LeaveDate) as leavedate, InformType, TotalDays, Leave,Applyhrs from deletetable where UserID='" + gvStaffDetails.SelectedRow.Cells[2].Text.ToString().Trim() + "' and Month='" + Session["paymonth"] + "' and Year='" + Session["payyear"] + "'";
            da = new SqlDataAdapter(sql, con);
            //DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            da.Fill(dt);
            con.Open();
            gvadjustleave.DataSource = dt;
            Session["AdjustLeave"] = dt;
            gvadjustleave.DataBind();
            con.Close();
            
        }
        catch (Exception Ex1)
        {
            LblErr.Text = Ex1.Message.ToString();
            return;
        }
    }



load time Load Data Multiple time Show Dropdown,so i don't want Below Example.
InformType
Not Informed
Not Informed
Prior
Prior
Prior
Prior
Late informed
Not Informed
Not Informed
Not Informed
Not Informed
Not Informed
Not Informed
Not Informed

So I don't want Dropdownlist (above) Result

I want Dropdown List load Data Result below exaple

InformType
Prior
Late informed
Not Informed


Thanks
Posted
Updated 5-Nov-14 22:09pm
v2
Comments
george4986 6-Nov-14 4:16am    
is ur "dt" returning duplicate values of "InformType"?

Hi,


Use

Item.Clear() Before DataBind

Ex.
Dropdown=> ddlType

C#
ddlType.Item.Clear();
ddlType.DataSource = dt;
ddlType.DataBind();


Thanks
 
Share this answer
 
if you want to load leave types to drop down list, try with below sql statement.
SQL
select distinct InformType from deletetable
 
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