RSS

Monthly Archives: April 2011

Adrotator use XML for Advertisement


Create User Control

<div   style=”padding-top:2px; padding-left:0px;” id=”rotator”>

<asp:AdRotator ID=”adRtrCtrl” Target=”parent” runat=”Server” Width=”300px” Height=”250px” AdvertisementFile=”~/Advertisement/Advertisements.xml” AlternateTextField=”Hello” BorderStyle=”Solid” BorderWidth=”1px” BorderColor=”White”/></div>

Xml file

<Advertisements>

<Ad>

<ImageUrl>AdsImg/car.jpg</ImageUrl>

<NavigateUrl>https://humrahimcs.wordpress.com</NavigateUrl&gt;

<Alt>Csharp code</Alt>

<Caption>Csharp Site</Caption>

<Impressions>2</Impressions>

</Ad>

<Ad>

<ImageUrl>AdsImg/Advance.jpg</ImageUrl>

<NavigateUrl>https://humrahimcs.wordpress.com</NavigateUrl&gt;

<Alt>VB.Net</Alt>

<Caption>Visual Basic</Caption>

<Impressions>2</Impressions>

</Ad>

<Ad>

<ImageUrl>AdsImg/flower.jpg</ImageUrl>

<NavigateUrl>http://www.goolge.com</NavigateUrl&gt;

<Alt>Csharp code</Alt>

<Caption>Csharp Site</Caption>

<Impressions>2</Impressions>

</Ad>

<Ad>

<ImageUrl>AdsImg/main-image.jpg</ImageUrl>

<NavigateUrl>http://www.cricinfo.com</NavigateUrl&gt;

<Alt>.Net Professional Job Site</Alt>

<Caption>VS.Net</Caption>

<Impressions>2</Impressions>

</Ad>

</Advertisements>

Add User control in aspx page

Add Reference of User Control

<%@ Register Src=”~/controls/AdvertisementHome.ascx” TagName=”Ads” TagPrefix=”uc” %>

Add Script Manager for Ajax auto update Panel

<asp:ScriptManager ID=”ScriptManager1″ runat=”server”>

</asp:ScriptManager>

Add Update Panel and User Control

<asp:Timer ID=”Timer1″ runat=”server”  Interval=”10000″ Enabled=”True”>

</asp:Timer>

<asp:UpdatePanel ID=”UpdatePanel1″ runat=”server” style=” border:solid 0px white; “>

<Triggers>

<asp:AsyncPostBackTrigger ControlID=”Timer1″ EventName=”Tick” />

</Triggers>

<ContentTemplate >

<asp:Label ID=”Label1″ runat=”server” Text=”” />

<uc:Ads runat=”server” ID=”ctr_ads”  />

</ContentTemplate>

</asp:UpdatePanel>

Advertisements
 
1 Comment

Posted by on April 18, 2011 in ASP Dot Net C#

 

Dynamically Create Multiple File Upload Control with ASP.Net C#


Dynamically Create Multiple File Upload Control with ASP.Net C#

MultipleFileUploadControl.aspx

1:Create Javascript Function for Generate Dynamic Control

<script type=”text/javascript” language=”javascript”>

function AddNewRow() {

var rownum = 1;

var div = document.createElement(“div”)

var divid= “dv” + rownum

div.setAttribute(“ID”,divid)

rownum++

var lbl = document.createElement(“label”)

lbl.setAttribute(“ID”, “lbl” + rownum)

lbl.setAttribute(“class”, “label1”)

lbl.innerHTML = “Images”

rownum++

var _upload = document.createElement(“input”)

_upload.setAttribute(“type”, “file”)

_upload.setAttribute(“ID”, “upload” + rownum)

_upload.setAttribute(“runat”, “server”)

_upload.setAttribute(“name”,”uploads”+rownum)

rownum++

var hyp = document.createElement(“a”)

hyp.setAttribute(“style”, “cursor:Pointer”)

hyp.setAttribute(“onclick”, “return RemoveDv(‘” + divid + “‘);”);

hyp.innerHTML = “Remove”

rownum++

var br=document.createElement(“br”)

var _pdiv = document.getElementById(“Parent”)

div.appendChild(br)

div.appendChild(lbl)

div.appendChild(_upload)

div.appendChild(hyp)

_pdiv.appendChild(div)

}

