DropDownList in GridView Async and find Control in Class File in c#.net


In this article, I have described the ways of keeping DropDownList in the GridView and binding the data by preserving the default SelectedValue. Apart from DropDownList, I have also shown how to keep CheckBox, RadioButtonList, TextBox in the GridView and preserving the default data,how to find control in class file ,how to use async Trigger in Update Panel using GridView in C#.net

Placing the DropDownList in the GridView

To place the DropDownList in the GridView, you will have to use asp:TemplateField that under <Columns>, Generally you will need to use the DropDownList in the GridView in the Edit mode (under EditItemTemplate, However this solution will work for you even if you want to place the DropDownList in the ItemTemplate) where you want your user to select the data from the DropDownList and update the record. A typical example is shown in the picture below

Image

The aspx page code of above GridView is below

<%@ Page Title="" Language="C#" MasterPageFile="~/GridMaster.master" AutoEventWireup="true"
    CodeFile="Default.aspx.cs" Inherits="Default" %>
 
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"
    ClientIDMode="Static">
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" ClientIDMode="Static">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="GridView1" />
        </Triggers>
        <ContentTemplate>
            <asp:Label ID="lblMessage" runat="server" EnableViewState="true" />
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" ClientIDMode="Static"
                GridLines="None" AutoGenerateEditButton="True" OnRowCancelingEdit="GridViewCancelEdit"
                OnRowEditing="GridViewEdit" OnRowUpdating="GridViewUpdate" 
                DataKeyNames="PersonID" CellPadding="4" ForeColor="#333333">
                <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                <Columns>
                    <asp:BoundField DataField="PersonID" HeaderText="Person ID" ReadOnly="True" Visible="false" />
                    <asp:TemplateField HeaderText="First Name">
                        <ItemTemplate>
                            <%# Eval("FName") %>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="txtFirstName" runat="server" Text='<%# Eval("FName") %>' />
                        </EditItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Last Name">
                        <ItemTemplate>
                            <%# Eval("LName") %>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="txtLastName" runat="server" Text='<%# Eval("LName") %>' />
                        </EditItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Department DropDown">
                        <ItemTemplate>
                            <%# Eval("DeptName")%>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:DropDownList ID="dropDownDept" DataSource="<%# BindDropDownDepartment() %>"
                                DataTextField="DeptName" DataValueField="DeptId" runat="server" SelectedValue='<%# Eval("DeptId").ToString() %>'>
                            </asp:DropDownList>
                        </EditItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="CustomCheckBox Field">
                        <ItemTemplate>
                            <%# Eval("IsActive") %>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:CheckBox ID="chkActive" runat="server" Checked='<%# Eval("IsActive") %>' />
                        </EditItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="RadioButtonField">
                        <ItemTemplate>
                            <%# Eval("IsActive") %>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:RadioButtonList ID="radioActive" runat="server" RepeatDirection="Horizontal"
                                RepeatLayout="Flow" SelectedValue='<%# Eval("IsActive") %>'>
                                <asp:ListItem Text="True" Value="True" />
                                <asp:ListItem Text="False" Value="False" />
                            </asp:RadioButtonList>
                        </EditItemTemplate>
                    </asp:TemplateField>
                </Columns>
                <EditRowStyle BackColor="#999999" />
                <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                <SortedAscendingCellStyle BackColor="#E9E7E2" />
                <SortedAscendingHeaderStyle BackColor="#506C8C" />
                <SortedDescendingCellStyle BackColor="#FFFDF8" />
                <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
            </asp:GridView>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>

In your code behind file of Default.aspx.cs code will be such as below given

using System;
using System.Data;
 
