Monthly Archives: March 2015

Add Default Item to DropDownList Dynamically

How to add a default item as ‘N/A’ to drop down list and set selected?

gnList.DataSourceID = "GNDS";
gnList.DataTextField = "Name";
gnList.DataValueField = "Id";
gnList.Items.Insert(0, new ListItem("N/A", "0"));

Another way

gnList.Items.Add(new ListItem("N/A", "0"));
gnList.DataSourceID = "GNDS";
gnList.DataTextField = "Name";
gnList.DataValueField = "Id";
gnList.Items.FindByValue("0").Selected = true;
Leave a comment

Posted by on March 21, 2015 in ASP.Net



Static DropDownList in GridView

Displaying a DropDownList column in GridView and setting the selected item.

<asp:TemplateField ShowHeader="False">
                                <asp:DropDownList  ID="DropDownList1" runat="server"  SelectedValue='<%# Bind("Status") %>' autocomplete="off" Width="150">
                                    <asp:ListItem Value="1">Enable</asp:ListItem>
                                    <asp:ListItem Value="2">Disable</asp:ListItem>
                                    <asp:ListItem Value="3">Delete</asp:ListItem>
Leave a comment

Posted by on March 20, 2015 in ASP.Net



Add Dynamic Controls to Content PlaceHolders in ASP.Net

            ContentPlaceHolder holder = Page.Master.FindControl("message") as ContentPlaceHolder;
            HtmlGenericControl alertControl = new HtmlGenericControl();
            alertControl.Attributes["class"] = "alert alert-success";
            alertControl.TagName = "div";
            Label message = new Label();
            message.Text = "User deleted successfully.";
Leave a comment

Posted by on March 20, 2015 in ASP.Net



OpenLayers 3 Map with Marker

OpenLayers 3 Map

<!doctype html>
<html lang="en">
    <link rel="stylesheet" href="" type="text/css">
      .map {
        height: 400px;
        width: 100%;
    <script src="//"></script>
    <script src="" type="text/javascript"></script>
    <title>OpenLayers 3 example</title>
    <h2>My Map</h2>
    <div id="map" class="map"></div>
    var map = new ol.Map({
        target: 'map',
        renderer: 'canvas',
        layers: [
            new ol.layer.Tile({source: new ol.source.OSM()})
        view: new ol.View({
            //projection: 'EPSG:900913',
            center: ol.proj.transform([80.6350, 7.2964], 'EPSG:4326', 'EPSG:3857'),
            zoom: 10

    //Full Screen
    var myFullScreenControl = new ol.control.FullScreen();

    map.addOverlay(new ol.Overlay({
        position: ol.proj.transform(
                [80.6350, 7.2964],
        element: $('<img src="//">')

    map.on('singleclick', function(evt) {
        var coord = evt.coordinate;
        var transformed_coordinate = ol.proj.transform(coord, "EPSG:900913", "EPSG:4326");


1 Comment

Posted by on March 13, 2015 in Geo Programming



ASP.Net Validating CheckBoxList with JavaScript

<asp:CheckBoxList ID="groupsList" runat="server" DataSourceID="GroupsDS" DataTextField="Name" DataValueField="Id" CssClass="span6 m-wrap groupsList" RepeatLayout="UnorderedList"></asp:CheckBoxList>
<asp:CustomValidator ID="CustomValidator1" ErrorMessage="Please select at least one group."
ForeColor="Red" ClientValidationFunction="ValidateCheckBoxList" runat="server" />
<asp:SqlDataSource runat="server" ID="GroupsDS" ConnectionString='<%$ ConnectionStrings:flexi_stocky %>' SelectCommand="SELECT * FROM [Groups]"></asp:SqlDataSource>

<script type="text/javascript">
function ValidateCheckBoxList(sender, args) {
var checkBoxList = document.getElementById("<%=groupsList.ClientID %>");
var checkboxes = checkBoxList.getElementsByTagName("input");
var isValid = false;
for (var i = 0; i < checkboxes.length; i++) {
if (checkboxes[i].checked) {
isValid = true;
args.IsValid = isValid;


Leave a comment

Posted by on March 7, 2015 in JavaScript



ASP.NET GridView ListBox Column Data Binding

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" CssClass="table" DataSourceID="GenericNamesDataSource" DataKeyNames="Id">


<asp:TemplateField HeaderText="Group Name" SortExpression="GroupName">
<asp:ListBox ID="ListBox2" runat="server" DataSourceID="GroupsDataSource" DataTextField="Name" DataValueField="Id"  SelectedValue='<%# Bind("GroupId") %>' SelectionMode="Multiple" CssClass="chzn-select" autocomplete="off" data-placeholder="Select Item(s)"></asp:ListBox>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("GroupName") %>'></asp:Label>



<asp:SqlDataSource ID="GenericNamesDataSource" runat="server" ConnectionString='<%$ ConnectionStrings:flexi_stocky %>'
SelectCommand="SELECT GN.Id, GN.GroupId, GN.CreatedAt, G.Name AS GroupName FROM GenericNames AS GN INNER JOIN Groups AS G ON GN.GroupId = G.Id">


<asp:SqlDataSource ID="GroupsDataSource" runat="server" ConnectionString='<%$ ConnectionStrings:flexi_stocky %>' SelectCommand="SELECT DISTINCT [Id], [Name] FROM [Groups]"></asp:SqlDataSource>

Leave a comment

Posted by on March 6, 2015 in ASP.Net