Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to avoid to display duplicate value in grid view?????
eg:- 1 maths 1234
2 bio 234
1 maths 1234
2 bio 234
my code is:-
public partial class InstSentIntForFran : System.Web.UI.Page
{
    SqlConnection cn;
    autheticate at = new autheticate();
    protected void Page_Load(object sender, EventArgs e)
    {
        
        getCandidateSentIntrest();
    }
    public void getCandidateSentIntrest()
    {
        try
        {
            cn = at.sqlcon();
            //SqlDataAdapter sda = new SqlDataAdapter(strqry, cn);
            //DataSet ds = new DataSet();

            string strqry = getQuery();
 
            SqlDataAdapter sda = new SqlDataAdapter(strqry, cn);
            DataSet ds = new DataSet();
            ds.Clear();
            sda.Fill(ds);
            int dd = ds.Tables[0].Rows.Count;
            GridView1.DataSource = ds;
            GridView1.DataBind();
          
          
        }
        catch (Exception err)
        {
            lblres.Text = err.Message;
        }
    }


    string getQuery()
    {

         string sentintrestType = "";
        if (Request.QueryString["sentintrestType"] != null)
        {
            sentintrestType = Request.QueryString["sentintrestType"].ToString();
        }
        string qry = "Select C.Franchise_Brand_Name,p.Franchise_Offer_Industry,p.Franchise_Offer_ExpnReg,p.Franchise_OfferInvReqMin,p.Franchise_Offer_InvReqMx,p.Franchise_Offer_MinSqft,p.Franchise_Offer_MaxSqFt,I.Int_Date from User_Details U,Franchise_Details C,Franchise_Offer_Details p,Intrests I where I.Applicants_User_Name='" + Session["uid"] + "' and I.Receivers_User_Name = U.User_Name and I.Receivers_User_Name = C.User_Name and p.User_Name = C.User_Name  ";
        
       
        if (sentintrestType == "Brand_Int_Frn")
        {
            qry = qry + "and I.Brand_Int_Frn='true'";
        }
        qry = qry + "ORDER BY I.Int_Date DESC";
        return qry;

    }

}

plz help me what is wrong in this?????
Posted
Updated 10-Jun-12 20:09pm
v2

2 things:
1. Make sure your query returns only the needed data. No duplicates from query itself.
2. Change this line of code:
C#
GridView1.DataSource = ds;

to
C#
GridView1.DataSource = ds.Tables[0];



Not an issue, but you may want to put the GridBind code in Page IsPostback property to avoid grid's rebind on every postback.
 
Share this answer
 
If your query returning one row than
write this in gridview's property aspx page
C#
AutoGenerateColumns="False"
 
Share this answer
 
Comments
Sandeep Mewara 11-Jun-12 2:56am    
How do 'AutogenerateColumns' duplicate row values? :doh:
Mac12334 11-Jun-12 10:19am    
Sry :(
Wrongly posted
next time onwards i will take care.
Sandeep Mewara 11-Jun-12 10:32am    
Not an issue. Keep helping others - good work.

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