September 2008 Entries

AJAX Enabled WebParts and FireFox Drag and Drop

WebParts Cross- browser drag and drop is a very common issues on ASPNET WebPart Framework.. Basically WebParts doesn't support the Drag and Drop feature in Firefox browsers and this known to be a BUG for ASPNET Webpart Framework.. To get things working in all browsers including the cross browser drag-and-drop feature then you would need to use Visual studio 2008 / VWD 2008 with latest version of the Microsoft ASPNET Futures (AJAX Control Toolkit 3.5).. For more detail information then i would suggest...

Set Background Color for each ListItems of the DropDownList

The following snippet below describes on how we are going to set the ListItem Background Color based on the Color name displayed in the DropDownList ASPX MARKUP OF DROPDOWNLIST <asp:DropDownList ID="DropDownList1" AppendDataBoundItems="true" runat="server" AutoPostBack="True" OnSelectedIndexChanged="Dro... OnLoad="DropDownList1_Load"... <asp:ListItem Value="-1">Select</as... <asp:ListItem Value="0">Red</asp:Li... <asp:ListItem...

Formatting String number values to money in ASPNET

The following are ways on how to format string number values into a money format with decimals. Option 1: - Using String.Format method C# double formatToMoney; string num = "1500"; if (double.TryParse(num, out formatToMoney)) { string newNum = String.Format("{0:c}", formatToMoney); Response.Write(newNum); } VB.NET Dim formatToMoney As Double Dim num As String = "1500" If Double.TryParse(num, formatToMoney) Then Dim newNum As String = String.Format("{0:c}", formatToMoney) Response.Write(newNum) End...

Limiting the Data being displayed in the GridView and Display Tooltip

The following snippet below describes on how we are going to limit the Text displayed in the boundfield column of the GridView and display the original data in the ToolTip when user hovers the mouse for a particular cell. C# protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { ViewState["OrigData"] = e.Row.Cells[0].Text; if (e.Row.Cells[0].Text.Length >= 30) //Just change the value of 30 based on your requirements { e.Row.Cells[0].Text...

Passing Multiple Querystring values with Response.Redirect method

Here's an example on how to pass Multiple querystrings in the page.. Page1 protected void Button1_Click(object sender, EventArgs e) { string strName = "VINZ"; string strAddress = "CEBU"; string strDate = DateTime.Now.ToShortDateStr... Response.Redirect(string.Fo... } The on Page2 you can get each values this way below protected void Page_Load(object sender, EventArgs e) { if ((Request.QueryString["para...

Custom Login: Validating UserName and Password using the ADO.NET way

The snippet below describes on how we are going to validate the user credentials being supplied by the end user in Login page using the ADO.NET way.. C# protected void ValidateUserInfo(string user, string pass) { SqlConnection connection = new SqlConnection("YOUR CONNECTION STRING HERE"); string sql = "SELECT * FROM TableName WHERE UserID = @username AND Password = @password"; SqlCommand cmd = new SqlCommand(sql,connection); cmd.Parameters.AddWithValue... user); cmd.Parameters.AddWithValue...

Bind TextBox and Label Control with Data from database

This sample snippet below describes on how we are going to Populate a TextBox and Label control in the page based on the data associated per user using the ADO.NET way.. C# private void getData(string user) { DataTable dt = new DataTable(); SqlConnection connection = new SqlConnection("YOUR CONNECTION STRING HERE"); connection.Open(); SqlCommand sqlCmd = new SqlCommand("SELECT * from TABLE1 WHERE UserID = @username", connection); SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd); sqlCmd.Parameters.AddWithVa...

Manually Binding DropDownList based on the value selected on the first DropDownList

I decided to write this sample demo because I always encounter this kind of problem in the ASPNET Forum . So here's a sample (one way) solution on how to populate the second DropDownList based on the value selected on the first DropDownList using the ADO.NET way. Assuming that DropDownList1 contains the list of countries and we need to populate the list of States in a particular country based on the first DropDownList selection. protected void PopulateDropDownList1(){ string queryString = "SELECT...

WEBPART: Count the number of Closed WebParts within PageCatalogPart

The following snippets below checks whether the PageCatalogPart Control contains any available WebParts in a page that have been closed in the page.. C# protected void PageCatalogPart1_Load(object sender, EventArgs e) { int count = 0; if (WebPartManager1.WebParts.C... > 0) { for (int i = 0; i < WebPartManager1.WebParts.Co... i++) { WebPart wp = (WebPart)WebPartManager1.We... if (wp.IsClosed) { Response.Write("Page Catalog contains Closed WebParts"); count++; } } Response.Write("<br/>...

Get the days difference between two Dates

Here's an example on how to get the date difference between two given dates using TimeSpan.C#protected void Page_Load(object sender, EventArgs e){ DateTime dFrom; DateTime dTo; string sDateFrom = "9/9/2007"; string sDateTo = "1/10/2008"; if (DateTime.TryParse(sDateFrom, out dFrom) && DateTime.TryParse(sDateTo, out dTo)) { TimeSpan TS = dTo - dFrom; int daysDiff = TS.Days; Response.Write(daysDiff.ToS... } }VB.NETProtected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Dim...

Display Original Image Size in new window when clicking on the Image

The following snippet below will display the original Image size in new window when clicking on the image thumbnail using JavaScript.. JAVASCRIPT FUNCTION <script type="text/javascript" language="javascript"> function DisplayNewImageInWidnow() { var img = document.getElementById('&l... Image1.ClientID %>').src; html = "<HTML><HEAD>&l... + "</HEAD><BODY LEFTMARGIN=0 " + "MARGINWIDTH=0 TOPMARGIN=0 MARGINHEIGHT=0><CENTE... + "<IMG...

Forcing Button Click event to fire up when pressing ENTER Key on TextBox

I decided to write this article because I always encounter this kind of problem in the ASPNET Forum frequently. So here's a simple (one way) solution on how to invoke the Button Click event when pressing the ENTER key in the TextBox control. ASPX Mark Up and JavaScript function <head> <title>Untitled Page</title> </style> <script type="text/javascript" language="javascript"> function controlEnter (obj, event) { var keyCode = event.keyCode ? event.keyCode : event.which...