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

LVL 34
Mike EghtebasDatabase and Application DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

Fernando SotoRetiredCommented:
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 SotoRetiredCommented:
Not a problem Mike, glad I was able to help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.