how to change row background color of gridview


Create DataBase as follows:

Design .aspx as follows:

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head id="Head1" runat="server">
<title>Gridview onmouseover and onmouseout</title>
<script type="text/javascript">
var oldgridcolor;
function SetMouseOver(element) {
oldgridcolor = element.style.backgroundColor;
element.style.backgroundColor = '#FF9966';
element.style.cursor = 'pointer';
element.style.textDecoration = 'underline';
}
function SetMouseOut(element) {
element.style.backgroundColor = oldgridcolor;
element.style.textDecoration = 'none';
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView runat="server" ID="gvrecords" AutoGenerateColumns="False"
HeaderStyle-BackColor="#7779AF" HeaderStyle-ForeColor="White"
onrowdatabound="gvrecords_RowDataBound" BackColor="#DEBA84" BorderColor="#DEBA84"
BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2">

<Columns>
<asp:BoundField DataField="UserName" HeaderText="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName" />
<asp:BoundField DataField="Location" HeaderText="Location" />
</Columns>
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />

<HeaderStyle BackColor="#A55129" ForeColor="White" Font-Bold="True"></HeaderStyle>
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#FFF1D4" />
<SortedAscendingHeaderStyle BackColor="#B95C30" />
<SortedDescendingCellStyle BackColor="#F1E5CE" />
<SortedDescendingHeaderStyle BackColor="#93451F" />
</asp:GridView>
</div>
</form>
</body>
</html>

Then write Following Code in CodeBehind:

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindGridview();
        }
    }
    protected void gvrecords_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes["onmouseover"] = "javascript:SetMouseOver(this)";
            e.Row.Attributes["onmouseout"] = "javascript:SetMouseOut(this)";
        }
    }
    protected void BindGridview()
    {
        SqlConnection con = new SqlConnection("Data Source=server2;user id=sa;password=123;Initial Catalog=MySampleDB");
        con.Open();
        SqlCommand cmd = new SqlCommand("select * from UserDetails", con);
        cmd.ExecuteNonQuery();
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        gvrecords.DataSource = ds;
        gvrecords.DataBind();
    }

OutPut:

DownLoadSampleCode

how to call javascript function from gridview onmouseover,onmouseout


sometimes we need to call javascript function from gridview

this post will help to do that

First create database table as follows

Then design .aspx page as follows:

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head id="Head1" runat="server">
<title>Gridview onmouseover and onmouseout</title>
<script type="text/javascript">
    var oldgridcolor;
    function SetMouseOver(element) {
        alert("Welcome to onmouseover event.!");
    }
    function SetMouseOut(element) {
//        alert("welcome to onmouseout event");
    }
</script>
</head>
<body style="font-weight: 700">
<form id="form1" runat="server">
<div>
  <asp:GridView runat="server" ID="gvrecords"AutoGenerateColumns="False"
HeaderStyle-BackColor="#7779AF" HeaderStyle-ForeColor="White"
onrowdatabound="gvrecords_RowDataBound" BackColor="#DEBA84" BorderColor="#DEBA84"
        BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2">
<Columns>
<asp:BoundField DataField="UserName" HeaderText="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName" />
<asp:BoundField DataField="Location" HeaderText="Location" />
</Columns>
    <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<HeaderStyle BackColor="#A55129" ForeColor="White" Font-Bold="True"></HeaderStyle>
    <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
    <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
    <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
    <SortedAscendingCellStyle BackColor="#FFF1D4" />
    <SortedAscendingHeaderStyle BackColor="#B95C30" />
    <SortedDescendingCellStyle BackColor="#F1E5CE" />
    <SortedDescendingHeaderStyle BackColor="#93451F" />
</asp:GridView>
</div>
</form>
</body>
</html>

Then Write Following Code in Code Behind:

 
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindGridview();
        }
    }
    protected void gvrecords_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        //here we are setting onmouseover events
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes["onmouseover"] = "javascript:SetMouseOver(this)";
            e.Row.Attributes["onmouseout"] = "javascript:SetMouseOut(this)";
        }
    }
    protected void BindGridview()
    {
        SqlConnection con = new SqlConnection("Data Source=server2;user id=sa;password=123;Initial Catalog=MySampleDB");
        con.Open();
        SqlCommand cmd = new SqlCommand("select * from UserDetails", con);
        cmd.ExecuteNonQuery();
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        gvrecords.DataSource = ds;
        gvrecords.DataBind();
    }