function RemoveDv(obj) {

var p = document.getElementById(“Parent”)

var chld = document.getElementById(obj)

p.removeChild(chld)

}

</script>

2: Write this code in aspx body tag

<table cellpadding=”0″ cellspacing=”0″ width=”100%” border=”0″>

<tr id=”Tr1″ runat=”Server”>

<td>

<label>

Photo:</label><asp:FileUpload ID=”uploadPhoto1″ runat=”server” CssClass=”” /><br />

<div id=”Parent”>

</div>

<label>

&nbsp;</label>

<input type=”button” onclick=”AddNewRow(); return false;”  value=”More” />&nbsp;

<asp:Button ID=”btnAddPhoto” Text=”add photo” runat=”server”

onclick=”btnAddPhoto_Click1″ />&nbsp;

<asp:Button ID=”btnCancel” Text=”cancel” runat=”server” />

</td></tr></table>

CodeBehind  Code

MultipleFileUploadControl.CS

public Byte[] GetFileContent(System.IO.Stream inputstm)

{

Stream fs=inputstm;

BinaryReader br=new BinaryReader(fs);

Int32 lnt = Convert.ToInt32(fs.Length);

byte[] bytes = br.ReadBytes(lnt);

return bytes;

}

private void SavePhotoContent()

{

HttpPostedFile postFile;

string ImageName=string.Empty;

byte[] path;

string[] keys;

try{

string contentType=string.Empty;

byte[] imgContent=null;

string[] PhotoTitle;

string PhotoTitlenme;

HttpFileCollection files = Request.Files;

keys = files.AllKeys;

for (int i = 0; i < files.Count; i++)

{

postFile = files[i];

if (postFile.ContentLength > 0)

{

// postFile.SaveAs(Server.MapPath(“Uploads”) + “\\” + System.IO.Path.GetFileName(postFile.FileName));

contentType = postFile.ContentType;

path = GetFileContent(postFile.InputStream);

ImageName = System.IO.Path.GetFileName(postFile.FileName);

PhotoTitle = ImageName.Split(‘.’);

PhotoTitlenme=PhotoTitle[0];

}

}

}

catch (Exception ex){

ex.Message.ToString();

}

}

protected void btnAddPhoto_Click1(object sender, EventArgs e)

{

SavePhotoContent();

}

 
11 Comments

Posted by on April 15, 2011 in ASP Dot Net C#

 

Tags:

Dynamically Create Multiple File Upload Control with Vb.Net


MultipleFileUploadControl.aspx

1:Create Javascript Function for Generate Dynamic Control

<script type=”text/javascript”>

var rownum = 1;

function addRow() {

//Create div dynamically.

var dv = document.createElement(“div”);

//Assign different attributes to the element.

var divid = “div” + rownum;

dv.setAttribute(“ID”, divid);

rownum++;

// Create label dynamically

var label2 = document.createElement(“label”);

//Assign different attributes to the label.

label2.setAttribute(“ID”, “lbl” + rownum);

label2.setAttribute(“class”, ‘label1’);

label2.innerHTML = ‘Photo’;

rownum++;

//Create file upload dynamically(Thumbnail)

var element2 = document.createElement(“input”);

//Assign different attributes to the element.

element2.setAttribute(“type”, ‘file’);

element2.setAttribute(“name”, “fl” + rownum);

element2.setAttribute(“ID”, “flup” + rownum);

element2.setAttribute(“runat”, “Server”);

rownum++;

// Create remove link

var atag = document.createElement(“a”);

//Assign different attributes to the element.

atag.setAttribute(“ID”, “atg” + rownum);

atag.setAttribute(“style”, “cursor:pointer”);

atag.setAttribute(“onclick”, “return RemoveDiv(‘” + divid + “‘);”);

atag.innerHTML = ‘Remove’;

rownum++;

// create br

var br = document.createElement(“br”);

var upl1 = document.getElementById(“upl1”);

dv.appendChild(br);

//

dv.appendChild(label2);

dv.appendChild(element2);

dv.appendChild(atag);

upl1.appendChild(dv)

}

