Thursday, 29 December 2011

How to Get the Time in AM PM Format Just Copy and Paste Given Below Query

select substring(convert(varchar(20), GetDate(), 9), 13, 5)
+ ' ' + substring(convert(varchar(30), GetDate(), 9), 25, 2)

And how can it Concat with Time see the Given below examle:- 

select CONVERT(VARCHAR(10), GETDATE(), 103)+
substring(convert(varchar(20), GetDate(), 9), 13, 5)
+ ' ' + substring(convert(varchar(30), GetDate(), 9), 25, 2)

Tuesday, 27 December 2011

How to Select All Check Boxs of Gridview row on Single Selection of Header Check Box using JavaScript

function chkall(ival)
   var f= document.getElementById("GdvStatus");   

for(var i=0; i<f.getElementsByTagName("input").length ;i++ )
if(f.getElementsByTagName("input").item(i).type == "checkbox" )

How To Call:

<asp:CheckBox ID="ChkSelectAll" onclick="chkall(this.checked)" runat="server" />  

Monday, 26 December 2011

How To Show the Header of GridView When Data Source is nothing

There is a big Problem when Gridview Do not get the Datasource then it do not shows its Header. For Showing the header of Gridview when Data Source is nothing:

Public Sub BindAddress(ByVal id As Integer)
        Dim sql As String
   sql = "select id,Name,Mobile,bill_type_id,client_id,(select data from master_data md where md.data_id = ca.bill_type_id) as bill_type, Address1,Address2,Address3,"
        sql = sql & " case when bill_type_id = 6 then 1 else 0 end as RdAdd1"
        sql = sql & " from client_address ca where client_id =" & id

   Dim da As SqlDataAdapter = New SqlDataAdapter(sql, conn)
        Dim ds As DataSet = New DataSet()
        da.Fill(ds, "AddTbl")
        If ds.Tables(0).Rows.Count > 0 Then
            GdvAdd.DataSource = ds.Tables("AddTbl")
         ds.Tables(0).Rows.Add(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
         GdvAdd.DataSource = ds.Tables("AddTbl")
         GdvAdd.Rows(0).Visible = False
        End If

    End Sub

Tuesday, 20 December 2011

How to Set the position of Page when post back

Some times it happens that our web have a Grid View and Data Grid Contained lots of rows. Which makes Scrolling in Your page. If we clicks on a row and its redirect to another page then The Grid View and Data Grid Becomes Comes on Starting Position of Gridview or DataGrid. For Setting Your Grid View and Data Grid On Last Row Position the Given Below Property can be used.

Property of Page:

MaintainScrollPositionOnPostback ="true"


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Reports.aspx.vb" Inherits="Reports" MaintainScrollPositionOnPostback ="true" %>

Note: If your Grid is inside the Update panel then will not work. For Update Panel we use Given Below Process:


1. Put Given Below Script under the Script Manager tag.

   <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <script type="text/javascript" language="javascript">
    var prmExotic = Sys.WebForms.PageRequestManager.getInstance();

    function pageLoaded(sender, args) {


     function Exotic()
     document.getElementById("divExotic").scrollTop =document.getElementById("Hidden2").value;
   function FuncExotic()
   var s=document.getElementById("divExotic").scrollTop;




2. Put the Hidden Field Text Box Just below the Body tag.

  <input type="hidden" id="Hidden2" runat="server"           

3. Keep DataGrid and Gridview Control Inside the Given Below Div Tag.

<div runat="server" id="divExotic" style="width:580px;height:700px; overflow-x:hidden; overflow-y:scroll; text-align: left;" onscroll="FuncExotic()">
''------------ Pur Your Grid---------'


How to Convert Row in Column using Pivot concept


FROM student



Pivoting Query :-

select student_id, isnull(Student1,'') as St1,isnull(Student2,'') as St2,isnull(Student3,'') as St3,

isnull(Student4,'') as St4,isnull(Student5,'') as St5 from
(SELECT student_id, Student1,Student2,Student3,Student4,Student5
FROM student) up
PIVOT (SUM(Marks) FOR Student_name IN (Student1,Student2,Student3,Student4,Student5)) AS pvt
) ds1 ORDER BY student_id

OutPut :-


--SELECT eMP_ID,cALL_sTATUS_ID,isnull([1],0) AS R1,Isnull([2],0) --AS R2,ISNULL([3],0) AS R3,ISNULL([4],0) AS R4,ISNULL([5],0) AS --R5 FROM



--,count(*) AS CALLS

--from cALL C

--group by CALL_ID)

--P PIVOT ( SUM(CALLS) FOR CALL_id IN([1],[2],[3],[4],[5])) AS --pvt

Sunday, 18 December 2011

How to make single Selection of Radio Button in a Grid View using

Some time its happens in a Gridview have a column with more radio buttons but it do not select a single selection of a radio button. It selects all the radio buttons as you select it. For get Rid from this Problem. Given Below function can help you:

Protected Sub RdAdd_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim dr As GridViewRow
        Dim oldRow As RadioButton = GdvAdd.FindControl("rdadd")
        Dim count = 0
        'TextBox3667.Text = Request.Form("RDI")
        For Each dr In GdvAdd.Rows
            oldRow = CType(GdvAdd.Rows(count).FindControl("rdadd"), RadioButton)
            oldRow.Checked = False
            count += 1
        'ADD Old Value
        Dim NewRow As RadioButton = sender
        Dim row As GridViewRow = NewRow.NamingContainer
        NewRow.Checked = True
    End Sub

Thursday, 15 December 2011

How to do pagin in Gridview

Protected Sub GdvSrch_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs)

        GdvSrch.PageIndex = e.NewPageIndex
    End Sub

Thursday, 8 December 2011

Function For Convert Dataset To Excel Sheet

Public Sub ExportDataSetToExcel(ByVal ds As DataSet, ByVal filename As String)
  '--------Export Dataset To Excel---------------'
Dim attachment As String = "attachment; filename=" & filename & ".xls"
        Response.ClearContent()        Response.AddHeader("content-disposition",attachment)
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
        ' create a string writer  
        Using sw As New StringWriter()
            Using htw As New HtmlTextWriter(sw)
                ' instantiate a datagrid  
                Dim dg As New DataGrid()
                dg.DataSource = ds.Tables(0)
                dg.HeaderStyle.Font.Bold = True
            End Using
        End Using
    End Sub