Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ASP.NET rookieQ: 'MyDataGrid is not declared'

Posted on 2002-04-02
11
Medium Priority
?
475 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
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.

 

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 225 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
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/…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…

971 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