function RemoveDiv(obj) {

var parent = document.getElementById(‘upl1’);

var child = document.getElementById(obj);

parent.removeChild(child);

}    </script>

2: Write this code in aspx body tag

<div style=”padding-right:200px;”>

<asp:Label ID=”lblErrMSG” CssClass=”titlered” runat=”server” Visible=”false” Font-Bold=”true” />

</div>

<table cellpadding=”0″ cellspacing=”0″ width=”100%” border=”0″>

<tr runat=”Server”>

<td>

<label>

Photo:</label><asp:FileUpload ID=”uploadPhoto1″ runat=”server” CssClass=”” /><br />

<div id=”upl1″>

</div>

<label>

&nbsp;</label>

<asp:Button ID=”btnmore” Text=”More” runat=”server” />&nbsp;

<asp:Button ID=”btnAddPhoto” Text=”add photo” runat=”server” />&nbsp;

<asp:Button ID=”btnCancel” Text=”cancel” runat=”server” />

</td>

</tr>

</table>

CodeBehind  Code

MultipleFileUploadControl.vb

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

If Not Page.IsPostBack Then

btnmore.Attributes(“onclick”) = “addRow(); return false;”

End If

End Sub

Protected Sub btnAddPhoto_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddPhoto.Click

SavePhotoContent()

End Sub

Private Sub SavePhotoContent()

Dim postFile As HttpPostedFile

Dim files As HttpFileCollection

Dim keys() As String

Dim totolupld As Integer = 0

Dim isupld As Boolean = False

lblErrMSG.Visible = True

lblErrMSG.Text = String.Empty

Dim  ImgPath As Byte()

Dim contentType As String = String.Empty

Dim imageName As String = String.Empty

Dim photoTitle As String = String.Empty

Try

Dim contentType As String = String.Empty

Dim imgContent As Byte() = Nothing

Dim ImageName As String = String.Empty

files = Request.Files

keys = files.AllKeys

For ndx As Integer = 0 To keys.Length – 1

postFile = Request.Files(keys(ndx))

If postFile.ContentLength > 1 Then

contentType = postFile.ContentType

If Uploads.ValidateImageContentType(contentType) Then

Dim objPhoto As New PhotosFO

imgContent = Uploads.GetFileContent(postFile.InputStream)

ImgPath  = imgContent

contentType  = contentType

ImageName = System.IO.Path.GetFileName(postFile.FileName)

imageName  = ImageName

photoTitle  = ImageName.Split(“.”)(0)

Insert Into db code here

isupld = True

totolupld += 1

Else

lblErrMSG.Visible = True

lblErrMSG.Text = “Select a valid image.”

lblErrMSG.ForeColor = Drawing.Color.Red

isupld = True

Exit Sub

End If

End If

Next

If isupld = True Then

Response.Redirect(“galleryPhotos.aspx)

End If

Catch ex As Exception

Throw ex

End Try

End Sub

CREATE THIS CLASS FOR TO CREATE A METHOD OR FUNCTION OR YOU CREATE THIS FUNCTION IN SAME ABOVE CLASS

Public Class Uploads

Public Shared Function ValidateImageContentType(ByVal contentType As String) As Boolean
If (contentType = “image/jpg” Or contentType = “image/jpeg” Or contentType = “image/png” Or contentType = “image/gif”) Then
Return True
Else
Return False
End If
End Function

