Wednesday, 25 July 2012

How to select a distinct values from particular column in the datatable

// here 'm datatable from cache which is already stored, u can careate ur own datatable  

                    DataTable NewGdt = (DataTable)HttpRuntime.Cache[cachekey];
                    DataView Griddataview = new DataView(NewGdt);


                    DataTable distinctValues = Griddataview.ToTable(true, "Columnname");

How to implement Nested Gridview (Gridview within a gridview)



In Design page:

 <asp:GridView CssClass="content" ID="GVDistrict" runat="server" Width="100%" HorizontalAlign="Left" DataKeyNames="DISTRICT"
 AutoGenerateColumns="False" CaptionAlign="Left" OnRowDataBound="GVDistrict_OnRowDataBound"   >
 <Columns>
 <asp:BoundField DataField="DISTRICT" HeaderText="District">
     <HeaderStyle Width="12%" />
 </asp:BoundField>
   <asp:TemplateField HeaderText="Category Details">
 <ItemTemplate>

 <asp:GridView CssClass="content" ID="CategoryDeatils" runat="server" Width="100%" CaptionAlign="Left"
  AutoGenerateColumns="False" AllowSorting="True" HorizontalAlign="Left" >
  <columns>
   <asp:BoundField Datafield="PKG_CATEGORY" HeaderText="Category" />
    <asp:BoundField Datafield="CASES" HeaderText="#Cases" />
     <asp:BoundField Datafield="AMT" HeaderText="Package Amt." />     
    <asp:BoundField Datafield="TOTALAPPAMOUNT" HeaderText="Total App. Amt."/>
  </columns>
  <HeaderStyle CssClass="headerContent" HorizontalAlign="Left" />
 <AlternatingRowStyle HorizontalAlign="Left" BackColor="GhostWhite" />
 </asp:GridView>


 </ItemTemplate>
 </asp:TemplateField>
 </Columns>
 <HeaderStyle CssClass="headerContent" HorizontalAlign="Left" />
 <AlternatingRowStyle HorizontalAlign="Left" BackColor="GhostWhite" />
 </asp:GridView>




In code behind:

protected void bindparentgridview()

            
    {       

                  try
                  {

                    // Get some data in datatable and bind it to parent gridview


                    GVDistrict.DataSource = Gdt;
                    GVDistrict.DataBind();
                  }
                   
                
                   catch (HttpException ex)
                 {
                   Lblmsg.Text = "There seems to be problem in Network Connectivity. Please try again." + ex.ToString();
                 }
                   catch (Exception ex)
                 {
                   Lblmsg.Text = "There seems to be an Exception.  !!" + ex.ToString();
                 }

             
    }




 protected void GVDistrict_OnRowDataBound(object sender, GridViewRowEventArgs e)
    {



        if (e.Row.RowType == DataControlRowType.DataRow)
        {
           
           // get childgridview control here

           GridView ChildGridview = ((GridView)e.Row.FindControl("CategoryDeatils"));


          
            try
            {

              // get some datatable dt and bind the childgridview here

               
                ChildGridview.DataSource = dt;
                ChildGridview.DataBind();


            }
            catch (HttpException ex)
            {
                Lblmsg.Text = "There seems to be problem in Network Connectivity. Please try again." +    ex.ToString();
            }
            catch (Exception ex)
            {
                Lblmsg.Text = "There seems to be an Exception.  !!" + ex.ToString();
            }


        }

    }



Monday, 2 July 2012

How to get only valid dates from a varchar date field in oracle





First we need to create a function as below:


CREATE OR REPLACE FUNCTION MY2DATE (p_str IN VARCHAR2
  ,format_picture IN VARCHAR2
)
   RETURN DATE
IS
BEGIN
   RETURN TO_DATE(p_str, format_picture);
EXCEPTION
   WHEN OTHERS
   THEN
      RETURN NULL;
END;




Call that function with field name and the valid date format while selecting:

SELECT MY2DATE(FIRST,'dd/mm/YYYY HH:MM AM') FROM ORDERS

Thursday, 28 June 2012

Comparing Date between Two dates


Example: to_date(AUTHORIZEDTIME,'mm/dd/YYYY HH12:MI:SS AM') between to_date('" + fromdate + "','dd/mm/yyyy') and to_date('" + tilldate + "','dd/mm/yyyy') ORDER BY dateorder DESC


Syntax: to_date(Fieldname,'Date Format')  between to_date(Fieldname,'Date Format') and to_date(Fieldname,'Date Format')

Wednesday, 20 June 2012

For checking all the rows in a gridview to check for already existing Identical values

int rowindex = GVRules.SelectedIndex;
        foreach (GridViewRow gvrow in GVRules.Rows)
        {
            if (gvrow.RowIndex != rowindex)
            {
                if (DdlRule.SelectedValue == GVRules.DataKeys[gvrow.RowIndex].Values[2].ToString()

&& DdlMemPrmZone.SelectedItem.Text == gvrow.Cells[2].Text && DdlMemProvZone.SelectedItem.Text ==

gvrow.Cells[3].Text)
                {
                    Label1.Text = "Rule " + DdlRule.SelectedItem.Text + " for Member Premium Zone "

+ DdlMemPrmZone.SelectedItem.Text + " and Member Provider Zone " + DdlMemProvZone.SelectedItem.Text

+ " is already added to this Policy !!";
                    return false;
                }
            }

        }

Sorting the gridview column wise, using datasource

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for AutowithholdruleforDS
/// </summary>
public class AutowithholdruleforDS
{
    public AutowithholdruleforDS()
    {
        string Cachekey = "AutowithholdRule_" + HttpContext.Current.Session.SessionID;
         this.CD1 = (DataTable)HttpRuntime.Cache[Cachekey];
    }
    private DataTable CD1;

    public DataView Select()
    {
        if (this.CD1 != null)
        {
            this.CD1.DefaultView.Sort = "";
            return this.CD1.DefaultView;
        }
        else
        {
            return null;
        }
    }
}

Email validation using Javascript

function EmailValidCheck(emailtxt)
{
 var email1=document.getElementById(emailtxt).value;
 var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i;
 if(email1.length>0)
 {
 var returnval=emailfilter.test(email1);
 if (returnval==false)
 {
 alert("Please Enter Valid Employee Email ID !!")
 document.getElementById(emailtxt).focus();
 return false;
 }
 }
}