Displaying Records in Multiple Tables on each Page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • orderofblessing
    New Member
    • Jun 2007
    • 4

    Displaying Records in Multiple Tables on each Page

    Hi every one:

    I just registered on forum today to get the help on a little but tricky problem to me.

    Actually i am converting a php website into .NET C#. I just want to display each search record in each table.And also want paging on the search results. I am also attaching the link the php search results page. After clicking this http://legacy.southbeds.gov.uk/our-s...wapshop2.phtml just press search and you will see how the results are being displayed in PHP. I want same results in .net but not sure which control can do that.

    Basically i am poping data from database by DataSet.
    Any body can give me clue.

    Thanks in advance
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Welcome to TSDN. Have you tried using a datatable, datagrid or gridview and enabled paging?

    Comment

    • orderofblessing
      New Member
      • Jun 2007
      • 4

      #3
      Originally posted by kenobewan
      Welcome to TSDN. Have you tried using a datatable, datagrid or gridview and enabled paging?
      Thanks for your prompt reply:

      DataGrid/DataTable/GridView all looks to display the whole datasheet at once not in separate chunks as the PHP is doing in my example links.

      If you can see the link i send you. i think Repeater control may do that. But still not sure. Still looking for the exact solution.

      Regards
      Mian

      Comment

      • nateraaaa
        Recognized Expert Contributor
        • May 2007
        • 664

        #4
        You can do this with a datagrid/datatable/gridview the thing is that you need to create a datagrid/datatable/gridview for each result returned. I did something similar to this using a datagrid. I created a datagrid with two TemplateColumns and then used the Template columns to create the rows for the datagrid. Here is a portion of my html code.

        Code:
        <asp:datagrid id="dgResults" Runat="server" ShowFooter="False" ShowHeader="False" BorderWidth="1" BorderColor="Black" BorderStyle="Solid" Width="70%" AutoGenerateColumns="False" PageSize="10" AllowPaging="True">
        <Columns>
          <asp:TemplateColumn>
             <ItemTemplate>
                <asp:Label ID="lblFirstColumn" Runat="server"></asp:Label>
             </ItemTemplate>
           </asp:TemplateColumn>
        <asp:TemplateColumn>
             <ItemTemplate>
                <asp:Label ID="lblSecondColumn" Runat="server"></asp:Label>
             </ItemTemplate>
        </asp:TemplateColumn>
        </Columns>
        PagerStyle Visible="False" NextPageText="" PrevPageText=""></PagerStyle>
        </asp:datagrid>
        For the set up of your datagrid you will want to create two TemplateColumns and then create a label control for each row that will be displayed in your datagrid. Looking at the website that your provided it looks like you will need 15 labels in each template column.

        Now in the code behind I loop through each item returned to the datagrid.

        //first create a global DataTable variable;
        DataTable dtable = new DataTable();

        //now create a method that you will call after you bind your data to the grid. I called this method BindTemplateCol umns();

        Code:
        private void BindTemplateColumns()
        {
        dtable = ds.Tables["WhateverYouNamedYourDataSetTable"];
        for (int i = 0; i < dgResults.Items.Count; i++)
        {
          DataRow row = dtable.Rows[i]; //this may affect your paging I had to use a Session value * a pageSize variable to correct an issue with paging.
        Label lbl1 = (Label)dgResults.Items[i].FindControl("lblFirstColumn")';
          lbl1.Text = row["columnname"].ToString();
        Label lbl2 = (Label)dgResults.Items[i].FindControl("lblSecondColumn")';
          lbl2.Text = row["columnname"].ToString();
        //repeat for every label that you create.
        }
        }
        In your search button click event you will want to execute your search proc put the results in ds.Tables["WhateverYouNam edYourDataSetTa ble"] then assign your datasource of the datagrid to ds.Tables["WhateverYouNam edYourDataSetTa ble"]. Then call the DataBind method of the datagrid. Next call BindTemplateCol umns().

        Code:
        dgResults.DataSource = ds.Tables["WhateverYouNamedYourDataSetTable"];
        dgResults.DataBind();	
        BindTemplateColumns();
        I hope this helps.

        Nathan

        Comment

        • orderofblessing
          New Member
          • Jun 2007
          • 4

          #5
          Thanks I really appreciate you guys on helping me but i still got issues as:

          I got the theory in mind but still cant create Dynamically Array of DataGrid/DataTable.

          I am trying to create an array of DataGrid and then displaying on the PlaceHolder. i.e:

          DataGrid objDataGrid = new DataGrid[10];

          But System giving me exception "Object reference not set to an instance of an object."

          Please have a look on my question again and let me know how i can solve this issue.

          Thanks again for giving me response...

          Regards
          Mian

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

            #6
            Just do what the php script did.
            Dynamicaly create a table object and populate it.
            As for paging, again, just follow what the php script did, stick everything as params:
            ?page=2&area=&t own=&bedrooms=& type=

            And you can search from that like you normally would.
            But when you see page=X you go:
            "ok self, we display 5 results per page and since he wants page X i will skip X*5 entries and display entries (X*5)+1 up to ((X*5)+1)+4 (for a total of 5)"
            then create your tables and add them to your page

            Comment

            • orderofblessing
              New Member
              • Jun 2007
              • 4

              #7
              Thanks for paging issue but the main issue is displaying data which i cant do with dynamic GridView/DataTable.

              Thanks
              Mian

              Comment

              • Plater
                Recognized Expert Expert
                • Apr 2007
                • 7872

                #8
                Originally posted by orderofblessing
                Thanks for paging issue but the main issue is displaying data which i cant do with dynamic GridView/DataTable.

                Thanks
                Mian
                I said use Table :-P
                You can create an instance of a table in your code. Then you add columns/rows just like you would anything else. (The output will be an html table)

                Comment

                Working...