Nov 5, 2012

How to set css for server controls globally.

Usually Asp.Net controls like textbox, button ,radio button, checkbox are seen as input controls with different types like text,submit,radio etc...

So to set the CSS for the server controls

/* Global font for server controls */

    font-family: Verdana;
    font-size: 10px;

textbox with textmode = password 


Multiline text box
    font-family: Verdana;
    font-size: 10px;

// for radio button/ check boxes
    font-family: Verdana;
    font-size: 10px;

For list boxes
select {
      /*font-family:Arial,Verdana,sans-serif; */
      font-family: Verdana;
/* Global font for server controls */ 

Nov 1, 2012

Unable to update the EntitySet because it has a DefiningQuery and no element exists in the element to support the current operation.

This is the error occurs when there is no primary key set in the table for which you are trying to do some update operation.

Set the primary key for the table and update the Entity model and then try.

Oct 26, 2012

How to pass Eval value to javascript function from GridView ItemTemplate

Passing the Eval value to a javascript method is bit tricky.

You cannot pass directly as shown below.

<asp:LinkButton id='lnk' runat='server' OnClientClick='<%#Eval("columnname",
"javascript:testfun({0});")%>' />

Instead , the below way should work

<asp:LinkButton id='lnk' runat='server' OnClientClick='<%#Eval("columnname",
"javascript:testfun({0});")%>' />

Oct 9, 2012

How to alter all columns of a table in SQL SERVER

To alter all columns of a table :
SET @SQL = (
ALTER TABLE dbo.yourtablename ALTER COLUMN [' + + '] NVARCHAR(MAX) NULL;
FROM sys.columns c WHERE OBJECT_NAME(object_id) = 'yourtablename'
).value('text()[1]', 'VARCHAR(MAX)')

Sep 16, 2012