Public Shared Function GetFileContent(ByVal inpstrm As System.IO.Stream) As Byte()
Dim fs As Stream = inpstrm
Dim br As New BinaryReader(fs)
Dim bytes As Byte() = br.ReadBytes(fs.Length)
Return bytes
End Function

End Class

 
Leave a comment

Posted by on April 15, 2011 in Vb.Net

 

Char Codes (Key Codes)


Javascript Char Codes (Key Codes) Table

Key Pressed Javascript Key Code
backspace 8
tab 9
enter 13
shift 16
ctrl 17
alt 18
pause/break 19
caps lock 20
escape 27
page up 33
page down 34
end 35
home 36
left arrow 37
up arrow 38
right arrow 39
down arrow 40
insert 45
delete 46
0 48
1 49
2 50
3 51
4 52
5 53
6 54
7 55
8 56
9 57
a 65
b 66
c 67
d 68
e 69
f 70
g 71
h 72
i 73
j 74
k 75
l 76
m 77
n 78
o 79
p 80
q 81
r 82
s 83
t 84
u 85
v 86
w 87
x 88
y 89
z 90
left window key 91
right window key 92
select key 93
numpad 0 96
numpad 1 97
numpad 2 98
numpad 3 99
numpad 4 100
numpad 5 101
numpad 6 102
numpad 7 103
numpad 8 104
numpad 9 105
multiply 106
add 107
subtract 109
decimal point 110
divide 111
f1 112
f2 113
f3 114
f4 115
f5 116
f6 117
f7 118
f8 119
f9 120
f10 121
f11 122
f12 123
num lock 144
scroll lock 145
semi-colon 186
equal sign 187
comma 188
dash 189
period 190
forward slash 191
grave accent 192
open bracket 219
back slash 220
close braket 221
single quote 222
 
Leave a comment

Posted by on April 15, 2011 in Java Script

 

CAPTCHA Implementation in ASP.NET


I want to implement Captcha in my ASP.NET project

“Default.aspx

<label>Image verification text (case sensitive/text only):</label>

<asp:TextBox ID=”txtImageVerification” runat=”server” ></asp:TextBox>

<asp:Image ID=”imgVerification” runat=”server” ImageAlign=”absMiddle” />

<br />

<div style=”padding-left: 170px;”>

<asp:Button ID=”btnsubmit” ValidationGroup=”grpContactUs” runat=”server” Text=”Submit”  >

<asp:validationsummary Visible=”True” id=”valSummary” runat=”server” howSummary=”False” DisplayMode=”BulletList” ShowMessageBox=”True” HeaderText=”The following errors were found:” ValidationGroup=”grpContactUs” />

</div>

 

 

CodeBehind Side

 

“Default.aspx.vb

Imports siteCaptcha

Partial Class _Default

Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

If Not Page.IsPostBack Then

Dim rnd As New Random

Session(“ImageValidate”) = validateImage.GenerateVCodeImage(Server.MapPath(“images/imageverfication/ImgVerify.jpeg”))

imgVerification.ImageUrl = “~/images/imageverfication/ImgVerify.jpeg?id=” & rnd.Next(100).ToString

End If

End Sub

 

Protected Sub btnsubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnsubmit.Click

Try

If Not Session(“ImageValidate”) Is Nothing Then

If Session(“ImageValidate”).ToString <> txtImageVerification.Text Then

Dim rnd As New Random

Session(“ImageValidate”) = validateImage.GenerateVCodeImage(Server.MapPath(“images/imageverfication/ImgVerify.jpeg”))

imgVerification.ImageUrl = “~/images/imageverfication/ImgVerify.jpeg?id=” & rnd.Next(100).ToString

Me.PMsg.InnerHtml = “Image verification text did not match !”

Me.PMsg.Visible = True

Exit Sub

Else

