Saturday 29 March 2014

Delete gridview records with confirmation message box example in ASP.NET

In this article I will explain how to delete records in gridview with confirmation message box in ASP.NET.


User clicks on Delete link button in GridView at that time I need to show confirmation message box and if user clicks on ok button in confirmation message box I want to delete record from database and rebind the gridview otherwise no action should perform on particular record.

Below is the Sample Code:

protected void gvFileDetails_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton btnDelete = (LinkButton)e.Row.FindControl("lnkDelete");
if (btnDelete != null)
{
btnDelete.Attributes.Add("onclick", "javascript:return " +
"confirm('Are you sure you want to delete this record?')");
}
}
}

Friday 28 March 2014

Highlight GridView rows on Mouseover and Mouseout in ASP.NET using JavaScript

In this article I will explain how to highlight GridView rows on Mouseover and Mouseout in ASP.NET using JavaScript.

In my previous article I explained how to insert, update, Delete in gridview and Upload Images in gridview and Upload files & Download in gridview. In the present article I got the requirement like change GridView rows color based on Mouseover and Mouseout using asp.net for that I used JavaScript functionality to handle onmouseover and onmouseout situations.

First we need to establish a connection in Web.config file.

<connectionStrings>
<add name="connectionString" connectionString="Data Source=LocalHost;uid=sa1;password=Con@123;Initial Catalog=practice"/>
</connectionStrings>

JavaScript code for MouseOver and MouseOut event code:

<script type="text/javascript">
var Priviousgridcolor;
function GridMouseOver(element) {
Priviousgridcolor = element.style.backgroundColor;
element.style.backgroundColor = '#C0C0C0';
element.style.cursor = 'pointer';
}
function GridMouseOut(element) {
element.style.backgroundColor = Priviousgridcolor;
element.style.textDecoration = 'none'; 
}
</script> 

How to create dynamic DataTable and bind data to columns in dynamic DataTable using asp.net

In this article I will explain how to create dynamic DataTable and bind data to columns in dynamic DataTable using ASP.NET.

First Open new website , Right click and add new page with the name as DynamicallyCreateDataTable.aspx after that we need to create one new DataTable after that add columns with DataTypes and bind data to columns after that add those columns to DataTable.

Output:


How to increase or restrict the size of file upload in ASP.NET


In this article I will explain how to increase or restrict the size of file upload in ASP.NET

Syntax:

<httpRuntime
   executionTimeout = "HH:MM:SS"
   maxRequestLength = "number" />

Example:

Open your Web.config file, and just below the <system.web> tag, add the following tag:
Below code is useful for upload 20 MB size file.

<system.web>
      <httpRuntime executionTimeout="90" maxRequestLength="2097151"/>
</system.web>

How to upload or Save files in folder and download files when click on Download link in gridview using asp.net

In this article I will explain how to upload or Save files in folder and download files when click on Download link in gridview using asp.net.

We have different ways to save files in our project Solution explorer under folder. If we save files in our database it will occupy more space so it will create problem for us after host website because host providers will provide limited space for us we can solve this problem by saving files in our project folder.

Below is the DataBase design screen (Table Design). 


 First we need to create a new website. After that right click on your website and add new folder and give name as Files because here I am using same name for my sample if you want to change folder name you need to change the Files folder name in your code behind also

We need to establish a Database connection in web.config file

<connectionStrings>
<add name="connectionString" connectionString="Data Source=LocalHost;uid=sa1;password=Con@123;Initial Catalog=practice"/>
</connectionStrings>

How to insert images into our project folder and display the images in gridview using asp.net

In this article I will explain how to insert images into our project folder and display the images in gridview using asp.net.

In this article I will explain how to insert images into our project solution folder and insert images path into database and display images in GridView from images folder based on Images path in database. Finally, How to insert images into our project folder and display the images in gridview using asp.net? For that first create new website after that right click on your website and add new folder and give name as images because here I used same name for my sample if you want to change folder name you need to change the images folder name in your code behind also first design table in your database like this to save images path in database.

Below is the DataBase design screen(Table Design).



First you need to establish a DataBase connection in web.config file

<connectionStrings>
<add name="connectionString" connectionString="Data Source=LocalHost;uid=sa1;password=Con@123;Initial Catalog=practice"/>
</connectionStrings>

Wednesday 26 March 2014

How to check special characters in TextBox using JQuery

In this article I will explain how to check special characters in ASP.NET TextBox using JQuery