MultiSelect ListBox seach using Jquery

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ListBox.aspx.cs" Inherits="ListBox" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head id="Head1" runat="server">

    <script type="text/javascript" src=""></script>

    <form id="form1" runat="server">
                <asp:TextBox ID="TextBox1" runat="server" Width="217px"></asp:TextBox>
                <asp:ListBox ID="ListBox1" runat="server" Width="220px" Font-Bold="True"
                    Font-Size="Small" Height="165px">
                    <asp:ListItem Text="krishna" Value="krishna"></asp:ListItem>
                    <asp:ListItem Text="daya" Value="daya"></asp:ListItem>
                    <asp:ListItem Text="bansi" Value="bansi"></asp:ListItem>
                    <asp:ListItem Text="hetal" Value="hetal"></asp:ListItem>
                    <asp:ListItem Text="kavita" Value="kavita"></asp:ListItem>
                    <asp:ListItem Text="poonam" Value="poonam"></asp:ListItem>
                    <asp:ListItem Text="janki" Value="janki"></asp:ListItem>
                    <asp:ListItem Text="niyati" Value="niyati"></asp:ListItem>
                    <asp:ListItem Text="bhumika" Value="bhumika"></asp:ListItem>
                    <asp:ListItem Text="bindi" Value="bindi"></asp:ListItem>
                    <asp:ListItem Text="nayana" Value="nayana"></asp:ListItem>
                    <asp:ListItem Text="nita" Value="nita"></asp:ListItem>
                    <asp:ListItem Text="kajal" Value="kajal"></asp:ListItem>
                    <asp:ListItem Text="jashoda" Value="jashoda"></asp:ListItem>
                    <asp:ListItem Text="shilpa" Value="shilpa"></asp:ListItem>
                    <asp:ListItem Text="ridhi" Value="ridhi"></asp:ListItem>
                    <asp:ListItem Text="rachana" Value="rachana"></asp:ListItem>
                    <asp:ListItem Text="rakshita" Value="rakshita"></asp:ListItem>
                    <asp:ListItem Text="parul" Value="parul"></asp:ListItem>
                     <asp:ListItem Text="twinkle" Value="twinkle"></asp:ListItem>

    <script type="text/javascript">

        function DoListBoxFilter(listBoxSelector, filter, keys, values) {
            var list = $(listBoxSelector);
            var selectBase = '<option value="{0}">{1}</option>';

            for (i = 0; i < values.length; ++i) {

                var value = values[i];

                if (value == "" || value.toLowerCase().indexOf(filter.toLowerCase()) >= 0) {
                    var temp = '<option value="' + keys[i] + '">' + value + '</option>';
        var keys = [];
        var values = [];

        var options = $('#<% = ListBox1.ClientID %> option');
        $.each(options, function(index, item) {
        $('#<% = TextBox1.ClientID %>').keyup(function() {
            var filter = $(this).val();
            DoListBoxFilter('#<% = ListBox1.ClientID %>', filter, keys, values);

Jul 23, 2012

How to open Rad Window on page load from Code Behind.

Rad Window on PageLoad:
using Telerik.Web.UI;
     RadWindow newWindow = new RadWindow();
     newWindow.NavigateUrl = "Test.aspx";
     newWindow.VisibleOnPageLoad = true;
     newWindow.Modal = true;
     newWindow.Width = 750;
     newWindow.Height = 480;

Apr 16, 2012

How to set Identity column value start from certain value + SQL

Below is the SQL query to get the  to set Identity column value start from certain value

DBCC CHECKIDENT ( 'TestDB.dbo.TestTable',RESEED, 1000000)

Mar 7, 2012

How to get fields & assigned domains of FeatureClass + ESRI + C#

here is the code to get fields of a featureclass and check for the assigned domain 

IFields fields = featureClass.Fields;
string domainName = string.Empty;
for (int i = 0; i < fields.FieldCount; i++)
if (fields.get_Field(i).DomainFixed)
domainName = fields.get_Field(i).Domain.Name;


Mar 6, 2012

How to get feature class from the shape file on Disk.

Below is the method that gets the feature class from the shape file
/// Get the FeatureClass from a Shapefile on disk (hard drive).
/// A System.String that is the directory where the shapefile is located.
Example: "C:\data\USA"

/// A System.String that is the shapefile name.
 Note: the shapefile extension's
///(.shp, .shx, .dbf, etc.) is not provided! Example: "States"</param>

public ESRI.ArcGIS.Geodatabase.IFeatureClass GetFeatureClassFromShapefileOnDisk
(System.String string_ShapefileDirectory, System.String string_ShapefileName)
     System.IO.DirectoryInfo directoryInfo_check = new System.IO.DirectoryInfo(                         
      if (directoryInfo_check.Exists)
        //We have a valid directory, proceed
        System.IO.FileInfo fileInfo_check = new System.IO.FileInfo(string_ShapefileDirectory + "\\" +           
                                                                     string_ShapefileName + ".shp");
    if (fileInfo_check.Exists)
        //We have a valid shapefile, proceed

         ESRI.ArcGIS.Geodatabase.IWorkspaceFactory workspaceFactory =
                                                 new ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactoryClass(); 
         ESRI.ArcGIS.Geodatabase.IWorkspace workspace =      
                                                 workspaceFactory.OpenFromFile(string_ShapefileDirectory, 0); 
         ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace =
       // Explict Cast

        ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass = 
        return featureClass;
     //Not valid shapefile
      return null;
    // Not valid directory
       return null;

How to find feature count that intersect an envelope in Geodatabase + C#

In our previous post, we discussed about connecting the File GeoDB and returning the Workspace.

Now will see how to find feature count that intersect an envelope in the File GeoDB

// The method FileGdbWorkspaceFromPropertySet definition is present in our previous post

IWorkspace featureWorkspace = FileGdbWorkspaceFromPropertySet(gdbPath);
        IFeatureWorkspace fws = (IFeatureWorkspace)featureWorkspace;

// Method that Gets Features Count From a FeatureClass

private static int GetCountFromFeatureClass(IFeatureWorkspace fws, string parcelName, IEnvelope envelope)
        // Open the feature classes used by the queries.
        IFeatureClass parcelsFeatureClass = fws.OpenFeatureClass(parcelName);      

        //// Create the spatial filter. Note that the SubFields property specifies that only
        //// the Shape field is retrieved, since the features' attributes aren't being inspected.
        ISpatialFilter spatialFilter = new SpatialFilterClass();
        spatialFilter.Geometry = envelope;
        spatialFilter.GeometryField = parcelsFeatureClass.ShapeFieldName;
        spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
        spatialFilter.SubFields = "Shape";

        // Use IFeatureClass.FeatureCount to get a parcel count.
        return parcelsFeatureClass.FeatureCount(spatialFilter);


Feb 15, 2012

How to connect to a ESRI Geodatabase and return workspace.

Initialize Product License with License Initializer

Connecting to GeoDB is the first step of querying the GeoDB. Inorder to work with the ArcObjects, the ArcGIS license has to be initialized. ESRI provides a License initializer project downloaded from the below link.

Download the Project and add it to your solution which uses arcObjects. Set the Project InitializeProductLicense as the startup and run the project. Debug and see what is the license status returned.

below are the different cases returned

IF the return value is isriLicenseCheckedOut, then license is intialized.     
Below is the method that get path of the geoDB say C:\\test\\Test.gdb and returns the workspace that can be queried for different scenarios.              
Namespace Used:

using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.Geometry;

public static IWorkspace FileGdbWorkspaceFromPropertySet(String path)
            //Initialize the application.
            esriLicenseStatus licenseStatus = esriLicenseStatus.esriLicenseUnavailable;
            IAoInitialize m_AoInitialize = new AoInitializeClass();
            licenseStatus = m_AoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcView);
            Type factoryType = Type.GetTypeFromProgID(
            IWorkspaceFactory2 workspaceFactory = (IWorkspaceFactory2)Activator.CreateInstance
            return workspaceFactory.OpenFromFile(path, 0);

In the next post will see how to query parcels intersecting a envelope in the GeoDB.