Monday, November 14, 2011

ASP.NET Menu Control and Z-INDEX

If you were using the ASP.NET menu control in vs2008, it would (at least for me) always render itself in front of any object. Once I updated to vs2010 and created an ASP.NET menu control, it kept "hiding" itself behind such objects as an embedded pdf. If you look at the source code that vs2008/vs2010 generates it is very different. Vs2008 (.net framework 2.0/3.5) creates tables when rendering a menu control on the client side. Vs2010 (.net framework 4.0) generates DIV/LI/UL statements by default on the client end. If you have tried raising the z-index to a very high level for the menu control in vs2010 and find that it is still rendered behind other objects, the following suggestion might work for you. When you define an ASP.NET menu control add the RenderingMode property and set it to Table:


<asp:Menu ID="mnuMain" runat="server" RenderingMode="Table"...


This will force the menu control to be rendered at the client side using tables and should render the menu control in front of any other control just like in vs2008! Hope this works for you as it worked for me.

Adiel

Wednesday, September 7, 2011

Convert Tab Delimited File to XmlDocument in C#

To convert a tab delimited file to an XmlDocument here is a simple function:


using System.Data;
using System.IO;
using System.Text;
using System.Xml;

...
private XmlDocument getFileData()
{

string path = base.Server.MapPath("tab_data.txt");

DataSet ds = new DataSet();
DataTable dt = ds.Tables.Add("MyData");

using (StreamReader sr = new StreamReader(path))
{
int columncount = 0;
string headerRow = sr.ReadLine();
string[] headers = headerRow.Split('\t');
foreach (string h in headers)
{
DataColumn dc = new DataColumn(h.Trim());
dt.Columns.Add(dc);
}
while (sr.Peek() != -1)
{
columncount = 0;
string data = sr.ReadLine();
string[] cells = data.Split('\t');
DataRow row = dt.NewRow();
foreach (string c in cells)
{
row[columncount] = c.Trim();
columncount++;
}
dt.Rows.Add(row);
}
}

// Call Helper function to convert Datatable to XmlDocument
return DataTableToXML(dt);


}

public XmlDocument DataTableToXML(DataTable table)
{

XmlDocument _XMLDoc = new XmlDocument();

_XMLDoc.LoadXml(table.DataSet.GetXml());

return _XMLDoc;

}

Thursday, June 16, 2011

CalendarExtender - Ajax Control Toolkit for ASP.NET

CalendarExtender

If you have ever used the CalendarExtender, you might have received a "Specified cast is not valid" error if populating it with null dates from the database using the SelectedDate property.

-Handling dbnull.

The following SelectedDate property correctly handles dbnulls in the data:

<cc1:CalendarExtender ID="calActivityDate" runat="server"


TargetControlID="txtActivityDate"


SelectedDate='<%# Convert.IsDBNull(Eval("activityDate")) ? null : Eval("activityDate") %>'


PopupButtonID="imgActivityDate" />