0

I have to use datatable and make things like given in the image

I want my ui to look like this using data tables instead that they are normally shown in table format

the data must be picked from the database and then retrieved by ajax the retrieve function will be looking like

public static List<string[]> AllItems()
{
    List<string[]> ItemList = new List<string[]>();
    using (MySqlConnection exmp = new MySqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString))
    {
        using (MySqlCommand getAllItems = new MySqlCommand())
        {
            getAllItems.Connection = exmp;
            getAllItems.CommandType = CommandType.Text;
            getAllItems.CommandText = "SELECT * FROM table1";

            exmp.Open();
            MySqlDataReader reader = getAllItems.ExecuteReader();
            while (reader.Read())
            {
                string[] temp = new string[8];
                //Item Name
                temp[0] = reader[0].ToString();
                // Item Nick Name
                temp[1] = reader[1].ToString();
                //Item property
                temp[2] = reader[2].ToString();
                //Item Image URl
                temp[3] = reader[3].toString();
                //Item Price
                temp[4] = reader[4].toString();
                //Item Special Property that makes a link
                temp[5] = reader[5].toString();

                ItemList.Add(temp);
            }
        }
    }
    return ItemList;
}

My ajax function to retrieve json

 $.ajax({
            type: "POST",
            url: "default.aspx/AllItems",
            data: {},
            contentType: "application/json",
            dataType: "json",
            success: OnSuccess
        });

Now using the code given above for retrieving data from database, I have to make a structure as given in the pic mentioned above using datatables How can I do it?

Please provide some sample code; I'll be grateful to you.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
aashishkr
  • 55
  • 1
  • 7
  • webforms ? MVC ? Webforms has repeater control that you can use. In MVC you can create a div that looks like first section and then iterate over your result to append results. – Hakunamatata Jul 14 '16 at 04:12
  • webforms, but i preffer datatables because i need to include search and pagination feature to which datatables provides easily – aashishkr Jul 14 '16 at 04:15
  • http://stackoverflow.com/questions/22904666/using-pagination-with-repeater-control-in-asp-net-web-form check this answer – Hakunamatata Jul 14 '16 at 04:33
  • still i think datatables will be good because i have to make search function which will be tough and require more effort – aashishkr Jul 14 '16 at 05:33

0 Answers0