public partial class Default : System.Web.UI.Page
{
 
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            var obj = new BAL();
            obj.LoadPerson(ref  GridView1);
        }
    }
    
    protected DataTable BindDropDownDepartment()
    {
        var obj = new BAL();
        return obj.LoadAll();
    }
    protected void GridViewCancelEdit(object sender, System.Web.UI.WebControls.GridViewCancelEditEventArgs e)
    {
        var obj = new BAL();
        GridView1.EditIndex =-1;
        obj.LoadPerson(ref  GridView1);
 
    }
    protected void GridViewEdit(object sender, System.Web.UI.WebControls.GridViewEditEventArgs e)
    {
        var obj = new BAL();
        GridView1.EditIndex = e.NewEditIndex;
        obj.LoadPerson(ref  GridView1);
 
    }
    protected void GridViewUpdate(object sender, System.Web.UI.WebControls.GridViewUpdateEventArgs e)
    {
        
        GridView1.EditIndex = -1;
        var obj = new BAL();
        obj.UpdateGrid(ref GridView1, e.RowIndex);
    }
}

Now Add a class File in Your Application and write down in that below given code.

using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.UI.WebControls;
 
/// <summary>
/// Summary description for BAL
/// </summary>
public class BAL
{
 
    public BAL()
    {
        //
        // TODO: Add constructor logic here
        //
    }
    public void LoadPerson(ref GridView grd)
    {
 
        using (var objCon = new SqlConnection())
        {
            objCon.ConnectionString = ConfigurationManager.ConnectionStrings["cnGrid"].ConnectionString;
            if (objCon.State == ConnectionState.Closed)
                objCon.Open();
            using (var objAdp = new SqlDataAdapter("usp_PersonRecords", objCon))
            {
                objAdp.SelectCommand.CommandType = CommandType.StoredProcedure;
                var ds = new DataSet();
                objAdp.Fill(ds);
                grd.DataSource = ds.Tables[0];
                grd.DataBind();
            }
        }
 
    }
    public DataTable LoadAll()
    {
        dynamic objDt;
        using (var objCon = new SqlConnection())
        {
            objCon.ConnectionString = ConfigurationManager.ConnectionStrings["cnGrid"].ConnectionString;
            if (objCon.State == ConnectionState.Closed)
                objCon.Open();
            using (var objAdp = new SqlDataAdapter("usp_DeptRecords", objCon))
            {
                objAdp.SelectCommand.CommandType = CommandType.StoredProcedure;
                var ds = new DataSet();
                objAdp.Fill(ds);
                objDt = ds.Tables[0];
            }
        }
        return objDt;
    }
    public void UpdateGrid(ref GridView grd, int index)
    {
 
        var row = grd.Rows[index];
        var ddlDept = (DropDownList)row.FindControl("dropDownDept");
        var txtFname = (TextBox)row.FindControl("txtFirstName");
        var txtLname = (TextBox)row.FindControl("txtLastName");
        var isActive = (RadioButtonList)row.FindControl("radioActive");
        var chkAct = (CheckBox)row.FindControl("chkActive");
 
        var id = Convert.ToInt32(grd.DataKeys[row.RowIndex].Value);
        var FNAME = txtFname.Text.ToUpper();
        var lname = txtLname.Text.ToUpper();
        var deptID = Convert.ToInt32(ddlDept.SelectedItem.Value);
        var isactive = isActive.SelectedValue == "True" ? Convert.ToInt32(1) : Convert.ToInt32(0);
        using (var objCon = new SqlConnection())
        {
            objCon.ConnectionString = ConfigurationManager.ConnectionStrings["cnGrid"].ConnectionString;
            if (objCon.State == ConnectionState.Closed)
                objCon.Open();
            using (var cmd = new SqlCommand("usp_PersonUpdate", objCon))
            {
                cmd.CommandType = CommandType.StoredProcedure;
 
                var parm = new[]
                               {
                                   new SqlParameter("@PersonID", SqlDbType.Int, Int32.MaxValue) {Value =id},
                                   new SqlParameter("@FName", SqlDbType.VarChar, 100) {Value =FNAME },
                                   new SqlParameter("@LName", SqlDbType.VarChar, 100) {Value = lname},
                                   new SqlParameter("@DeptID", SqlDbType.Int, Int32.MaxValue) {Value =deptID},
                                   new SqlParameter("@IsActive", SqlDbType.Bit) {  Value = isactive}
                               };
                cmd.Parameters.AddRange(parm);
                cmd.ExecuteNonQuery();
                cmd.Dispose();
                LoadPerson(ref grd);
            }
        }
    }
}