ASP.NET MVC3 Routes


MVC Routes


MVC3 gives you great control over how URLs are mapped to your controllers. It gives you the ability to define your URLs in a human readable SEO (Search Engine Optimization) friendly fashion, to remap old URLs to new functionality and side-by-side utilize classic ASP.NET sites inside of MVC3. It also results in hiding what kind of page user is calling and what environment we are working in. Most of the new websites are following this and it is important to understand that routing is not URL rewriting as routing will have customizations and many attachments towards request/response.
When we create any type of MVC application by default GLOBAL.ASAX file is created becoz ASP.NET implements MVC using this global application class mainly. Routes defined in the Global.asax.cs file of our MVC3 web application/site. In this global.asax file most important element relative to our work is RegisterRoutes method. By default, there is only one route defined in the RegisterRoutes method that looks like the line below.
routes.MapRoute(
“Default”, // Route name
“{controller}/{action}/{id}”, // URL with parameters
new { controller = “Home”, action = “Index”, id = UrlParameter.Optional } // Parameter defaults
);
This route defines the route name, which can be anything as long as it is unique, the URL template, and the parameter defaults. The default route that is pre-defined for you maps to Controller/Action/id. You can add additional routes by copying the same line and adjusting the URL parameters and the related default values. Remember when we add additional routes the order is important.
Custom MVC3 Routes


One of the many factors frequently considered by search engines to determine the relevance of a particular page to a particular search term is whether or not the URL link itself includes a particular term. In a classic ASP.NET site for a magazine, you might have a URL that looks like

http://www.internet.com/ViewArticle.aspx?id=123.

This URL passes the ID number of the article to view, but the URL itself doesn’t describe the content in any human readable way. If the URL instead was http://www.internet.com/MVC3_Routing/123 a human-or a web crawler-could read that and know that the article is about MVC3 Routing.
Another frequent use of custom routing is to allow multiple sites to link to the same location while providing additional data about where they came from. For example, if you had a link to a product page and you wanted to provide custom co-branding based on which one of your partners linked in to a page, you could do so by including a “partner name” variable in the link. A link like this could be to http://www.internet.com/PartnerA/Article/123 or http://www.internet.com/PartnerB/Article/123 for example.This would allow two different sites to link to the same article while providing their own information in the process.

 

The code block below defines a new route called ArticleRoute that defines a new parameter called article in addition to the standard controller and action.
routes.MapRoute(
“ArticleRoute”,
“{article}/{controller}/{action}”,
new { article=”Unknown”, controller = “Home”, action = “Index” } );
You can access this custom article part of the route in your controller by accessing the RouteData object.
RouteData.Values[“article”]
To access the RouteData object in your Razor views, use the @Url.RequestContext.RouteData object.


When you are constructing URLs that use string data such as article titles or author’s names, you will need to use some form of URL-friendly encoding. The easiest method is to use HttpUtility.UrlEncode(“Your String”) which will replace all of the URL unfriendly characters with the appropriate HTML escapes.B This method is web spider friendly but not necessarily human readable URL friendly.
It is very important to remember that any data in a URL is easily user manipulated and shouldn’t be trusted. It is not an appropriate place to pass application variables between pages unless they are of a nature that it would be acceptable if the user manipulated them.
Re-mapping Routes
From time to time it is necessary to re-route an old URL to a new location. Traditionally you would use a redirect page to let users know to update their bookmarks and include a link to the new location. Sometimes it is impractical or even impossible to change URLs as is the case when you have 3rd party software systems set up to access and scrape particular URLs.
If you wanted to route MyRazor.cshtml page to your MVC3 Home/Index controller, you can do so by defining a route like the one below.
routes.MapRoute(“RT”, ” MyRazor.cshtml “,
new { controller = “OtherController”, action = “Packed” });


Including Classic ASP.NET as a Sub-directory in an MVC3 Web Application
If you have a large classic ASP.NET web site that you need to incrementally transition to MVC3 you can put the entire classic ASP.NET web site in your MVC3 web site as a sub-directory. You can then call the IgnoreRoute method seen in the code block below to tell MVC3 to not handle that particular URL path.
routes.IgnoreRoute(“OldClassicASP/”);