Me.PMsg.InnerHtml = “SUCESSFULLY VERIFICATION OF IMAGE”

Me.PMsg.Visible = True

 

End If

 

Else

Dim rnd As New Random

Session(“ImageValidate”) = validateImage.GenerateVCodeImage(Server.MapPath(“images/imageverfication/ImgVerify.jpeg”))

imgVerification.ImageUrl = “~/images/imageverfication/ImgVerify.jpeg?id=” & rnd.Next(100).ToString

Me.PMsg.InnerHtml = “Image verification text did not match !”

Me.PMsg.Visible = True

Exit Sub

End If

Catch exs As System.Threading.ThreadAbortException

Response.Redirect(Request.UrlReferrer.ToString)

Catch ex As Exception

Throw ex

End Try

End Sub

End Class

 

Create images folder on root then subfolder is imageverfication. See below image

 

 


Create  validateImage.vb in App_Code

Imports System.Drawing.Drawing2D

Imports System.Drawing.Imaging

Imports System.Drawing.Text

Namespace siteCaptcha

Public Class validateImage

Private Shared Function generateVCode(ByVal CodeLength As Integer) As String

Dim VCode As String = String.Empty

Dim randObj As New Random()

Dim c As Integer = 63

For i As Byte = 1 To CodeLength

c = randObj.Next(35)

If c >= 10 Then

c += 7

End If

c += 48

VCode += Chr(c)

Next

Return VCode

End Function

Private Shared Function generateHatchStyle() As HatchStyle

Dim slist As New ArrayList

For Each style As HatchStyle In System.Enum.GetValues(GetType(HatchStyle))

slist.Add(style)

Next

Dim randObj As New Random()

Dim index As Integer = randObj.Next(slist.Count – 1)

Return CType(slist(index), HatchStyle)

End Function

Public Shared Function GenerateVCodeImage(ByVal path As String) As String

Dim oBitmap As Drawing.Bitmap = New Drawing.Bitmap(130, 35)

Dim oGraphic As Drawing.Graphics = Drawing.Graphics.FromImage(oBitmap)

Dim foreColor As System.Drawing.Color

Dim backColor As System.Drawing.Color

Dim sText As String = generateVCode(6)

Dim sFont As String = “Comic Sans MS”

foreColor = System.Drawing.Color.FromArgb(220, 220, 220)

backColor = System.Drawing.Color.FromArgb(190, 190, 190)

Dim oBrush As New Drawing.Drawing2D.HatchBrush(CType(generateHatchStyle(), Drawing.Drawing2D.HatchStyle), foreColor, backColor)

Dim oBrushWrite As New Drawing.SolidBrush(Drawing.Color.Red)

oGraphic.FillRectangle(oBrush, 0, 0, 140, 50)

oGraphic.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias

Dim oFont As New Drawing.Font(sFont, 14)

Dim oPoint As New Drawing.PointF(5.0F, 4.0F)

sText = sText.ToUpper

Dim tmpStr As String = sText

Dim chr As Char() = sText.ToCharArray

sText = “”

For chrCount As Integer = 0 To chr.Length – 1

sText &= chr(chrCount) & ” ”

Next

oGraphic.DrawString(sText, oFont, oBrushWrite, oPoint)

oBitmap.Save(path, ImageFormat.Jpeg)

oBitmap.Dispose()

‘sText = sText.ToLower

Return tmpStr

End Function

 

End Class

 

End Namespace

 

 

 
2 Comments

Posted by on April 7, 2011 in ASP Dot Net C#

 

Gridview Sorting with VB Net with image


Gridview Sorting  with VB.Net

<asp:GridView ID=”grd” runat=”server” Width=”100%” BorderWidth=”0″ BackColor=”#ffffff”

CellPadding=”0″ CellSpacing=”0″ GridLines=”None” ShowFooter=”true” AutoGenerateColumns=”False”

PageSize=”50″ AllowPaging=”true” AllowSorting=”true”>

