[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 630
  • Last Modified:

gridview not populating... asp.net c#

I have checked and made sure the table has data in it.

Question: Why the following code is not population the gridview?
public partial class Default3 : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ROD_July18ConnectionString"].ToString());
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            LoadData();
        }
    }
    private void LoadData()
    {
        var da = new SqlDataAdapter("SELECT * FROM t08MedCenter", con);
        var ds = new DataSet();
        da.Fill(ds);
        grdHighLight.DataBind();
    }
}
----------------------------
   <form id="form1" runat="server">
    <div>
    <asp:GridView runat="server" ID="grdHighLight" >
            
    </asp:GridView>
    </div>
    </form>

Open in new window

0
Mike Eghtebas
Asked:
Mike Eghtebas
  • 3
  • 3
1 Solution
 
Fernando SotoCommented:
Hi eghtebas;

You need to assign the DataTable to the DataSource of the DataGrid first.

private void LoadData()
{
    var da = new SqlDataAdapter("SELECT * FROM t08MedCenter", con);
    var ds = new DataSet();
    da.Fill(ds);
    // Assign the Table to the grids datasource before data binding it.
    grdHighLight.DataSource = ds.Tables[0];
    grdHighLight.DataBind();
}

Open in new window

0
 
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Thank you very much.

Mike
0
 
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Hi Fernando,

I wonder if you have a moment to take a look at:

http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_28504938.html

In this question I have problem validating for html5. <asp:gridview... > generates its own inline css attributes and html5 doesn't like it.

FYI, I have used gridview from the toolbar; perhaps I need not to use gridview from the tollbar. Instead, I may have to populate this gridview from codebehinde to have a better control on its styling.

Thanks,

Mike
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Fernando SotoCommented:
I have looked at the other question but not being an web developer I would not be of any help, sorry.
0
 
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Thank you for the response.

Mike
0
 
Fernando SotoCommented:
Not a problem Mike, glad I was able to help.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now