Gridview doesn't show up !

Hello all,

i am trying to create a gridview from a datatable. The datatable is filled up with data, no worries on this side. But the gridview doesn't show up...

Any ideas why ?

Cheers,

Terence
protected void Page_Load(object sender, EventArgs e)
    {
        DataTable test = readExcel();
        
        GridView toto = new GridView();

        toto.DataSource = test;
        toto.AutoGenerateColumns = true;
        toto.Visible = true;
        toto.DataBind();
    }

Open in new window

LVL 1
terencepiresAsked:
Who is Participating?
 
rajvjaConnect With a Mentor Commented:
Why are you doing like this? Any reason?
You can code manually in design view to display gridview.

If you want to do this, you need to specify the location where to display the gridview.
0
 
terencepiresAuthor Commented:
yes there is

the data is taken from an excel file, using an oledbconnection object, which is not available in the list of standard connection types

what do you mean by "you need to specify the location" ?
0
 
terencepiresAuthor Commented:
ok done
just created a div and added it to it's control collection

thanks !
0
 
guru_samiCommented:
You are creating an instance of GridView but is not added to the controls on the page.

You can add the GridView on the aspx page and seperately bind it in code-behind without any issue.
If no data is found, It will not be displayed.
No need to set explicit visibility also.

.aspx:
<asp:GridView ID="toto" runat="server" AutoGenerateColumns="true" >
        </asp:GridView>
   
.cs

protected void Page_Load(object sender, EventArgs e)
    {
        DataTable test = readExcel();
     
        toto.DataSource = test;
        toto.DataBind();
    }
0
 
guru_samiCommented:
sorry... my bad....
0
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.

All Courses

From novice to tech pro — start learning today.