Constraints
You can define additional constraints to your defined routes to insure that the values passed for particular parts of your route are valid. This is useful not only for general security related needs but is also useful for scenarios where you might want to have additional routing logic in place for particular routes.
routes.MapRoute(
“ColorPath”, // Route name
“{color}/{controller}/{action}/{id}”, // URL with parameters
new { controller = “Home”, action = “Index”, id = UrlParameter.Optional } // Parameter defaults
, new { color=”blue” }
);
In the example route above, a new anonymous object is added to the MapRoute path call that adds a constraint to this path. The route will only be used if the color is blue.
Namespaces
In large ASP.NET MVC3 applications you can potentially have hundreds of controllers. This can become problematic because the .NET Framework looks in the Controllers folder and all sub-folders looking for controllers to match up with the defined routes.
To help you organize your code, you can add namespaces to your routes to constrain the controllers the route will match to particular namespaces. The route below will only use controllers defined in the Home.Guru namespace.
routes.MapRoute(“NamespacedRoute”, “Cool/{controller}/{action}”,
new { controller = “Home”, action = “Index”, id = UrlParameter.Optional } , null,
, new string[] { “Home.Guru” });


Global Filters
If you want to define code that runs before or after your routing calls, you can define a global filter. Global filters are registered in the Global.asax.cs file by adding a line to the RegisterGlobalFilters method. This method, by default, registers the HandleErrorAttribute that is used to handle error conditions in ASP.NET MVC3 applications.
If you wanted to add a copyright notice at the bottom of all of your pages, you could add a global filter attribute that overrides the OnResultExecuted method which is run after your page has run.
public class CopyrightNoticeAttribute : ActionFilterAttribute
{
public override void OnResultExecuted(ResultExecutedContext filterContext)
{
filterContext.HttpContext.Response.Write(String.Format(“<h1>Copyright {0}</h1>”,DateTime.Now.Year));
}
}
Once your custom attribute has been written you can add it to the global.asax.cs file.
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new CopyrightNoticeAttribute());
filters.Add(new HandleErrorAttribute());//Default in MVC3
}
——————*————————–*———————————–*————–

AJAX::Edit Update Delete Using Accordion Control Using EntityFrameWork


SomeTimes We need to use accordion only to edit update delete

for that, this is the code:

