How to use DetailsView control in asp.net?
Thursday, October 4th, 20071. select Details View control and drag in your page.
2. Right Click ->select properties.
3. set Allow paging is true.
4. Write following Code in your code behind file.
public partial class tryexamples1 : System.Web.UI.Page
{
OleDbConnection cn;
OleDbDataAdapter ada;
OleDbDataReader dr;
protected void Page_Load(object sender, EventArgs e)
{
//database connection
if (!IsPostBack)
{
bind();
}
}
private DataTable gettable()
{
cn = new OleDbConnection(”Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:/Inetpub/wwwroot/mahesh/userinfo.mdb”);
cn.Open();
ada = new OleDbDataAdapter(”select * from logintable”,cn);
DataTable dt=new DataTable();
ada.Fill(dt);
return dt;
}
private void bind()
{
DataTable dt = gettable();
DetailsView1.DataSource = dt;
DetailsView1.DataBind();
}
protected void DetailsView1_PageIndexChanging(object sender, DetailsViewPageEventArgs e)
{
DetailsView1.PageIndex = e.NewPageIndex;
bind();
}
}