<script type="text/javascript"> function checkOSVersion() { if (navigator.userAgent.indexOf("WOW64") != -1 || navigator.userAgent.indexOf("Win64") != -1) { alert("This is a 64 bit OS"); } else { alert("Not a 64 bit OS"); } } </script>
Monday, August 18, 2014
Retrieve OS version with Javascript
Sunday, February 23, 2014
Using FileUpload with JQuery Mobile
In order to allow your FileUpload control work, you'll need to set data-ajax="false" where ever your form tag is located.
<form data-ajax="false" id="form1" runat="server"> </form>
Monday, February 17, 2014
Visual Studio 2012 Extensions
CodeMaid
http://visualstudiogallery.msdn.microsoft.com/76293c4d-8c16-4f4a-aee6-21f83a571496
PostSharp
http://visualstudiogallery.msdn.microsoft.com/a058d5d3-e654-43f8-a308-c3bdfdd0be4a
GhostDoc
http://visualstudiogallery.msdn.microsoft.com/46A20578-F0D5-4B1E-B55D-F001A6345748
Language Convert
http://visualstudiogallery.msdn.microsoft.com/cc8da841-f978-4c3e-8397-c820bd57298c
Image Optimizer
http://visualstudiogallery.msdn.microsoft.com/a56eddd3-d79b-48ac-8c8f-2db06ade77c3
Saturday, February 1, 2014
Binding returned data from an Ajax call to a Gridview
You'll need the JQuery reference in the head section.
<script src ="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js" type ="text/javascript">
For this first function you'll need to change the url in the ajax call to either the page your creating the Ajax call or the page your getting the post from which can also be a web service or handler. Then don't forget to set the method name after the page or web service your calling.
function Button1_onclick() { $.ajax({ type: "POST", data: '{}', contentType: "application/json; charset=utf-8", url: "AjaxTest.aspx/GetTransactionData", dataType: "xml", success: OnSuccess, error: function (XMLHttpRequest, textStatus, errorThrown) { $("#errmsg").ajaxError(function (event, request, settings) { $(this).append("<li>Error requesting page " + settings.url + "</li>"); }); } }); return false; }
The next function will loop through the returned xml and append a table row for each row found in the xml to the Gridview.
function OnSuccess(xml) { debugger; try { $(xml).find('Table1').each(function () { var id_text = $(this).find('ID').text(); var name_text = $(this).find('Description').text(); $('#<%=GridView1.ClientID %>').append("<tr><td>" + id_text + "</td><td>" + id_text + "</td</tr>"); }); } catch (err) { var txt = "There was an error on this page.\n\n"; txt += "Error description: " + err.description + "\n\n"; txt += "Click OK to continue.\n\n"; alert(txt); } }
Below is the form example used to initiate the ajax call.
<input id="Button1" type="button" value="Get XML" onclick="return Button1_onclick()" /> <asp:GridView ID="GridView1" runat="server"></asp:GridView>
Finally, this is where you'll fill the data that gets returned to the client side. You'll need to add a WebMethod to your ".CS" page then create your data table and fill it from either a direct database call or web service to return the xml. In the example below, I'm creating my initial data table columns in the Page_Load so that when the Ajax call returns, it knows what columns are mapped to the Gridview.
using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web; using System.Web.Script.Services; using System.Web.Services; using System.Web.UI; using System.Web.UI.WebControls;
protected void Page_Load(object sender, EventArgs e) { DataTable table = new DataTable(); table.Columns.Add("ID"); table.Columns.Add("Description"); table.Rows.Add(); GridView1.DataSource = table; GridView1.DataBind(); } [WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Xml)] public static string GetTransactionData() { DataTable dt = new DataTable(); dt.Columns.Add("ID"); dt.Columns.Add("Description"); dt.Rows.Add("1", "Description 1"); dt.Rows.Add("2", "Description 2"); dt.Rows.Add("3", "Description 3"); dt.Rows.Add("4", "Description 4"); dt.Rows.Add("5", "Description 5"); DataSet m_dsDataSet = new DataSet("pageDataSet"); m_dsDataSet.Tables.Add(dt); string strXml = m_dsDataSet.GetXml(); return strXml; }
Monday, January 27, 2014
Binding Nested Detailsview in Gridview
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { GridViewRow row = e.Row; // Make sure we aren't in header/footer rows if (row.DataItem == null) { return; } DetailsView dv = (DetailsView)row.FindControl("DetailsView1"); List<[object]> aList = List<[object]>(); if (e.Row.RowType == DataControlRowType.DataRow) { aList[e.Row.RowIndex].Name = aList[e.Row.RowIndex].Name; dv.DataSource = aList.Where(u => u.ID == Convert.ToInt32(aList[e.Row.RowIndex].Address)).ToList(); dv.DataBind(); } }