In .aspx Page:

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head id="Head1" runat="server">
<title></title>
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.modalBackground
{
background-color: Gray;
filter: alpha(opacity=80);
opacity: 0.8;
z-index: 10000;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Button ID="btnShow" runat="server"
onclick="btnShow_Click" Text="Click here to see accordion" />
<div>
<cc1:Accordion ID="Accordion1" runat="server"
FadeTransitions="true" RequireOpenedPane="false"
HeaderCssClass="accordionHeader"
ContentCssClass="accordionContent" onitemcommand="Accordion1_ItemCommand">
<HeaderTemplate><%# Eval("Description") %>
</HeaderTemplate>
<ContentTemplate>
<asp:Image ID="btnImg" ImageUrl='<%#Eval("Image") %>'
runat="server" Height="100" />
<br />
<asp:Label id="lbl1" Text="Features :"
style="font-weight:bold; color:Blue" runat="server" />
<%# Eval("Feature") %>
<br />
<asp:Label id="lbl2" Text="Vendor:"
style="font-weight:bold; color:Blue" runat="server" />
<%# Eval("Seller") %>
<br />
<asp:Label id="lb3" Text="Price:"
style="font-weight:bold; color:Blue" runat="server" />
<%# Eval("Price") %>
<br />
<asp:LinkButton ID="LinkButton1" runat="server" CommandArgument='<%#Eval("Id") %>' CommandName="Edit">Edit</asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CommandArgument='<%#Eval("Id") %>' CommandName="Delete">Delete</asp:LinkButton>
</ContentTemplate>
</cc1:Accordion>
<asp:Label ID="lblresult" runat="server"/>
<asp:Button ID="btnShowPopup" runat="server" style="display:none" />
<cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnShowPopup" PopupControlID="pnlpopup"
CancelControlID="btnCancel" BackgroundCssClass="modalBackground">
</cc1:ModalPopupExtender>
<asp:Panel ID="pnlpopup" runat="server" BackColor="White" Height="209px" Width="400px" style="display:none">
<table width="100%" style="border:Solid 3px #D55500; width:100%; height:100%" cellpadding="0" cellspacing="0">
<tr style="background-color:#D55500">
<td colspan="2" style=" height:10%; color:White; font-weight:bold; font-size:larger" align="center"> Details</td>
</tr>
<tr>
<td>
<asp:Label ID="lblID" Font-Bold="true" ForeColor="Green" runat="server"></asp:Label>
</td>
</tr>
<tr><td>
<asp:Image ID="Image1" runat="server" Height="100" Width="100"/></td></tr>
<tr><td>
<asp:TextBox ID="tb2" runat="server" Text="Label"></asp:TextBox></td></tr>
<tr><td>
<asp:TextBox ID="tb3" runat="server" Text="Label"></asp:TextBox></td></tr>
<tr><td>
<asp:TextBox ID="tb4" runat="server" Text="Label"></asp:TextBox></td></tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="ButtonUpdate" runat="server" OnClick="Update" Text="Update"/>
<asp:Button ID="btnCancel" runat="server" Text="Cancel" />
</td>
</tr>
</table>
</asp:Panel>
</div>
</form>
</body>
</html>

CodeBehind:

 

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    static int ItemNo;
    protected void btnShow_Click(object sender, EventArgs e)
    {
        DatabaseModel.DatabaseEntities obj = new DatabaseModel.DatabaseEntities();
        var x = (from n in obj.Items
                 select n);
        Accordion1.DataSource = x;
        Accordion1.DataBind();
    }
    protected void Accordion1_ItemCommand(object sender, CommandEventArgs e)
    {
        ItemNo = Convert.ToInt32(e.CommandArgument);
        DatabaseModel.DatabaseEntities obj = new DatabaseModel.DatabaseEntities();
        if (e.CommandName == "Edit")
        {
            Class1 cls = new Class1();
            var x = (from n in obj.Items
                     where n.Id == ItemNo
                     select new
                     {
                         n.Description,
                         n.Image,
                         n.Seller,
                         n.Price,
                         n.Feature
                     }).FirstOrDefault();
            this.ModalPopupExtender1.Show();
            lblID.Text = x.Description;
            Image1.ImageUrl = x.Image;
            tb2.Text = x.Feature;
            tb3.Text = x.Seller;
            tb4.Text = x.Price;
        }
        else if (e.CommandName == "Delete")
        {
            var x = (from n in obj.Items where n.Id == ItemNo select n).FirstOrDefault();
            obj.Items.DeleteObject(x);
            obj.SaveChanges();
            btnShow_Click(sender, e);
        }
    }
    public void Update(object sender, EventArgs e)
    {
        DatabaseModel.DatabaseEntities obj = new DatabaseModel.DatabaseEntities();
        var x = (from n in obj.Items where n.Id == ItemNo select n).FirstOrDefault();
        if (x != null)
        {
            x.Description = lblID.Text;
            x.Feature = tb2.Text;
            x.Seller = tb3.Text;
            x.Price = tb4.Text;
            obj.SaveChanges();
            btnShow_Click(sender, e);
        }
    }
}

DownLoad SampleCode

How to clear states of all types of controls in asp.net form like textboxes, dropdownlists and checkboxes


Introduction:

Sometimes we have forms with 30 or 40 controls(includes textboxes , checkboxes and dropdownlists). At this time, if we want to clear all contols for single button click , normally we need to write code for all controls text to string.empty or null this is lengthy and timetaking process. to overcome this process, here we are creating following process

for this we need to place all controls in form tag only

if you are not interested to place in form

you can use any container controls like pannel or etc…

Using Form Tag:

Code in .aspx Page:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Cleartb.aspx.cs" Inherits="Cleartb" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:DropDownList ID="DropDownList1"
runat="server">
<asp:ListItem>default</asp:ListItem>
<asp:ListItem>first</asp:ListItem>
<asp:ListItem>second</asp:ListItem>
<asp:ListItem>third</asp:ListItem>
<asp:ListItem>fourth</asp:ListItem>
</asp:DropDownList>
<br />
<asp:CheckBox ID="CheckBox1" runat="server" />
<br />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" Text="Clear" onclick="Button1_Click" />
</div>
</form>
</body>
</html>

