Tuesday, 15 April 2014

Reading repetitive XML to memory using C#

Sample XML Document:
<Elements>
    <Element>
        <Name>N1</Name>
        <Type>T1</Type>
        <Color>C1</Color>
    </Element>
    <Element>
        <Name>N2</Name>
        <Type>T2</Type>
        <Color>C2</Color>
    </Element>
    <Element>
        <Name>N3</Name>
        <Type>T3</Type>
        <Color>C3</Color>
    </Element>
</Elements>


Sample C# Code:
XmlDocument myDoc = new XmlDocument()
myDoc.Load(XML_File_Path_Name);

foreach(XmlElement elem in myDoc.SelectNodes("Elements/Element"))
{
    XmlNode nodeName = elem.SelectSingleNode("Name/text()");
    XmlNode nodeType = elem.SelectSingleNode("Type/text()");
    XmlNode nodeColor = elem.SelectSingleNode("Color/text()");

    string name = nodeName!=null ? nodeName.Value : String.Empty;
    string type = nodeType!=null ? nodeType.Value : String.Empty;
    string color = nodeColor!=null ? nodeColor.Value : String.Empty;



Tuesday, 8 April 2014

Enable remote MySQL connection


Put this as root:

GRANT ALL PRIVILEGES ON *.* TO  'USERNAME'@'IP'  IDENTIFIED  BY  'PASSWORD';

where IP is the IP you want to allow acess and USERNAME is the user you use to connect
If you want to allow access from any IP just put % instead of your IP

and then you only have to put

FLUSH PRIVILEGES

or restart mysql server and that's it

Tuesday, 8 October 2013

Changing the SiteMaster StyleSheet from Codebehind

- In the SiteMaster Page, add ID to StyleSheet tag:
     <link id="layoutStyleSheet" href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
- In a login page, set a SESSION to a value. e.g. SESSION["user"] = "test"
- In the SiteMaster Page_Load method:
     protected void Page_Load(object sender, EventArgs e)
     {
         if (Session["user"] != null)
         {
             if (Session["user"].ToString() == "test")
             {
                 HtmlLink link = Page.Master.FindControl("layoutStyleSheet") as HtmlLink;
                 link.Href = "~/Styles/Aqualinc.css";
             }
             .
             .
             .       
         }
     }

Wednesday, 25 September 2013

Trace HTML textbox changes on the fly using JQuery

$(document).ready(function () {
    var searchValue = "";
    setInterval(checkTextboxChanged, 0.5);

    function checkTextboxChanged() {
        var currentValue = $('#TextBoxId').val();
        if (currentValue != searchValue) {
            searchValue = currentValue;
            TextboxChanged();
        }
    }

    function TextboxChanged() {
        // do your magic here
    }
});
 

Tuesday, 17 September 2013

Telerik RadGrid: Access the new values in Update Command

GridEditableItem editItem = e.Item as GridEditableItem;
Hashtable newValues = new Hashtable(); e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editItem);
string inf = newValues["username"].ToString();
.
.
.

After getting all the updated values, they can be passed to SQL update command.

Access input textbox value from the ASP.Net code behind

If you add attribute "runat" & "id" to your input then you can access it in your code behind without using Ajax:

<input type="text" id="myInput" runat="server" />

Tuesday, 10 September 2013

C# Partial-Page Update Sample Ajax Application

  • In the AJAX Extensions tab of the toolbox, double-click the ScriptManager control to add it to the page.
  • Drag an UpdatePanel control from the toolbox and drop it underneath the ScriptManager control.
  • Add those controls that you need to be partially updated.
More

Analysis Service in Power BI Report Server

 We couldn’t connect to the Analysis Services server. Make sure you’ve entered the connection string correctly... link