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=;"

Script for adjust the web pages as center

function align()
{

var lmt = document.getElementById('center');
var container = document.documentElement;

if(lmt && container)
{
var containerHeight;
if (container.innerWidth)
{
containerHeight = container.innerHeight;
}
else
{
containerHeight = container.clientHeight;
}
var lmtHeight;
if (lmt.innerWidth)
{
lmtHeight = lmt.innerHeight;
}
else
{
lmtHeight = lmt.offsetHeight;
}
var y = Math.ceil((containerHeight - lmtHeight) / 2);
if(y <>
{
y = 0;
}
lmt.style.position = "relative";
lmt.style.top = y + "px";
}
if (document.getElementById)
{
document.body.style.visibility = 'visible';
}

}

function addevent(obj,evt,fn,capt){
if(obj.addEventListener)
{
obj.addEventListener(evt, fn, capt);
return true;
}
else if(obj.attachEvent)
{
obj.attachEvent('on'+evt, fn);
return true;
}
else return false;
}

if (document.getElementById && document.getElementsByTagName)
{
addevent(window, 'load', align, false);
addevent(window, 'resize', align, false);
}