<PagerSettings Visible=”False” />

<Columns>

<asp:TemplateField>

<HeaderTemplate>

<table border=”0″ cellpadding=”0″ cellspacing=”0″ width=”940px”>

<tr>

<td>

<asp:LinkButton OnClick=”Page_Click” ID=”lnkPageSort” runat=”server”>Article Title</asp:LinkButton>&nbsp;

<asp:Image ID=”imgTitle” runat=”server” ImageAlign=”AbsMiddle” ImageUrl=”images/icons/sortIcon_asc.gif” />

</td>

<td>

<asp:LinkButton OnClick=”Author_Click” ID=”lnkAuthor” runat=”server”>Author</asp:LinkButton>&nbsp;

<asp:Image ID=”imgAuthor” runat=”server” ImageAlign=”AbsMiddle” ImageUrl=”images/icons/sortIcon_asc.gif” />

</td>

<td>

<asp:LinkButton OnClick=”Published_Click” ID=”lnkPublished” runat=”server”>Published</asp:LinkButton>&nbsp;

<asp:Image ID=”imgPublished” runat=”server” ImageAlign=”AbsMiddle” ImageUrl=”images/icons/sortIcon_asc.gif” />

</td>

<td>

<asp:LinkButton OnClick=”Approved_Click” ID=”lnkApproved” runat=”server”>Approved</asp:LinkButton>&nbsp;

<asp:Image ID=”imgApproved” runat=”server” ImageAlign=”AbsMiddle” ImageUrl=”images/icons/sortIcon_asc.gif” />

</td>

<td align=”center”>

<asp:LinkButton OnClick=”DateCreated_Click” ID=”lnkDateCread” runat=”server”>Created</asp:LinkButton>&nbsp;

<asp:Image ID=”imgDateCreated” runat=”server” ImageAlign=”AbsMiddle” ImageUrl=”images/icons/sortIcon_asc.gif” />

</td>

<td align=”center”>

<asp:LinkButton OnClick=”dateModified_Click” ID=”lnkdateModified” runat=”server”>Modified</asp:LinkButton>&nbsp;

<asp:Image ID=”imgdateModified” runat=”server” ImageAlign=”AbsMiddle” ImageUrl=”images/icons/sortIcon_asc.gif” />

</td>

<td>

Actions

</td>

</tr>

</HeaderTemplate>

<ItemTemplate>

<tr>

<td>

<img src=”images/page1.gif” alt=”Edit Page” style=”vertical-align: text-bottom” />&nbsp;<a

href=”newsdetail.aspx?id=<%#Eval(“articleID”)%>”><%#Eval(“articleTitle”)%></a>

</td>

<td>

<%#Eval(“FullName”)%>

</td>

<td>

<%#Eval(“IsPublished”)%>

</td>

<td>

<%#Eval(“IsApproved”)%>

</td>

<td>

<%# DateTimeFormat.formateDate(DataBinder.Eval(Container.DataItem, “dateCreated”))%>

</td>

<td>

<%# DateTimeFormat.formateDate(DataBinder.Eval(Container.DataItem, “dateModified”))%>

</td>

<td>

<a href=”newsdetail.aspx?id=<%#Eval(“articleID”)%>”><strong>Edit</strong></a>&nbsp;&nbsp;|&nbsp;&nbsp;<asp:LinkButton

ID=”lnkDelete” OnClientClick=”return confirm(‘Are you sure you want to delete the record?’);”

runat=”server” CommandName=”cmdDelete” CommandArgument='<%#Eval(“articleID”)%>’><strong>Delete</strong></asp:LinkButton>

</td>

</tr>

</ItemTemplate>

<FooterTemplate>

<tr>

<td colspan=”7″>

&nbsp;

</td>

</tr>

</FooterTemplate>

</asp:TemplateField>

</Columns>

</asp:GridView>

For Gridview Column set Custom Date Formate