Now  Run by pressing F5 remember that before run to this ensure your database and connection string  in web config file and change in that setting of your MSSQLServer

<connectionStrings>
		<add name="cnGrid" connectionString="Data Source=xxxx;Initial Catalog=dbGrid;Persist Security Info=True;User ID=xxx;Password=xxx;Pooling=False" providerName="System.Data.SqlClient"/>
</connectionStrings>

Download Url : https://docs.google.com/file/d/0B-sDsBkcsM1YODBWaVZmLTJ6YlE/edit?usp=sharing

Advertisements

Unobtrusive validations in ASP.Net 4.5 Web Forms


Unobtrusive validations in ASP.Net 4.5 Web Forms

With the release of ASP.Net 4.5 web forms there are tons of features added in the ASP.Net and Unobtrusive validations support is one of them. We have already seen that kind of validation in ASP.Net MVC and now we are going to have that in ASP.Net web forms. In this post I am going to explain how its works and how its different from earlier versions.

How validation was working with earlier versions?

In the earlier versions of ASP.Net it was working via putting a JavaScript for that. Let’s take a simple example. I have putted three things here. A textbox, required field validator and a button like following.

<div>
    <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
    <asp:Button ID="btnSubmit" runat="server" Text="Submit" />
    <asp:RequiredFieldValidator ID="reqname" runat="server"
         ErrorMessage="Name is required" ControlToValidate="txtName">
     </asp:RequiredFieldValidator>
</div>

Now once you run browser and click on the button it validate the textbox and give a validation message like “Name is required”.

Unobtrusive validation in asp.net 4.5

Now, When you right click and view source. You will see that there is a JavaScript code embedded to page.

Unobtrusive validation in asp.net 4.5

And this is how the element will be rendered in html.

Unobtrusive validation in asp.net 4.5

So here everything is there based on JavaScript. It will create a page validator array and based on that it will validate when we submit form.

How Unobtrusive validations works in ASP.Net 4.5:

If you create web application in ASP.Net 4.5 It will enabled by default. So let’s see how its works. We are going to use same thing as above.

It’s works in same way as worked earlier when you click submit it will validate textbox and give a validation message “Name is required”.

Unobtrusive validation in asp.net 4.5

Now you done view source. It will look like following.

Unobtrusive validation in asp.net 4.5

Here you can see that It has added “data-val” attribute and based on that it will validate the control. It’s HTML5 way of doing validations. You can see it’s much cleaner then earlier version of asp.net.

Prerequisites for Unobtrusive validations:

This validation requires a jQuery.js file as internally its using jQuery for the validations. So if you have created an empty ASP.Net 4.5 web application. You need to add following code in application_start event of global.asax file.

protected void Application_Start(object sender, EventArgs e)
{
        ScriptManager.ScriptResourceMapping.AddDefinition("jquery",
        new ScriptResourceDefinition
        {
            Path = "~/scripts/jquery-2.0.0.min.js",
            DebugPath = "~/scripts/jquery-2.0.0.js",
            CdnPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.0.0.min.js",
            CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.0.0.js"
        });
}

 

How to configure Unobtrusive validations in ASP.Net 4.5:

There are few ways of configuring the Unobtrusive validations in ASP.Net 4.5. There is a property got added UnobtrusiveValidationMode  and It has two value.

  • None : It will tell that validation work in old fashion way. It will disable Unobtrusive validation.
  • WebForms: It will tell that it will have Unobtrusive validations.

There are multiple ways you can configure this property. You can put that app settings like following.

<appsettings>
    <add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/>
</appsettings>

Or you can write at application_start event like below.

void Application_Start(object sender, EventArgs e)
{
    ValidationSettings.UnobtrusiveValidationMode =
            UnobtrusiveValidationMode.WebForms;
}

Or you can write in page_load event like following.

protected void Page_Load(object sender, EventArgs e)
{
    Page.UnobtrusiveValidationMode = UnobtrusiveValidationMode.WebForms;
}

That’s it. Hope you like it. Stay tuned for more..

Easy to Style jQuery Drop Down Menu