JQuery is very lightweight library. JQuery is a matured open source library that makes life easy when doing some client side programming or scripting. It simplifies the way JavaScript is written. It is light weight, fast and works on modern browsers, thus it’s widely accepted among the web developers and even Visual Studio 2010 and ASP.net 4.0 now come with it.

Below is the JQuery function for Special characters verification code

  $(function () {
            $('.view').blur(function () {
                var str = $('#txtName').val();
                if (/^[a-zA-Z0-9- ]*$/.test(str) == false) {
                    alert('String Contains illegal Characters.');
                }
                else {
                }
            })
        })

Monday 24 March 2014

JQuery Split Function in ASP.NET

In this article I will explain how to split the string using split function in JQuery with ASP.NET.

The split () method is used to split a string into an array of substrings, and returns the new array.

If you observe below script I used special character '-' to split string and assign the new string to new Textbox. If you want check this code in sample check below code

Example:

<script type="text/javascript">
        $(document).ready(function () {
            $('#btnCheckSplit').click(function () {
                var name = $('#txtSiteName').val();
                var arr = name.split('-');
                var sampletxt = '';

                for (var i = 0; i < arr.length; i++) {
                    sampletxt += arr[i];
                    sampletxt += ' ';
                }

                document.getElementById("<%= lblOutput.ClientID%>").value = sampletxt;
            })
        });
    </script>

Thursday 20 March 2014

How to remove default loading popup image in Kendo UI grid

In this article I will explain how to disable the default loading popup image in kendo UI grid.

Many of us may find the loading popup very small and sometimes the user may not see it clearly. To avoid this we’ll be using our own modal popups. But still the default modal popup cannot be removed completely. This makes difficult for the user to identify whether the data is retrieved or not. In order to overcome this we can hide the default modal popup using CSS.

To hide the default modal popup we have to write the required CSS property.

Define a style tag on the beginning of the .cshtml page.

<style>
</style>

Inside the style tag you can write the following CSS to hide the default loading image in the kendoUI grid.

.k-loading-image {
        display: none;
    }

Now the entire code altogether is

<style>

.k-loading-image {
        display: none;
    }
</style>


The applied CSS style hides the default modal popup image. If you want the same action to happen in all the pages, define the above mentioned CSS in the corresponding layout page.

Wednesday 19 March 2014

How to open popup window in ASP.NET with JavaScript


In this article I will explain how to open a popup window in ASP.NET using JavaScript.

Sample JavaScript code:

Below is the sample code for showing popup window. Login.aspx is an Popup window page. Target is set to blank(_blank) and we set directions for the popup window. 

 function LoginPop() {
var n;
 n = window.open('Login.aspx', '_blank', 'channelmode=no,directories=no,left=0,location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,titlebar=yes,toolbar=no,top=0', true);n.focus(); CloseWindow();
        }

The open () method opens a new browser window. Open method supports all major browsers.

Syntax:

window.open(URL,name,specs,replace)

Tuesday 18 March 2014

GridView rowdatabound event for dropdown in asp.net


In this article I will explain how to find inside GridView controls in RowDataBound Event in ASP.NET

Syntax:

<asp:GridView OnRowDataBound="GridViewRowEventHandler" />

Gridview control is most common control in all asp.net applications to display the data and it’s very powerful control and lot of built in features. In this article, I will explore some tips and tricks in rowdatabound event in gridvew control, Actually RowDatabound event will occur when data row is bound to the control in the gridview control.

Find dropdown control in RowDataBound event

Using this event we can able to find the specific controls such as dropdown and get values from control which is used inside gridview control.

protected void gvNew_RowDataBound(object sender, GridViewRowEventArgs e)
    {
DropDownList ddlMainET = (DropDownList)e.Row.FindControl("ddlMainET");
if (ddlMainET != null)
            {
                DataSet dsCostCategory = new DataSet();

                // here we get data from DataBase.

                dsCostCategory = ObjAtSite.GetCostCategory();     
                ddlMainET.DataSource = dsCostCategory.Tables[0];
                ddlMainET.DataTextField = "CostDesc";
                ddlMainET.DataValueField = "CostSk";
                ddlMainET.DataBind();

                if (dsECMCostCategory.Tables[0].Rows.Count > 0)
                {
                    ListItem item = new ListItem("--Select--", "0");
                    ddlMainET.Items.Insert(0, item);                   
                }

// here dsData is an DataSet( GridView data binding DataSet )
// 30 is an page size
// Session["psAllocation"] is page index number
ddlMainET.SelectedValue = dsData.Table[0].Rows[(Convert.ToInt32(Session["psAllocation"]) * 30) + e.Row.RowIndex]["CostSk"].ToString();
               
            }

}