First Create class with DateTimeFormat.vb

In App_Code folder

Public Class DateTimeFormat

Public Shared Function formateDate(ByVal obj As Object) As String

Dim dtFormat As String = “”

Try

If Not obj Is Nothing Then

dtFormat = CType(obj, DateTime).ToString(“MM/dd/yy”) & “&nbsp;” & CType(obj, DateTime).ToString(“h:mm tt”)

End If

Catch ex As Exception

End Try

Return dtFormat

End Function

End Class

Code Behind Side

‘//Global Variables

Public Shared sortOrder() As String = {“ASC”}

Public Shared sortLast() As String = {“ASC”, “Title”}

Dim bolRights As Boolean = False

Public strCMSVersion As String = String.Empty

Public strControlPage As String = String.Empty

Public strSiteURL As String = String.Empty

At Page Load Event

If Not Page.IsPostBack Then

bindData()

End If

1.Function Load Data

Private Sub bindData()

Try

DataInfo = ArticlesBAL.GetArticleAll(Convert.ToInt32(Session(“siteID”)))

bindDataPaging(0)

If DataInfo.Rows.Count < 1 Then

Me.lblNoPage.Text = “There are currently no News to display. You may create a new News now by clicking the “”Add New News”” link above.”

Me.lblNoPage.visible = True

End If

Catch ex As Exception

Throw ex

End Try

End Sub

2.Function DataPage

Private Sub bindDataPaging(ByVal pageIndex As Integer)

Try

If DataInfo.Rows.Count > 0 Then

pnlFooter.Visible = False

Else

pnlFooter.Visible = True

End If

processPages(pageIndex)

Catch ex As Exception

Throw ex

End Try

End Sub

3.ProcessPages

Private Sub processPages(ByVal pageIndex As Integer)

Try

If DataInfo.Rows.Count > grd.PageSize Then

grd.DataSource = DataInfo

grd.DataBind()

Dim pageCount As Integer = 0

pageCount = grd.PageCount

If (pageIndex < 0) Then

grd.PageIndex = 0

ElseIf (pageIndex > pageCount – 1) Then

grd.PageIndex = pageCount – 1

Else

If (pageIndex = 0) Then

btnPrev.Visible = False

imgbtnPrev.Visible = False

btnNext.Visible = True

imgbtnNext.Visible = True

ElseIf (pageIndex = pageCount – 1) Then

btnPrev.Visible = True

imgbtnPrev.Visible = True

btnNext.Visible = False

imgbtnNext.Visible = False

Else

btnPrev.Visible = True

imgbtnPrev.Visible = True

btnNext.Visible = True

imgbtnNext.Visible = True

End If

grd.PageIndex = pageIndex

End If

pnlPaging.Visible = True

lblPageCount.Text = “| ” & (grd.PageIndex + 1).ToString() & ” |” & ” of ” & pageCount.ToString()

End If

grd.DataSource = DataInfo

grd.DataBind()

Catch ex As Exception

Throw ex

End Try

End Sub

4.grid Events

Protected Sub grd_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles grd.PageIndexChanging

End Sub

5.For Delete Link Button

Protected Sub grd_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles grd.RowCommand

If e.CommandName = “cmdDelete” Then

Dim DocumentID As Integer = e.CommandArgument

ArticlesBAL.DeleteArticle(DocumentID)

Dim pageIndex As Integer = grd.PageIndex

bindData()

bindDataPaging(pageIndex)

End If

End Sub

6.Grid RowCommand Event for Header Image change

Protected Sub grd_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grd.RowDataBound

If sortInfo <> “” Then

If (e.Row.RowType = DataControlRowType.Header) Then

Dim imgSort As Image = e.Row.FindControl(sortInfo)

If sortLast(0) = “DESC” Then

imgSort.ImageUrl = “images/icons/sortIcon_asc.gif”

ElseIf sortLast(0) = “ASC” Then