1. HTML

This would be the most common way to structure a list menu. It would make sense even if the CSS is disabled.

<ul id="nav">
	<li><a href="#">Parent 01</a></li>
	<li><a href="#">Parent 02</a>
		<ul>
			<li><a href="#">Item 01</a></li>
			<li><a href="#">Item 02</a></li>
			<li><a href="#">Item 03</a></li>
		</ul>
		<div></div>
	</li>
	<li><a href="#">Parent 03</a>
	<ul>
		<li><a href="#">Item 04</a></li>
		<li><a href="#">Item 05</a></li>
		<li><a href="#">Item 06</a></li>
		<li><a href="#">Item 07</a></li>
	</ul>			
		<div></div>
	</li>
	<li><a href="#">Parent 04</a></li>
</ul>

<div></div>

2. CSS

CSS is quite simple, we have to style two UL List – parent menu and submenu. We put float left for the parent menu so that all the list item would display inline. For the submenu, it’s hidden by default, and will only display on mouse over event.

body {font-family:arial; font-size:11px;}
.clear {clear:both}	
/* remove the list style */
#nav {
	margin:0; 
	padding:0; 
	list-style:none;
}	
	
	/* make the LI display inline */
	/* it's position relative so that position absolute */
	/* can be used in submenu */
	#nav li {
		float:left; 
		display:block; 
		width:100px; 
		background:#ccc; 
		position:relative;
		z-index:500; 
		margin:0 1px;
	}
		
	/* this is the parent menu */
	#nav li a {
		display:block; 
		padding:8px 5px 0 5px; 
		font-weight:700;  
		height:23px; 
		text-decoration:none; 
		color:#fff; 
		text-align:center; 
		color:#333;
	}

	#nav li a:hover {
		color:#fff;
	}
	
	/* you can make a different style for default selected value */
	#nav a.selected {
		color:#f00;
	}
	
		/* submenu, it's hidden by default */
		#nav ul {
			position:absolute; 
			left:0; 
			display:none; 
			margin:0 0 0 -1px; 
			padding:0; 
			list-style:none;
		}
		
		#nav ul li {
			width:100px; 
			float:left; 
			border-top:1px solid #fff;
		}
		
		/* display block will make the link fill the whole area of LI */
		#nav ul a {
			display:block;  
			height:15px;
			padding: 8px 5px; 
			color:#666;
		}
		
		#nav ul a:hover {
			text-decoration:underline;	
		}

/* fix ie6 small issue */
/* we should always avoid using hack like this */
/* should put it into separate file : ) */
*html #nav ul {
	margin:0 0 0 -2px;
}

3. Javascript

This could be one of the most simplest jQuery scripts. We are using hover mouse event and just the most basic jQuery animation slideUp and slideDown. 🙂 I love jQuery

$(document).ready(function () {	
	
	$('#nav li').hover(
		function () {
			//show its submenu
			$('ul', this).stop().slideDown(100);

		}, 
		function () {
			//hide its submenu
			$('ul', this).stop().slideUp(100);			
		}
	);
	
});

Display Rows as Columns in Gridview in Asp.net using C#


Here I will explain how to display gridview columns as rows in asp.net or display gridview rows as columns in asp.net using C#.

If you want change columns as rows we need to write code like as shown below
 
 
<head runat=”server”>
<title>Convert Gridview Columns as Rows in Asp.net</title>
<style type=”text/css”>
body
{
font-family:Calibri;
}
.gridcss
{
background:#df5015;
font-weight:bold;
color:White;
}
</style>
</head>
<body>
<form id=”form1″ runat=”server”>
<table>
<tr>
<td><b>Normal Gridview</b></td>
<td>&nbsp;&nbsp;</td>
<td><b>Converted Gridview</b></td>
</tr>
<tr>
<td>
<asp:GridView ID=”gvnormal” runat=”server”>
<HeaderStyle BackColor=”#df5015″ Font-Bold=”true” ForeColor=”White” />
</asp:GridView>
</td>
<td>&nbsp;&nbsp;</td>
<td>
<asp:GridView ID=”gvconverted” runat=”server” OnRowDataBound=gvconverted_RowDataBound>
</asp:GridView>
</td>
</tr>
</table>
</form>
</body>

