Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ASP.NET rookieQ: 'MyDataGrid is not declared'

Posted on 2002-04-02
11
Medium Priority
?
473 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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!

 

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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 informatio…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

715 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