none
how to make a validation list in c# RRS feed

  • Question

  • please help me, iam newbie

    here i have a problem
    
    I have thousands of data in the datatable, I take this example only.
    
    I want to checklist
    
    1) unitid checklist must not be more than one if more than one then the error
    
    2) may not be the same unitid checklist, if the same then an error
    
    3) unitid must be the same but the date must be different, if the same then an error
    
    4) The date must be different unitid must be the same, otherwise error
    
    please help the masters
    
    Thank you very much
    
    I have created the code as below but it is not optimal

    if (JobType == "MUnit1bill")
                {
                     if (dt.Rows.Count > 0)
                    {
                        DataView view = new DataView(dt);
                        DataTable distinctValues1 = view.ToTable(true, "Unitid");
                        DataTable distinctValues2 = view.ToTable(true, "Duedatebaru");
                        DataTable distinctbill = view.ToTable(true, "BillingGroupID");
                        DataTable distinctcust = view.ToTable(true, "Customerid");
                      
                      
                        if (distinctValues1.Rows.Count == 1)
                        {
                            lblMessage.Text = "Unit  tidak boleh sama";
                            error = true;
                        }
                        if (distinctValues2.Rows.Count > 1)
                        {
                            lblMessage.Text = "Duedatebaru  tidak boleh lebih dari satu";
                            error = true;
                        }
                      
                        if (distinctbill.Rows.Count != distinctcust.Rows.Count)
                        {
                            lblMessage.Text = "Billingroup tidak boleh lebih dari satu";
                            error = true;
                        }
                        if (error)
                        {
                            GridView1.DataSource = null;
                            GridView1.DataBind();
                            dtChecked.Clear();
                        }}
                        if (!error)
                        {  

                            GridView1.DataSource = dtChecked.DefaultView;
                            GridView1.DataBind();
                            dtChecked.Clear();
                        }

                    }


    • Edited by Mey Cat Monday, December 2, 2019 4:11 AM
    Monday, December 2, 2019 3:32 AM

All replies

  • Hi Mey Cat,

    Thank you for posting here.

    Your description and your code look a little different, I’m not sure what you mean.

    Based on your code, I have a suggestion, you could adjust the code structure like this:

               if (dt.Rows.Count > 0)
                {
                  ...
                }
                if (error)
                {
                    ...
                }else
                {
                    ...
                }

    If I misunderstand what you mean, please describe your problem again.

    And is this project an asp.net project?

    If so, you can ask this question in the Asp.net forums.

    Hope this could be helpful.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Monday, December 2, 2019 8:02 AM