You must Sign In to post a response.
  • Category: LINQ

    Sometimes grid view doesn't show data even the result contains data

    Hi ,

    It is a very strange problem i am facing that the grid view some times shows empty grid even it is not possible that the query doesn't return any data i have checked the query by executing it in the sql server it always return the result.
  • #756724
    Hai Himanshu,
    Do you have the windows app or web application.
    If you are using the Web Application, you should not the issue as each time, it will refresh the grid and should fill the grid correctly.
    The problem can come when you are binding the data in the Windows Application as once the GridView is binded already, it will not get binded again so before binding the grid View, first you need to make the DataSource as null for the GridView and then bind it based on the result of new data.
    By this way, you can get the desired results.
    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #756731
    Hi,

    Better to put a breakpoint and then check the code whether dataset contains data or not. If DataSet contain data and then also gridview won't show records then place your piece of code here, we will check it and let you know..

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #760673
    Hi Himanshu
    Always set grid datasource to null before assign new datasource to it.
    also for Web Application . write Gridview.DataBind().


    Thanks
    UMesh Bhosale

  • #760680
    Hi
    Himashu

    You can bind records before assign null in Gridview after bind try this code both


    using (SqlConnection con = new SqlConnection(strCon))
    {
    SqlDataAdapter sqladp = new SqlDataAdapter("Select * from tblProducts", con);
    sqladp.Fill(dt);

    if (dt != null)
    {
    Grd1.DataSource = null;
    Grd1.DataSource = dt;
    Grd1.DataBind();
    }
    }


    Hope it will be helpful to you.

    Name : Dotnet Developer-2015
    Email Id : kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.


  • Sign In to post your comments