Wednesday, March 27, 2024

Remove double record in List

 

files = files.Distinct(new FileInfoComparer()).ToList();//remove double records


 public class FileInfoComparer : IEqualityComparer<FileInfo>

    {

        public bool Equals(FileInfo x, FileInfo y)

        {

            return x.Name == y.Name;

        }


        public int GetHashCode(FileInfo obj)

        {

            return obj.Name.GetHashCode();

        }

    }

Thursday, July 6, 2023

Change Display of an Javascript RadioButton using ASP.net C#

 ASP.net Page:

Pickup location: <input runat="server" id="inRadHome" checked type="radio" name="inRadioPickup" value="Home" />Home  


Behind c# page :

if(condition)

{

 string script_clinic = "<script type='text/javascript'>document.getElementById('inRadHome').value = 'Clinic'; document.getElementById('inRadHome').nextSibling.nodeValue = 'Clinic'; </script>";

        ClientScript.RegisterStartupScript(this.GetType(), "ChangeInputValue", script_clinic);

}

Tuesday, June 20, 2023

Use DropDownList in EditTemplate in GridView

 Instead using a TextBox in the EditTemplate of a GridView, if needed you can use a DropdownList , here is a code in HTML page  :

<EditItemTemplate>                        

         <asp:DropDownList ID="type_edit" runat="server" AutoPostBack="true" SelectedValue='<%# Bind("transaction_type") %>' >

                    <asp:ListItem Value="" ></asp:ListItem>

                    <asp:ListItem Value="LOAN">LOAN</asp:ListItem>

                    <asp:ListItem Value="PRINCIPAL PAYMENT">PRINCIPAL PAYMENT</asp:ListItem>

                    <asp:ListItem Value="INTEREST PAYMENT">INTEREST PAYMENT</asp:ListItem>

             </asp:DropDownList>

  </EditItemTemplate>


You do not have to write anything in code behind page.😀😀

Thursday, December 31, 2020

Transfer a textbox content of a popup window to a textbox of parent page


Transfer a textbox content of a popup window to a textbox of parent page

 <script type="text/javascript">      

    document.getElementById('Button2').onclick = function () {

        if (window.opener != null && !window.opener.closed) {

            var txtNew = window.opener.document.getElementById("TextBox1");

            txtNew.value = txtNew.value + "\n\n" + document.getElementById("TextBox_sms").value;

        } 

        window.close();

    }       

</script>


Monday, September 30, 2019

Check if string contains any matches in a string array


Check if string contains any matches in a string array

string med="TESTSTRIPS, LANCETS, ETOH SWABS #100";
string[] items = { "TESTSTRIPS", "GLUCOMET" };
 bool isneed_referal = items.Any(c => med.Contains(c));

Thursday, May 18, 2017

Convert a "YYYYMMDDHHMMSS" format string value to a DateTime value

string formatString = "yyyyMMddHHmmss";
string sample = "20100611221912";
DateTime dt = DateTime.ParseExact(sample,formatString,null);