</html>

Now in code behind add following namespace references
C# Code
 
using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI.WebControls;
After that write the following code in code behind
 
 
 
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGridviewData();
}
}
protected void BindGridviewData()
{
DataTable dt = new DataTable();
dt.Columns.Add(“UserId”, typeof(Int32));
dt.Columns.Add(“UserName”, typeof(string));
dt.Columns.Add(“Education”, typeof(string));
dt.Columns.Add(“Location”, typeof(string));
DataRow dtrow = dt.NewRow();    // Create New Row
dtrow[“UserId”] = 1;            //Bind Data to Columns
dtrow[“UserName”] = “SureshDasari”;
dtrow[“Education”] = “B.Tech”;
dtrow[“Location”] = “Chennai”;
dt.Rows.Add(dtrow);
dtrow = dt.NewRow();               // Create New Row
dtrow[“UserId”] = 2;               //Bind Data to Columns
dtrow[“UserName”] = “MadhavSai”;
dtrow[“Education”] = “MBA”;
dtrow[“Location”] = “Nagpur”;
dt.Rows.Add(dtrow);
dtrow = dt.NewRow();              // Create New Row
dtrow[“UserId”] = 3;              //Bind Data to Columns
dtrow[“UserName”] = “MaheshDasari”;
dtrow[“Education”] = “B.Tech”;
dtrow[“Location”] = “Nuzividu”;
dt.Rows.Add(dtrow);
gvnormal.DataSource = dt;
gvnormal.DataBind();
gvconverted.DataSource = ConvertColumnsAsRows(dt);
gvconverted.DataBind();
gvconverted.HeaderRow.Visible = false;
}
protected void gvconverted_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[0].CssClass = “gridcss”;
}
}
// This function is used to convert columns to rows
public DataTable ConvertColumnsAsRows(DataTable dt)
{
DataTable dtnew=new DataTable();
//Convert all the rows to columns
for (int i = 0; i <= dt.Rows.Count; i++)
{
dtnew.Columns.Add(Convert.ToString(i));
}
DataRow dr;
// Convert All the Columns to Rows
for (int j = 0; j < dt.Columns.Count; j++)
{
dr = dtnew.NewRow();
dr[0] = dt.Columns[j].ToString();
for (int k = 1; k <= dt.Rows.Count; k++)
dr[k] = dt.Rows[k – 1][j];
dtnew.Rows.Add(dr);
}
return dtnew;
}

Use Of PagedDataSource Class


Hello Friends Today I wil share with you new Experience which i did in my company that’s Use of Paged Data Source Class.
It’s Really a cool class and give us smart of to paging.
With Just A Smart Coding.

for This You will have to no need to take tension of Cursors ,Difficult logic’s
Simply Make a new Web Site
and
Do Following Steps of Coding as Given below.
Step 1:Make Presentation view of your page as below given
make a new web forma and place on page
1)DropDownlist(with soem entries)
2) DataList 1(with a link button in itemtemplate)
3) DataList 2(with some bind records using eval)
4) Two Link Button (previous and next)

<p>

<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Default.aspx.cs” Inherits=”_Default” %>
<!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 runat=”server”>
<title></title>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<table>
<tr>
<td>
<asp:DropDownList ID=”ddlselect” runat=”server” AutoPostBack=”True”
onselectedindexchanged=”ddlselect_SelectedIndexChanged”>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
<asp:ListItem>6</asp:ListItem>
</asp:DropDownList>
<asp:LinkButton ID=”LinkButton1″ Text=”Previous” runat=”server”
onclick=”LinkButton1_Click”></asp:LinkButton>
<asp:DataList ID=”DataList2″ runat=”server” RepeatDirection=”Horizontal”
onitemcommand=”DataList2_ItemCommand”
onitemdatabound=”DataList2_ItemDataBound”
onselectedindexchanged=”DataList2_SelectedIndexChanged”>
<ItemTemplate>
<asp:LinkButton ID=”lnkbtnPaging” runat=”server” CommandArgument='<%# Eval(“PageIndex”) %>’
CommandName=”lnkbtnPaging” Text='<%# Eval(“PageText”) %>’></asp:LinkButton>
</ItemTemplate>
</asp:DataList><br />
<asp:LinkButton ID=”lnkNext”  Text=”Next” runat=”server”
onclick=”lnkNext_Click”></asp:LinkButton>
</td>
</tr>
</table>
<asp:DataList ID=”DataList1″ runat=”server”>
<ItemTemplate>
<asp:Label ID=”Label1″ runat=”server” Text='<%# Eval(“BookId”) %>’></asp:Label>
<asp:Label ID=”Label2″ runat=”server” Text='<%# Eval(“BookName”) %>’></asp:Label>
</ItemTemplate>
</asp:DataList>
</div>
</form>
</body>
</html>
</p>

