Thursday, 25 August 2016

How to Enable and Disable all Validations Controls in a single page in Asp.net C#

For Disable validation controls in a page
public void DisableAllValidations(ControlCollection cntrls)
{
     foreach (Control ctrl in cntrls)
     {
        if (ctrl is CompareValidator)
            ((CompareValidator)ctrl).Enabled = false;
        if (ctrl is CustomValidator)
            ((CustomValidator)ctrl).Enabled = false;
        if (ctrl is RangeValidator)
            ((RangeValidator)ctrl).Enabled = false;
        if (ctrl is RegularExpressionValidator)
            ((RegularExpressionValidator)ctrl).Enabled = false;
        if (ctrl is RequiredFieldValidator)
            ((RequiredFieldValidator)ctrl).Enabled = false;
        DisableForm(ctrl.Controls);
     }
}
For Enable validation controls in a page
public void DisableAllValidations(ControlCollection cntrls)
{
     foreach (Control ctrl in cntrls)
     {
        if (ctrl is CompareValidator)
            ((CompareValidator)ctrl).Enabled = true;
        if (ctrl is CustomValidator)
            ((CustomValidator)ctrl).Enabled = true;
        if (ctrl is RangeValidator)
            ((RangeValidator)ctrl).Enabled = true;
        if (ctrl is RegularExpressionValidator)
            ((RegularExpressionValidator)ctrl).Enabled = true;
        if (ctrl is RequiredFieldValidator)
            ((RequiredFieldValidator)ctrl).Enabled = true;
        DisableForm(ctrl.Controls);
     }
}

Calculate the duration of the visit based on the Start and End Date. The duration will only count regular business days (does not count weekends or holidays)

private double GetBusinessDays(DateTime startD, DateTime endD)
{
   double calcBusinessDays =
           1 + ((endD - startD).TotalDays * 5 -
               (startD.DayOfWeek - endD.DayOfWeek) * 2) / 7;

   if (endD.DayOfWeek == DayOfWeek.Saturday) calcBusinessDays--;
   if (startD.DayOfWeek == DayOfWeek.Sunday) calcBusinessDays--;
   return calcBusinessDays;
}

Tuesday, 19 January 2016

How to get DatakeyValues in ItemCommand in Telerik Radgrid

Please use below code to get data key values from telerik radgrid.
protected void CompleteTickets_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == "Delete")
        //Ticket ID
        GridDataItem item = (GridDataItem)e.Item;
    int ticketID = Convert.ToInt32(item.GetDataKeyValue("TicketID"));
}

How to set row number in telerik radgrid or in asp.net gridview

Below code will give you the solution to set row number in telerik radgrid or in asp.ner gridview.

   
    <%# Container.DataSetIndex + 1 %>
  

How to get selected rowindex in repeater asp.net

Below is the code to get selected rowindex in repeater.
RepeaterItem i = (sender as RadComboBox).NamingContainer as RepeaterItem;
int index = i.ItemIndex;

Sunday, 29 November 2015

How to select first row in Telerik Radgrid when page load occurs.

protected void RadGrid1_PreRender(object sender, EventArgs e)
{
  RadGrid1.MasterTableView.Items[0].Selected = true;
}

Sunday, 11 October 2015

How to remove a service from windows Service


    Open command prompt in administrative mode.
    Then type  sc delete <your service name> .Then press enter