Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

Data not refreshed in the Datagrid with paging

  Asked By: Marty    Date: Dec 28    Category: Asp.net    Views: 5693
  

I have been implementing a datagrid which would allow editing and deletion
of records from the grid and supports paging. I have implemented the grid
but am facing very peculiar problem. On the first page I see only 1 as the
page button whereas my PageButtonCount = 5. On clicking the edit link
button, the rest of the page button (1,2,3,4,5) appears. Further on clicking
the page buttons its the same old data that appears. Please help and I am
also pasting the code below.


using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using produits_new;
using System.Data.SqlClient;



namespace produits_new.other_info
{
/// <summary>
/// Summary description for Categories.
/// </summary>
//

public class Categories : System.Web.UI.Page
{
protected System.Web.UI.WebControls.HyperLink hlHome;
protected System.Web.UI.WebControls.Button btnNew;

protected System.Web.UI.WebControls.CheckBox chkVisible;

protected System.Web.UI.WebControls.Label lblListCat;
protected System.Web.UI.WebControls.Label lblNewTemplate;
protected System.Web.UI.WebControls.Label lblNewColor;
protected System.Web.UI.WebControls.Label lblNewCategorie;
protected System.Web.UI.WebControls.Label lblNewCat;

protected System.Web.UI.WebControls.TextBox txtCategorie;
protected System.Web.UI.WebControls.TextBox txtTemplate;
protected System.Web.UI.WebControls.TextBox txtColor;

protected System.Web.UI.WebControls.DataGrid dgCategorie;

private string strSQL;
private System.Text.StringBuilder strErrMsg = new
System.Text.StringBuilder();
private short icheck_status;

private SqlConnection Cat_Conn;
private SqlDataAdapter Cat_DA;
private DataSet Cat_DS;
private DataTable Cat_DT;


public Categories()
{
Cat_Conn = (new ProdConnec()).connectSqlDB();

}

private void Page_Load(object sender, System.EventArgs e)
{
if (this.Page.IsPostBack == false)
{
this.PopulateGrid();
dgCategorie.AllowPaging = true;
dgCategorie.PagerStyle.Mode =
PagerMode.NumericPages;
dgCategorie.PagerStyle.PageButtonCount = 5;
dgCategorie.PageSize = 10;
dgCategorie.VirtualItemCount = 50;
}
}

public void dgCategorie_PageIndexChanged(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
PopulateGrid();
}

private void PopulateGrid()
{
Cat_Conn.Open();
Cat_DS = new DataSet();

strSQL = "Select Cat_Nom, Coul_Cat, Tmpl_Cat " +
"From Categories";

Cat_DA = new SqlDataAdapter(strSQL, Cat_Conn);
Cat_DA.Fill(Cat_DS, "Categorie");

dgCategorie.DataSource =
Cat_DS.Tables["Categorie"].DefaultView;
dgCategorie.DataBind();
Cat_Conn.Close();
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web
Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnNew.Click += new
System.EventHandler(this.btnNew_Click);
this.chkVisible.CheckedChanged += new
System.EventHandler(this.chkVisible_CheckedChanged);
this.dgCategorie.PageIndexChanged += new
System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.dgCategorie_P
ageIndexChanged);
this.dgCategorie.CancelCommand += new
System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgCategorie_Cance
lCommand);
this.dgCategorie.EditCommand += new
System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgCategorie_EditC
ommand);
this.dgCategorie.DeleteCommand += new
System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgCategorie_Delet
eCommand);
this.dgCategorie.SelectedIndexChanged += new
System.EventHandler(this.dgCategorie_SelectedIndexChanged);
this.Load += new
System.EventHandler(this.Page_Load);

}
#endregion

private void btnNew_Click(object sender, System.EventArgs e)
{
try
{
strSQL = "Insert into Categories (Cat_Nom,
Coul_Cat, " +
"Tmpl_Cat, Show_Cat, Version_Cat)
values ('" +
txtCategorie.Text + "', '" +
txtColor.Text + "', '" +
txtTemplate.Text + "', '" +
icheck_status.ToString() + "', '1')";
// hv 2 put version of category by replacing
1

Cat_Conn.Open();
SqlCommand selCmd = new SqlCommand(strSQL,
Cat_Conn);
selCmd.ExecuteNonQuery();
Cat_Conn.Close();

txtCategorie.Text = "";
txtColor.Text = "";
txtTemplate.Text = "";
chkVisible.Checked = false;
}

catch(Exception Err)
{
strErrMsg.Append("<script
language=javascript>");
strErrMsg.Append(Err.ToString());
strErrMsg.Append("</script>");



if((IsStartupScriptRegistered("Error_Message")) == false)

RegisterStartupScript("Error_Message", strErrMsg.ToString());

//ShowInfo("Error while Saving " +
ed.ToString(), "Error");
}
}

private void chkVisible_CheckedChanged(object sender,
System.EventArgs e)
{
if(chkVisible.Checked)
icheck_status = 1;
else
icheck_status = 0;
}

private void dgCategorie_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{

}

private void dgCategorie_CancelCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{

}

private void dgCategorie_DeleteCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{

}

private void dgCategorie_EditCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{

}

private void dgCategorie_SelectedIndexChanged(object sender,
System.EventArgs e)
{

}
}
}

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on Data not refreshed in the Datagrid with paging Or get search suggestion and latest updates.




Tagged: