locked
How to get missed No RRS feed

  • Question

  • User-807418713 posted

    Hello

    This is my table1 data

    RefNo ItemName Qty
    R001 Item1 4
    R002 Item3 2
    R003 Item4 1
    R004 Item1 5
    R005 Item3 6

    Now i delete R004  Record In Table1

    on page load it should shows alert you want R004 if user click yes then it should show R004 in Label1 if user says NO then R006 in Label1

    how to do so using asp.net c#

    Thanking You

    Tuesday, September 1, 2020 7:35 PM

All replies

  • User475983607 posted

    Sort the array then find where the index does not math the RefNo.  Depending on sort order is general not good design and leads to data errors.

    static void Main(string[] args)
    {
        List<string> items = new List<string>() { "R002", "R001", "R003", "R005" };
        items.Sort();
    
        string item = string.Empty;
    
        for(int i = 1; i <= items.Count(); i++)
        {
            if(int.Parse(items[i-1].Substring(1)) != i)
            {
                item = "R" + i.ToString("D3");
                break;
            }
        }
    
        if(string.IsNullOrEmpty(item))
        {
            item = "R" + (items.Count()+1).ToString("D3");
        }
    
        Console.WriteLine(item);
    
    }

    Tuesday, September 1, 2020 8:51 PM