Thursday, September 2, 2010

Clearing textbox values after submitting

private void GetAllCtlClr(ControlCollection ctls)
{
foreach (Control c in ctls)
{
if (c is System.Web.UI.WebControls.TextBox)
{
TextBox tt = c as TextBox;
tt.Text = "";

}
if (c.HasControls())
{
GetAllCtlClr(c.Controls);
}
}

}

call this method in Page_Load event

(OR)
Write the following in the submit button click event:

Response.Write("");

Monday, December 8, 2008

Get the file name form the directroy

using System;
using System.IO;

public class GetFilesTest {
public static void Main() {

// make a reference to a directory
DirectoryInfo di = new DirectoryInfo("c:\\");

// get a reference to each file in that directory
FileInfo[] fiArr = di.GetFiles();

// print out the names of the files
foreach (FileInfo fri in fiArr)
Console.WriteLine(fri.Name);
}
}

Editable Nested GridView

Hey Guys,

check it out Nested grid.

http://www.codeproject.com/KB/aspnet/EditNestedGridView.aspx

best regards,
JAGAN

Wednesday, November 5, 2008

Custom Validator for Image Upload in ASP.NET



EnableClientScript="false" OnServerValidate="CustomValidator1_ServerValidate"
ErrorMessage="too large" ControlToValidate="FileUpload1" Display="Dynamic" />



Code Behind Page:
Protected Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As ServerValidateEventArgs)

Dim filesize As Int64
filesize = FileUpload1.PostedFile.ContentLength

If (filesize > 5 * 1024) Then
args.IsValid = False
Label1.Text = "failed"
Return
Else
Label1.Text = "small size"
End If
End Sub

Including page in front of grid view page numbers

here is the code for including 'page' text infront of the grid view page numbers

protected void GridView1_PreRender(object sender, EventArgs e)
{
GridView grid = (sender as GridView);

if (grid != null)
{
GridViewRow pagerRow = grid.BottomPagerRow;

if (pagerRow != null && pagerRow.Visible)
{
Table pagerTable = (pagerRow.Cells[0].Controls[0] as Table);

pagerTable.CssClass = "PagerTable";

Label pageText = new Label();

pageText.Text = "page ";
pageText.CssClass = "PagerLabel";
pagerRow.Cells[0].Controls.AddAt(0, pageText);
}
}
}

And Css style is:
.PagerLabel
{
float: left;
font-weight: normal;
padding-left: 5px;
padding-top: 3px;
}

.PagerTable
{
float: left;
}


best regards,
Jagan Patnam

Custom paging in a Asp.net Gridview

Hello folks, check out this cool feature of ASP.NET Custom paging in a Gridview


http://bdotnet.in/blogs/tekexplore/archive/2008/04/08/custom-paging-in-gridview-control.aspx

Best regards,
Jagan Patnam

Connetion strings in ASP.NET

Ms-Access :
Provider=Microsoft.Jet.OLEDB.4.0DataSource=C:\mydatabase.mdb;UserId=admin;Password=;

Sql server :
Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;

My Sql :
Provider=MySQLProv;Data Source=mydb;User Id=myUsername;Password=myPassword;

Oracle :
Provider=msdaora;DataSource=MyOracleDB;UserId=myUsername;Password=myPassword;