Step 2: Now Do coding As Given Below.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data.SqlClient;
using System.Data;
using System.Configuration;
public partial class _Default : System.Web.UI.Page
{

PagedDataSource pds = new PagedDataSource();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGrid();
}
}
private void BindGrid()
{
string sql = “Select * from TbBook Order By BookId”;
SqlDataAdapter da = new SqlDataAdapter(sql, ConfigurationManager.ConnectionStrings[“Or”].ConnectionString);
DataTable dt = new DataTable();
da.Fill(dt);
pds.DataSource = dt.DefaultView;
pds.AllowPaging = true;
pds.PageSize = Convert.ToInt16(ddlselect.SelectedValue);
pds.CurrentPageIndex = CurrentPage;
lnkNext.Enabled = !pds.IsLastPage;
LinkButton1.Enabled = !pds.IsFirstPage;
DataList1.DataSource = pds;
DataList1.DataBind();
doPaging();
}
public int CurrentPage
{

get
{
if (this.ViewState[“CurrentPage”] == null)
return 0;
else
return Convert.ToInt32(this.ViewState[“CurrentPage”].ToString());
}
set
{
this.ViewState[“CurrentPage”] = value;
}

}

private void doPaging()
{
DataTable dt = new DataTable();
dt.Columns.Add(“PageIndex”);
dt.Columns.Add(“PageText”);
for (int i = 0; i < pds.PageCount; i++)
{
DataRow dr = dt.NewRow();
dr[0] = i;
dr[1] = i + 1;
dt.Rows.Add(dr);
}
DataList2.DataSource = dt;
DataList2.DataBind();
}

protected void DataList2_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName.Equals(“lnkbtnPaging”))
{
CurrentPage = Convert.ToInt16(e.CommandArgument.ToString());
BindGrid();
}
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
CurrentPage -= 1;
BindGrid();
}
protected void lnkNext_Click(object sender, EventArgs e)
{
CurrentPage += 1;
BindGrid();
}
protected void DataList2_SelectedIndexChanged(object sender, EventArgs e)
{

}
protected void ddlselect_SelectedIndexChanged(object sender, EventArgs e)
{
CurrentPage = 0;
BindGrid();
}
protected void DataList2_ItemDataBound(object sender, DataListItemEventArgs e)
{
LinkButton lnkbtnPage = (LinkButton)e.Item.FindControl(“lnkbtnPaging”);
if (lnkbtnPage.CommandArgument.ToString() == CurrentPage.ToString())
{
lnkbtnPage.Enabled = false;
lnkbtnPage.Font.Bold = true;
}
}
}

Note :Never Forget to make table of tbbook with columns and fill dummy entries int that.
Then Press F5 and Run your web site see the handsome paging of your site.
enjoy and do programming.

File Upload Control With Regular Expression Validation Control In asp.net 4.0 With Ajax


Aryan Verma

https://orientprogrammer.wordpress.com
Step 1: Make A New Web Site Using IDE 4.0 (Visual Studio 2010)
and after clicking on new web site you will get interface look as below given.


Step 2: Now place given control in code or can write to these.

.style1
{
color: #FF9900;
}

File Upload Control With Regular Expression Validator And Validations On Image Uploading
Upload Gravatar

Now Run and Enjoy In This .net World