Code Under Buttonclick event:
protected void Button1_Click(object sender, EventArgs e)
    {
        foreach (Control ctrl in form1.Controls)
        {
            if (ctrl is TextBox)
            {
                TextBox tb = (TextBox)ctrl;
                tb.Text = string.Empty;
            }
            else if (ctrl is DropDownList)
            {
                DropDownList dl = (DropDownList)ctrl;
                dl.SelectedIndex = 0;
            }
            else if (ctrl is CheckBox)
            {
                CheckBox cb = (CheckBox)ctrl;
                cb.Checked = false;
            }
        }
    }

Using Panel Container:

Code in .aspx Page:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Cleartb.aspx.cs" Inherits="Cleartb" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">

<asp:Panel ID="Panel1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:DropDownList ID="DropDownList1"
runat="server">
<asp:ListItem>default</asp:ListItem>
<asp:ListItem>first</asp:ListItem>
<asp:ListItem>second</asp:ListItem>
<asp:ListItem>third</asp:ListItem>
<asp:ListItem>fourth</asp:ListItem>
</asp:DropDownList>
<br />
<asp:CheckBox ID="CheckBox1" runat="server" />
<br />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" Text="Clear" onclick="Button1_Click" />
</div>

</asp:Panel>
</form>
</body>
</html>

Code Under Buttonclick event:
protected void Button1_Click(object sender, EventArgs e)
    {
        foreach (Control ctrl in Panel1.Controls)
        {
            if (ctrl is TextBox)
            {
                TextBox tb = (TextBox)ctrl;
                tb.Text = string.Empty;
            }
            else if (ctrl is DropDownList)
            {
                DropDownList dl = (DropDownList)ctrl;
                dl.SelectedIndex = 0;
            }
            else if (ctrl is CheckBox)
            {
                CheckBox cb = (CheckBox)ctrl;
                cb.Checked = false;
            }
        }
    }

Using Javascript:

<html xmlns="http://www.w3.org/1999/xhtml&quot; >
<head id="Head1" runat="server">
<title>Reset controls</title>
<script language="javascript" type='text/javascript'>
function Clear() {
for (i = 0; i < document.forms[0].length; i++) {
doc = document.forms[0].elements[i];
switch (doc.type) {
case "text":
doc.value = "";
break;
case "checkbox":
doc.checked = false;
break;
case "radio":
doc.checked = false;
break;
case "select-one":
doc.options[doc.selectedIndex].selected = false;
break;
case "select-multiple":
while (doc.selectedIndex != -1) {
indx = doc.selectedIndex;
doc.options[indx].selected = false;
}
doc.selected = false;
break;

default:
break;
}
}
}

</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBox ID="CheckBox1"
runat="server" /><asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>Default</asp:ListItem>
<asp:ListItem>First</asp:ListItem>
<asp:ListItem>Second</asp:ListItem>
<asp:ListItem>Third</asp:ListItem>
</asp:DropDownList>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><asp:TextBox ID="TextBox2"
runat="server"></asp:TextBox>
<input id="Button1" type='button' onclick='Clear()' value='ClearState'/>
</div>
</form>
</body>
</html>

How to show progressbar while some process is in progress in windows forms application


Sometimes we are processing long time at that time user need to wait for process to complete

If we don’t show any progress user might feel something uncomfortable. To give relax from that feel we have to show some progress about that process.

How to show that progress:

First design the form as follows:

Controls to place in form:

1.Progressbar

2.timer

3.button

4.label

After adding these controls to form set the following properties:

For Progressbar:

Set value property = 10

Set maximum property  = 1000

Minimum = 10

Step = 1

Then write following code under button click event

timer1.Enabled = true;

 

then write following  code under timer tick event

if (progressBar1.Value < progressBar1.Maximum)

{

progressBar1.PerformStep();

}

else

{

this.Hide();

timer1.Enabled = false;

MessageBox.Show(“your data send…”);

}