Solved

ASP.NET rookieQ: 'MyDataGrid is not declared'

Posted on 2002-04-02
11
470 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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
 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

828 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