Problem adding a datagrid in ASP.Net mobile web application

I am trying to add the datagrid control in the form control of the mobile web appication. Its giving me an error that the Non-mobile controls can be added inside the templates only. What does that mean??

What is a template and how do I creat one??
I am getting the following error:

Parser Error Message: 'asp:DataGrid' cannot be a toplevel form element.

Source Error:


Line 15:       <asp:ButtonColumn Text="Button" HeaderText="B1"></asp:ButtonColumn>
Line 16:       </Columns>
Line 17:       </asp:DataGrid>
Line 18:       <asp:DataGrid id="DataGrid2" runat="server"></asp:DataGrid>
Line 19:       <mobile:Command id="Command1" onclick="Print" runat="server">Command</mobile:Command>
 


Thanks
wilkersonsAsked:
Who is Participating?
 
Bob LearnedCommented:
ObjectList1.TableFields = "RefNbr;Docdate"

Bob
0
 
wilkersonsAuthor Commented:
Do I have to use Object list control instead?? If yes, please give examples of binding objectlist control to the datasource.

Thanks
0
 
Bob LearnedCommented:
I haven't used the ObjectList control (which is the Mobile Web equivalent), but I'll see what I can accomplish.

What kind of Datasource are we talking about?

Bob
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
wilkersonsAuthor Commented:
I  am using SQL Server as the datasource. I am getting error at:
   ObjectList1.DataMember = "PostDate"

--------I want to display the data in the PostDate column of the database.
In regular ASP.Net I could accoumplish this by using the DataTextField property of the  Drop Down List control.

BTW: I want to display the data in the Grid form that is why I am using Object list control. Is this the right choice as in regualr ASP.Net project i had used the datagrid control

Thanks

 Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim conConnection As New SqlConnection(SQL_CONNECTION_STRING)
        Dim strSQL As String
        strSQL = "xWEBRSMReportShipDocs_SiteID_MaxPostDate"

        Dim cmdReport As New SqlCommand(strSQL, conConnection)
        cmdReport.CommandType = CommandType.StoredProcedure

        Dim prmSiteID As SqlParameter = cmdReport.Parameters.Add("@SiteID", SqlDbType.Char, 10)
        prmSiteID.Value = "S000772"

        Dim myAdapter As New SqlDataAdapter(cmdReport)
        Dim ds As New DataSet
        myAdapter.Fill(ds)

       
        conConnection.Close()
        ObjectList1.DataSource = ds
        ObjectList1.DataMember = "PostDate"

        ObjectList1.DataBind()


    End Sub
0
 
Bob LearnedCommented:
Example:

Imports System.Data.OleDb

Public Class MobileWebForm1 : Inherits System.Web.UI.MobileControls.MobilePage

#Region " Web Form Designer Generated Code "

  'This call is required by the Web Form Designer.
  <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

  End Sub
  Protected WithEvents Button1 As System.Web.UI.HtmlControls.HtmlInputButton
  Protected WithEvents DeviceSpecific1 As System.Web.UI.MobileControls.DeviceSpecific
  Protected WithEvents ObjectList1 As System.Web.UI.MobileControls.ObjectList
  Protected WithEvents Form1 As System.Web.UI.MobileControls.Form

  Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
    'CODEGEN: This method call is required by the Web Form Designer
    'Do not modify it using the code editor.
    InitializeComponent()
  End Sub

#End Region

  Private _drData As OleDbDataReader

  Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'Put user code to initialize the page here

    If Not Me.IsPostBack Then
      Me.BindObjectList()
    End If

  End Sub


  Private Sub BindObjectList()

    Dim dataName As String = Server.MapPath(".") & "\AccessDatabase.mdb"

    Dim connectString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & dataName

    Dim connectDatabase As New OleDbConnection(connectString)

    connectDatabase.Open()

    Dim cmdText As String = "Select * From Table"

    Dim selectCommand As New OleDbCommand(cmdText, connectDatabase)

    _drData = selectCommand.ExecuteReader(CommandBehavior.CloseConnection)

    Me.ObjectList1.DataSource = _drData
    Me.ObjectList1.DataBind()

  End Sub

End Class


Bob
0
 
wilkersonsAuthor Commented:
Ok this is working but there is a problem.
Its giving the result as:

DatabaseTableHeader1    Field-Values1
DatabaseTableHeader2    Field-Values2

whereas I need

DatabaseTableHeader1        DatabaseTableHeader2
 Field-Values1                      Field-Values2

in a tabular form with the headings at the top and their respective values below.

Any suggestions??

Thanks
0
 
Bob LearnedCommented:
I was able to get a tabular view from the Object List, through the Property Builder dialog box.

If you right-click on the control, there is a 'Property Builder' menu option.

