1

I right now have an array that I would like to display on my aspx page. When making my table on my aspx I need to have it so that it takes the size of my array regardless of how many rows. I am not sure how to do this, besides looping through my array to find values/size. How would I push my array to display the contents on my webpage?

Code Behind:

protected void Page_Load(object sender, EventArgs e)
        {

            Service1 myService = new Service1();
            string passed_value = Request.QueryString["parameter"];

            //runs to get array
            //returns array
            string[][] array;
            array = myService.Get_Array(passed_value);

        }

array for example:

@[0][0]123
@[0][1]C:\file\file_name.txt
@[0][2]file_name

and so on..

aspx just has a div for the table, I know how to make a table but not one that is dynamic. Sorry it's not much.

  <div class="table">

  </div>
2
  • 2
    Use GridView. Commented Oct 3, 2016 at 14:38
  • That should solve my issues, I didn't know my options. @PawanNogariya Commented Oct 3, 2016 at 14:43

1 Answer 1

1

The answer was using GridView thanks to @Pawan Nogariya. I hope this helps future users who are trying to display arrays since there are not many solutions unless you know about GridView.

ASPX:

   <asp:GridView ID="Grid" runat="server"
    AutoGenerateColumns = "false" Font-Names = "Arial"
    Font-Size = "11pt" AlternatingRowStyle-BackColor = "#C2D69B" 
    HeaderStyle-BackColor = "green" AllowPaging ="true"  
    PageSize = "10">
   <Columns>
    <asp:BoundField ItemStyle-Width = "150px"
     DataField = "ID" HeaderText = "ID" />
    <asp:BoundField ItemStyle-Width = "150px"
     DataField = "Path" HeaderText = "Path" />
    <asp:BoundField ItemStyle-Width = "150px"
     DataField = "Name" HeaderText = "Name" />
   </Columns>
   </asp:GridView>

Codebehind:

  DataTable dt = new DataTable();
            dt.Columns.Add("ID", Type.GetType("System.String"));
            dt.Columns.Add("Path", Type.GetType("System.String"));
            dt.Columns.Add("Name", Type.GetType("System.String"));
            for (int i = 0; i < length; i++)
            {
                dt.Rows.Add();
                dt.Rows[dt.Rows.Count - 1]["ID"] = array[i][0];
                dt.Rows[dt.Rows.Count - 1]["Path"] = array[i][1];
                dt.Rows[dt.Rows.Count - 1]["Name"] = array[i][2];
            }
            Grid.DataSource = dt;
            Grid.DataBind(); 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.