Archive / ASP.Net

RSS feed for this section

GridView.RowDataBound Event No Data

I was trying to use the GridView.RowDataBound event to change the background color of the row in a GridView. But the data was missing. Here is what I trying: void gvReport_RowDataBound(Object sender, GridViewRowEventArgs e){   if (e.Row.RowType == DataControlRowType.DataRow)   {      if (e.Row.Cells[1].Text.IndexOf(“Total:”) > 0)         e.Row.BackColor = System.Drawing.Color.FromArgb(247, 249, 223);   }} But my e.Row.Cells[1].Text had no data in it. I am binding […]


Hello,  I recently had a need to display a CAPTCHA on an ASP.Net contact form. After a short search on the internet, I found this article on the The Code Project: This Captcha control by Jeff Atwood was easy to plug in and works very well for my needs. I just wanted to let […]

Code to create a DataSet

Use this code to create a table and place it in a DataSet. // Create a new DataTable.System.Data.DataTable table = new DataTable(“Details”);// Declare variables for DataColumn and DataRow objects.DataColumn column;DataRow row;// Create new DataColumn, set DataType, // ColumnName and add to DataTable. column = new DataColumn();column.DataType = System.Type.GetType(“System.Int32”);column.ColumnName = “fk_agent_id”;column.ReadOnly = false;column.Unique = true;// Add the Column to […]

Code to create a DataRow and add it to a DataSet

Use this code to create a DataRow from a table in a DataSet and place it in the table in a DataSet. // Call a method to create the DataSet with a table in it.DataSet resultData = MakeDetailTable();DataRow row = resultData.Tables[“Details”].NewRow();row[“fk_agent_id”] = userInfo.account_id;row[“agent_name”] = userInfo.lname + “, “ + userInfo.fname;resultData.Tables[“Details”].Rows.Add(row);// Use the data in the GridView.gvReport.DataSource = […]

ASP.Net AJAX Animations

Some of the best resources for the animation framework that comes with the ASP.Net AJAX Control Toolkit can be found at the live toolkit site at this Sample Site. I often look at the Animation Reference section of this site. While adding animations to ASP.Net pages, it is sometimes necessary to call animations directly from Javascript […]

Server.ScriptTimeout Not Working

I had a file upload page that gave an HttpException with message “Request timed out”. Natrually, I set the Server.ScriptTimeout to 360. But I still got the error rmessage. To solve this I added the following to the web.config file: <httpRuntimeexecutionTimeout=“360“maxRequestLength=“41000“ /> The maxRequestLength did not solve the problem by itself. The executionTimeout was needed as well.  

Setting Page Meta Information at Runtime

I have a MasterPage and some child pages. The content for the child pages comes from a database. I have a form in the Admin section of my site for editing pages. You can set the Page Title, the Meta Description, Keywords, and page Content. Accessing the title is easy, because the title of the content pages […]

Convert VB.Net to C#

Great VB.Net to C# converter tool:  

“Save As” Dialog Box for Streaming File

To download files using a “Save As” dialog box try this code:         Select Case FileExt            Case “gif” ContentType = “image/gif”            Case “tif” ContentType = “image/tiff”            Case “jpg” ContentType = “image/jpeg”            Case “pdf” ContentType = “application/pdf”            Case “avi” ContentType = “video/x-msvideo”            Case “mp3” ContentType = “audio/mpeg”            Case “mpg” ContentType = “video/mpeg”            Case “wav” ContentType = “audio/wav”            Case “rar” ContentType = “application/x-rar-compressed”            Case “zip” ContentType = “application/x-zip-compressed”            Case […]

SelectedValue which is invalid because it does not exist in the list of items

To populate drop down lists I bind the list to a lookup table in the database (i.e. States). Occasional the parent table (i.e. Customers) has a value that is “not on the list” and this error is genreated:    ‘ddlState’ has a SelectedValue which is invalid because it does not exist in the list of items. […]