Wednesday, January 25, 2012

Disabling Export to Excel In Reportviewer


' In the Reportviewer Load call the CustomizeRV function
  Protected Sub ReportViewer1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles ReportViewer1.Load
        CustomizeRV(CType(sender, System.Web.UI.Control))
    End Sub


  'CustomizeRV definition
  Private Sub CustomizeRV(ByVal reportControl As System.Web.UI.Control)
        For Each childControl As System.Web.UI.Control In reportControl.Controls
            If childControl.[GetType]() Is GetType(System.Web.UI.WebControls.DropDownList) Then
                Dim ddList As System.Web.UI.WebControls.DropDownList = DirectCast(childControl, System.Web.UI.WebControls.DropDownList)
                AddHandler ddList.PreRender, New EventHandler(AddressOf ddList_PreRender)
            End If
            If childControl.Controls.Count > 0 Then
                CustomizeRV(childControl)
            End If
        Next
    End Sub

    'Event handler definition
Private Sub ddList_PreRender(ByVal sender As Object, ByVal e As EventArgs)
        If sender.[GetType]() Is GetType(System.Web.UI.WebControls.DropDownList) Then
            Dim ddList As System.Web.UI.WebControls.DropDownList = DirectCast(sender, System.Web.UI.WebControls.DropDownList)
            Dim listItems As System.Web.UI.WebControls.ListItemCollection = ddList.Items

            If (listItems IsNot Nothing) AndAlso (listItems.Count > 0) AndAlso (listItems.FindByText("Excel") IsNot Nothing) Then
                For Each list As System.Web.UI.WebControls.ListItem In listItems
                    If list.Text.Equals("Excel") Then
                        list.Enabled = False
                    End If
                Next
            End If
        End If
    End Sub

Thursday, December 8, 2011

Paging in Gridview If we dont set Datasource

Declare the dataset as
Shared ds as new Dataset

Bind the gridview using dataset as

Gridview1.Datasource = ds.Table(0)
Gridview1.DataBind()

After that make the AllowPaging = True

Then we have to handle  PageIndexChanging event as bel;ow

Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
        Try
            GridView1.PageIndex = e.NewPageIndex
            GridView1.DataSource = dsTmp.Tables(0)
            GridView1.DataBind()
        Catch ex As Exception

        End Try
    End Sub

Working with Gridview in ASP.NET

Suppose the gridview contains four columns with the last two column as template with Hyperlink
When I click that Hyperlink I need that value in some where say TextBox


                             
 

and in the code behind GridView1_RowCommand event

If e.CommandName = "claim" Then
            Dim index As Integer = Convert.ToInt32(e.CommandArgument)

            Dim row = GridView1.Rows(index)

            Dim lin As LinkButton = CType(row.FindControl("ClaimLink"), LinkButton)
            Dim lin2 As LinkButton = CType(row.FindControl("TransLink"), LinkButton)

            ClaimID.Text = lin.Text
            TRansID.Text = lin2.Text
End If

Wednesday, October 27, 2010

Filtering in DataTable or Dataset

First fill the datatable or dataset as normal

then if we want to filter the datatable / dataset depending upon say textboxchanged event

string expr = "";
expr = "_ItemName like '"+txt.Text+"*'";
dt.DefaultView.RowFilter = expr;
dgv.DataSource = dt.DefaultView;

Here _ItemName is the Column used for Filtering

Monday, March 1, 2010

Summary for file encryption and decryption

Import IO and Security.Cryptography

File Decryption
Dim ue As New UnicodeEncoding()
Dim key As Byte() = ue.GetBytes(pword)
Dim rm As New RijndaelManaged()
Dim fs1 As New FileStream(file_path, FileMode.Open)
path = save_path
Dim str As String(), st As String()
str = file_path.Split("\"c)
Dim str1 As String = str(str.Length - 1)
st = str1.Split("."c)
save_path = path & "\" & st(0) + "." & st(1)
Dim i As Integer = 0
Dim fs2 As New FileStream(save_path, FileMode.Create)
Dim cs As New CryptoStream(fs2, rm.CreateDecryptor(key, key), CryptoStreamMode.Write)
While (True)
Dim d As Integer
d = fs1.ReadByte()
If d = -1 Then
Exit While
End If
cs.WriteByte(Convert.ToByte(d))
End While
cs.Close()
fs1.Close()

File Encryption
Dim ue As New UnicodeEncoding()
Dim key As Byte() = ue.GetBytes(pword)
Dim rm As New RijndaelManaged()
Dim fs1 As New FileStream(file_path, FileMode.Open)
path = save_path
Dim str As String(), st As String()
str = file_path.Split("\"c)
Dim str1 As String = str(str.Length - 1)
save_path = path + "\" + str1 + ".cpt"
Dim i As Integer = 0
While (True)
If File.Exists(save_path) Then
st = str1.Split("."c)
i = i + 1
save_path = path + "\" & st(0) & "(" & i & ")" & "." & st(1) & ".cpt"
Else
Exit While
End If
End While
Dim fs2 As New FileStream(save_path, FileMode.Create)
Dim cs As New CryptoStream(fs2, rm.CreateEncryptor(key, key), CryptoStreamMode.Write)
While (True)
Dim d As Integer
d = fs1.ReadByte()
If d = -1 Then
Exit While
End If
cs.WriteByte(Convert.ToByte(d))
End While
cs.Close()
fs1.Close()

Write values in registry

First import Microsoft.win32

'select a prticular registry directory
registrydirectory = Registry.LocalMachine.OpenSubKey("SOFTWARE", True)
'createt ou own registry directory
registrydirectory.CreateSubKey("MyDir")

'open our own registry directory
registrydirectory = Registry.LocalMachine.OpenSubKey("Software\MyDir", True)
'write values and version
registrydirectory.SetValue("String Type", "String Data")
registrydirectory.Close()

Connection String Using Access 2007

cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + "Location with filename as String" + ";Jet OLEDB:Database Password=;"