using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Data.SqlClient; public partial class GridControll : System.Web.UI.UserControl { //public event EventHandler PageTitleUpdated; public delegate void RowDataBound(object sender, GridViewRowEventArgs e); public event RowDataBound GridRowDataBound; protected void Page_Load(object sender, EventArgs e) { BindGrid(); } public void BindGrid() { string strCon = System.Configuration.ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString; string strSql = "select CountryCode,CountryName,CountryLocale,Status from countrymaster"; SqlConnection con = new SqlConnection(strCon); con.Open(); SqlDataAdapter dadapter = new SqlDataAdapter(); dadapter.SelectCommand = new SqlCommand(strSql, con); DataSet dset = new DataSet(); dadapter.Fill(dset); con.Close(); this.GridView1.DataSource = dset; GridView1.DataBind(); } /// <summary> ///get grid columns collection /// </summary> public DataControlFieldCollection Columns { get { return GridView1.Columns; } } protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { OnRowDataBound(e); } protected void OnRowDataBound(GridViewRowEventArgs e) { if (GridRowDataBound != null) GridRowDataBound(this, e); } }
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <%@ Register TagPrefix="UG" TagName="GridControl" Src="~/GridControll.ascx" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <UG:GridControl ID="GridControl1" runat="server"></UG:GridControl> </div> </form> </body> </html>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)