Solved

ASP.NET rookieQ: 'MyDataGrid is not declared'

Posted on 2002-04-02
11
466 Views
Last Modified: 2012-05-04
I have the following in the top of one of my .aspx-files:

---------------------------------------------------------
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Configuration" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<SCRIPT LANGUAGE="VB" RUNAT=server>
  Sub Page_Load(Sender As Object, E As EventArgs)
      Dim DS As DataSet
      Dim MyConnection As SqlConnection
      Dim MyCommand As SqlDataAdapter
      MyConnection = New SqlConnection("connection")
      MyCommand = New SqlDataAdapter("SELECT * FROM table", MyConnection)

      DS = new DataSet()
      MyCommand.Fill(ds, "kapittel")
      MyDataGrid.DataSource=ds.Tables("table").DefaultView
      Page.DataBind()
  End Sub
</SCRIPT>
---------------------------------------------------------

When I run this I get the error-message "BC30451: Name 'MyDataGrid' is not declared." and I have no idea how to solve it. This code is almost exactly the same as downloaded from the asp.net-website. I have tried to use Dim MyDataGrid AS ... but I haven't found the right arguments. The exact same code also works in one of my ascx-files...go figure...

HenningF


0
Comment
Question by:HenningF
  • 5
  • 5
11 Comments
 

Expert Comment

by:cdpMat
ID: 6913233
You just need to rename your grid to 'MyDataGrid'. It's probably named DataGrid1 at the moment. Click it and select Properties to view it's name.
0
 
LVL 1

Author Comment

by:HenningF
ID: 6915184
OK, so what you are saying is that 'MyDataGrid' is some kind of reserved word? What if I want to have several different datagrids within the same page...?

My exact code at the moment looks like this:
---------------------------------------------------------
  Sub Page_Load(Sender As Object, E As EventArgs)
    Dim DS1 As DataSet
    Dim DS2 As DataSet
    Dim MyConnection As SqlConnection
    Dim MyCommand1 As SqlDataAdapter
    Dim MyCommand2 As SqlDataAdapter

    MyConnection = New SqlConnection("server=something, ...")
    MyCommand1 = New SqlDataAdapter("SELECT * FROM table1", MyConnection)
    MyCommand2 = New SqlDataAdapter("SELECT * FROM table2", MyConnection)

    DS1 = new DataSet()
    DS2 = new DataSet()
    MyCommand1.Fill(ds1, "table1")
    MyCommand2.Fill(ds2, "table1")

    MyDataGrid1.DataSource=ds1.Tables("table1").DefaultView
    MyDataGrid2.DataSource=ds2.Tables("table1").DefaultView
    Page.DataBind()
  End Sub
---------------------------------------------------------
0
 
LVL 1

Author Comment

by:HenningF
ID: 6915188
...a small typo in the 3rd line from the bottom, it should be "MyDataGrid2.DataSource=ds2.Tables("table2").DefaultView"
0
 

Expert Comment

by:cdpMat
ID: 6915295
No, I'm not saying that. I'm saying that your code was referring to a DataGrid which did not exist so was causing an error.

You have changed the code since you first asked the question - are you still having problems?
0
 
LVL 1

Author Comment

by:HenningF
ID: 6915299
It's actually the last code I'm using...I just modified it to keep you from reading all that much. It still doesn't work...
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Accepted Solution

by:
cdpMat earned 75 total points
ID: 6915325
My answer was correct though - you had referenced the grid wrongly in the code.

"Still doesn't work" is not enough information for anyone to help you.
0
 
LVL 23

Expert Comment

by:naveenkohli
ID: 6916638
what cdpmat said, is correct....
To make sure...show us where have you defined your variables MyDataGrid1, MyDataGrid2, ......etc.

do you have a line of code in your application that reads like..

Dim MyDataGrid1 As DataGrid

Or in ascx file do you have

<asp:DataGrid Runat=server ID="MyDataGrid1"></asp:DataGrid>
0
 
LVL 1

Author Comment

by:HenningF
ID: 6917494
I have a

<ASP:DROPDOWNLIST AUTOPOSTBACK="True" ID="MyDataGrid1" DATAVALUEFIELD="KapittelID" DATATEXTFIELD="Kapittelnavn" />

later on in my page (I don't use code-behind in this page). So maybe if I put something like Dim MyDataGrid1 As Dropdownlist it might work? I apologise for all this but I'm a total rookie, and I'm beginning to wonder if I should take a class on this instead of trying myself...
0
 

Expert Comment

by:cdpMat
ID: 6917600
A DropDownList control is totally different to a DataGrid control. Delete the dropdown and replace it with a DataGrid control. Make sure you name it MyDataGrid1.
0
 
LVL 1

Author Comment

by:HenningF
ID: 6917622
OK, it seems like I misunderstood this part, and I'm now looking more into how to make dropdownlists. I somehow got the idea that a DataGrid was a kind of "universal datastorage" and that I could use it in whatever manner I wanted. I see now that this is not the case, and you cdpMat will offcourse recieve the points for guiding me in the right direction.

Thanx,
HenningF
0
 

Expert Comment

by:cdpMat
ID: 6917644
A DataGrid is useful for displaying a table of data on a web page. You're probably thinking of a DataSet which temporarily holds tables of data to be used in controls. You can easily bind data to a drop down list control but you need to specify fields for the value and text etc.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now