As a test, I dragged/dropped an OleDbDataAdapter onto the form, create a connection, generated a DataSet, and used the dialog to get the right look.

Bob

0
 
wilkersonsAuthor Commented:
Since I have to bind the control at runtime I used the tablefields to display the data in the column RefNbr.
What if I have to display another column "Docdate" also??

            ObjectList1.DataSource = ds
           ObjectList1.TableFields = "RefNbr"
            ObjectList1.DataBind()

       
0
 
wilkersonsAuthor Commented:
Great!! That solves one part of my problem.

The other part is abt the datagrid:

Can I use a datagrid alsoin mobile web app project??
if yes, Is this the right way to add a datagrid:

<mobile:DeviceSpecific id="DeviceSpecific1" runat="server">
<Choice Xmlns="http://schemas.microsoft.com/mobile/html32template">
<HeaderTemplate>
<asp:DataGrid id="DataGrid1" runat="server">
<Columns>
      <asp:BoundColumn HeaderText="ABC"></asp:BoundColumn></Columns>
</asp:DataGrid>
</HeaderTemplate>
</Choice>
</mobile:DeviceSpecific>

0
 
Bob LearnedCommented:
I was thinking the same thing about using a DataGrid control, but I wanted to learn something about the ObjectList control.

Does this work?

Bob
0
 
wilkersonsAuthor Commented:
Nope...I think i am missing something.

0
 
wilkersonsAuthor Commented:
The following gives "The active schema does not support SCRIPt" at designtime and when I run the project I get a blank webpage
'''''''''''''''
<% @Import Namespace="System.Data" %>
<% @Import Namespace="System.Data.SqlClient" %>
<HEAD>
<...
<meta content="http://schemas.microsoft.com/Mobile/Page" name="vs_targetSchema">
</HEAD>
<body Xmlns:mobile="http://schemas.microsoft.com/Mobile/WebForm">

<script language="vb" runat="server">
  Sub Page_Load(sender as Object, e as EventArgs)
    If Not Page.IsPostBack then
      BindData() 'Only bind the data on the first page load
    End If
  End Sub
 
  Sub BindData()
    Const SQL_CONNECTION_STRING As String = "Server=WA;DataBase=SOLLI;user=sa;password=''"
    Dim conConnection As New SqlConnection(SQL_CONNECTION_STRING)
            Dim strSQL As String
            strSQL = "xWEBRSM_SelectInvoices"

            Dim cmdReport As New SqlCommand(strSQL, conConnection)
            cmdReport.CommandType = CommandType.StoredProcedure

            Dim prmSiteID As SqlParameter = cmdReport.Parameters.Add("@SiteID", SqlDbType.Char, 10)
            prmSiteID.Value = "S000766"

            Dim myAdapter As New SqlDataAdapter(cmdReport)
            Dim ds As New DataSet
            myAdapter.Fill(ds)

            conConnection.Close()
           Datagrid1.DataBind()
  End Sub

</script>
      <mobile:form id="Form1" runat="server">
            <mobile:ObjectList id="ObjectList1" runat="server" LabelStyle-StyleReference="title" CommandStyle-StyleReference="subcommand"></mobile:ObjectList>
            <mobile:DeviceSpecific id="DeviceSpecific1" runat="server">
                  <Choice Xmlns="http://schemas.microsoft.com/mobile/html32template">
                        <HeaderTemplate>
                              <asp:DataGrid id="DataGrid1" runat="server">            
                              </asp:DataGrid>
                        </HeaderTemplate>
                  </Choice>
            </mobile:DeviceSpecific>
      </mobile:form>
</body>
0
 
Bob LearnedCommented:
I don't see where you are data-binding:

<asp:DataGrid id="DataGrid1" runat="server"   DataSource="<%# DataSet1 %>" DataMember="Table">

or

DataGrid1.DataSource = ds
DataGrid1.DataMember = ds.Tables(0).TableName
Datagrid1.DataBind()

Bob
0
 
wilkersonsAuthor Commented:
Opps I forgot to paste the line but I had it in my original code:


conConnection.Close()
Datagrid1.DataSource=ds
Datagrid1.DataBind()
0
 
Bob LearnedCommented:
Where is DataMember?

Bob
0
 
wilkersonsAuthor Commented:
I  don't need the datamember here as I am retrieving records from a query and  it retrieves all records with databind().
I am using the same code in normalASP.NETapp and its working fine but here its giving a blank page.

0
 
Bob LearnedCommented:
Sorry for losing track of this.  I didn't have a ready answer, I got very busy.  Did you ever find a solution?

Bob
0
 
wilkersonsAuthor Commented:
Not really. I think object list is a better option but still doing R&D on that.

Anyway thanks for ur help
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.