Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Problem adding a datagrid in ASP.Net mobile web application

Posted on 2005-04-28
18
Medium Priority
?
823 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:wilkersons
  • 10
  • 8
18 Comments
 

Author Comment

by:wilkersons
ID: 13887530
Do I have to use Object list control instead?? If yes, please give examples of binding objectlist control to the datasource.

Thanks
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13897086
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
 

Author Comment

by:wilkersons
ID: 13897291
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 96

Expert Comment

by:Bob Learned
ID: 13897413
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
 

Author Comment

by:wilkersons
ID: 13897889
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13908427
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
 

Author Comment

by:wilkersons
ID: 13909192
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
 
LVL 96

Accepted Solution

by:
Bob Learned earned 1000 total points
ID: 13910632
ObjectList1.TableFields = "RefNbr;Docdate"

Bob
0
 

Author Comment

by:wilkersons
ID: 13911402
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13911414
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
 

Author Comment

by:wilkersons
ID: 13911628
Nope...I think i am missing something.

0
 

Author Comment

by:wilkersons
ID: 13911775
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13911932
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
 

Author Comment

by:wilkersons
ID: 13913417
Opps I forgot to paste the line but I had it in my original code:


conConnection.Close()
Datagrid1.DataSource=ds
Datagrid1.DataBind()
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13917429
Where is DataMember?

Bob
0
 

Author Comment

by:wilkersons
ID: 13920576
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13970519
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
 

Author Comment

by:wilkersons
ID: 14059940
Not really. I think object list is a better option but still doing R&D on that.

Anyway thanks for ur help
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month14 days, 18 hours left to enroll

577 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