How can we filter text from array in asp.net?

Search and Filter Array in ASP.Net.

I try and get solution: is like below:

I have an array which return data in size like 3,6,9,12,15.. (multiplication of 3)

Add the below code:


DataTable dt = new DataTable();
string GridData = ViewState["ShowItem"].ToString();
string[] FilterData = GridData.Split('^');

Above array return data like..

FilterData [0] = "Pizza";     (Item)
FilterData [1] = "2$";        (Price)
FilterData [2] = "2";         (Quantity)
FilterData [3] = "Burger";
FilterData [4] = "5$";
FilterData [5] = "1";
FilterData [6] = "Cesa";
FilterData [7] = "7$";
FilterData [8] = "3";

now I want to enter some data as column wise in database like:

Item     Price     uantity     Total(Price*Quantity)

Then add the below loop:


for (int nIndex = 0; nIndex < FilterData.Length; nIndex += 3)
{
    DataRow drow = dt.NewRow();
    drow["ProductItem"] = FilterData[nIndex];               // Item
    var cost = FilterData[nIndex + 1];                      // Cost
    var qty = FilterData[nIndex + 2];                       // Quantity
    drow["Cost"] = cost;
    drow["Quantity"] = qty;
    double Total =
        Convert.ToDouble(cost.Remove(cost.Length - 1)) *    // remove $
        Convert.ToInt32(qty);                               // Total
    drow["Total"] = Total;
    dt.Rows.Add(drow);
}

Hope it help you better:

About the Author

avatar