imgSort.ImageUrl = “images/icons/sortIcon_desc.gif”

End If

Dim lnkbtn As LinkButton = e.Row.FindControl(“lnkApproved”)

lnkbtn.Text = Resources.Resource.lblGridActive

Dim lnksite As LinkButton = e.Row.FindControl(“lnkPublished”)

lnksite.Text = Resources.Resource.lblGridPublish

End If

Else

If (e.Row.RowType = DataControlRowType.Header) Then

Dim lnkbtn As LinkButton = e.Row.FindControl(“lnkApproved”)

lnkbtn.Text = Resources.Resource.lblGridActive

Dim lnksite As LinkButton = e.Row.FindControl(“lnkPublished”)

lnksite.Text = Resources.Resource.lblGridPublish

End If

End If

End Sub

7.Grid Sorting Event

Protected Sub grd_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles grd.Sorting

End Sub

8.Grid Header link sorting

Protected Sub Page_Click(ByVal sender As Object, ByVal e As System.EventArgs)

Dim lnkHeader As LinkButton = CType(sender, LinkButton)

sorting(0, “articleTitle”, “imgTitle”)

End Sub

Protected Sub Author_Click(ByVal sender As Object, ByVal e As System.EventArgs)

sorting(0, “FullName”, “imgAuthor”)

End Sub

Protected Sub Published_Click(ByVal sender As Object, ByVal e As System.EventArgs)

sorting(0, “IsPublished”, “imgPublished”)

End Sub

Protected Sub Approved_Click(ByVal sender As Object, ByVal e As System.EventArgs)

sorting(0, “IsApproved”, “imgApproved”)

End Sub

Protected Sub DateCreated_Click(ByVal sender As Object, ByVal e As System.EventArgs)

sorting(0, “dateCreated”, “imgDateCreated”)

End Sub

Protected Sub dateModified_Click(ByVal sender As Object, ByVal e As System.EventArgs)

sorting(0, “dateModified”, “imgdateModified”)

End Sub

8.Sorting Function

Public Sub sorting(ByVal order As Integer, ByVal sortName As String, ByVal imgTitle As String)

Try

Dim dt As Data.DataTable = DataInfo

Dim dtV As New DataView

sortLast(0) = sortOrder(order)

sortLast(1) = sortName

sortInfo = imgTitle

If sortOrder(order) = “DESC” Then

dtV = dt.DefaultView

dtV.Sort = sortName & ” ” & sortOrder(order)

sortOrder(order) = “ASC”

ElseIf sortOrder(order) = “ASC” Then

dtV = dt.DefaultView

dtV.Sort = sortName & ” ” & sortOrder(order)

sortOrder(order) = “DESC”

End If

bindDataPaging(grd.PageIndex)

Catch ex As Exception

Throw ex

End Try

End Sub

9.Next Page Grid

Protected Sub btnNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNext.Click

bindDataPaging(grd.PageIndex + 1)

End Sub

10.Previou Page Grid

Protected Sub btnPrev_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrev.Click

bindDataPaging(grd.PageIndex – 1)

End Sub

11.Go To Specific Page Grid

Protected Sub btnGoToPage_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnGoToPage.Click

bindDataPaging(Convert.ToInt32(Trim(txtGoToPage.Text) – 1))

End Sub

 
Leave a comment

Posted by on April 6, 2011 in Gridview, Vb.Net

 

Tags: ,

First Letter of string is Capital in Vb.net and C#


if you want to show your string on web in proper case like every first character is captital then you can use this code

Vb.Net

Dim strchar As String=’sajjad ahmed’

Dim strCaptical As String = StrConv(strchar, VbStrConv.ProperCase)

Result :

Sajjad Ahmed

C-Sharp(C#)

string strchar=”sajjad ahmed”

Strings.StrConv(strchar, VbStrConv.ProperCase)
 
2 Comments

Posted by on April 6, 2011 in ASP Dot Net C#, Gridview