G
Guest
Hi there
my problem is with datagrid pagin.when i try to add the pagin feature to my
datagrid i get a strange behavior.
i will explain in details:
i wanted to allow pagin in the datagrid so i have put AllowPagin property =
true;
and then i have implemented the PageIndexChanged event handler.and made all
required changes to re-filling the datasource.in this case the pagin worked
fine.
but when i have put the AutoGenerateColumns property = false the pagin
didn't work.i don't know why this happened.i hopw that you can help me
Thanks
this is my current code:
////////////
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if(!IsPostBack)
{
MyDataGridBind();
}
}
//Start of the MyDataGridBind() Function//
void MyDataGridBind()
{
SqlConnection sqlcon = new SqlConnection();
SqlCommand sqlcom = new SqlCommand();
SqlDataAdapter sqlDA = new SqlDataAdapter();
DataSet dsRates = new DataSet();
sqlcon.ConnectionString =
ConfigurationSettings.AppSettings["connectionString"];
sqlcom.Connection = sqlcon;
sqlcom.CommandType = CommandType.Text;
sqlcom.CommandText = "SELECT * FROM rates";
sqlDA.SelectCommand = sqlcom;
sqlDA.Fill(dsRates);
DataGrid1.DataSource = dsRates;
BoundColumn bc2 = new BoundColumn();
BoundColumn bc3 = new BoundColumn();
ButtonColumn bc5 = new ButtonColumn();
bc2.DataField = "country";
bc2.HeaderText = "Fiyat";
DataGrid1.Columns.Add(bc2);
bc3.DataField = "rate";
bc3.HeaderText = "Bilgi";
DataGrid1.Columns.Add(bc3);
bc5.ButtonType = ButtonColumnType.LinkButton;
bc5.CommandName = "SendMail";
bc5.HeaderText = "BaÅŸvur";
bc5.Text = "Satın al";
DataGrid1.Columns.Add(bc5);
DataGrid1.DataBind();
}
//End of the MyDataGridBind() Function//
private void DataGrid1_PageIndexChanged(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
MyDataGridBind();
}
my problem is with datagrid pagin.when i try to add the pagin feature to my
datagrid i get a strange behavior.
i will explain in details:
i wanted to allow pagin in the datagrid so i have put AllowPagin property =
true;
and then i have implemented the PageIndexChanged event handler.and made all
required changes to re-filling the datasource.in this case the pagin worked
fine.
but when i have put the AutoGenerateColumns property = false the pagin
didn't work.i don't know why this happened.i hopw that you can help me
Thanks
this is my current code:
////////////
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if(!IsPostBack)
{
MyDataGridBind();
}
}
//Start of the MyDataGridBind() Function//
void MyDataGridBind()
{
SqlConnection sqlcon = new SqlConnection();
SqlCommand sqlcom = new SqlCommand();
SqlDataAdapter sqlDA = new SqlDataAdapter();
DataSet dsRates = new DataSet();
sqlcon.ConnectionString =
ConfigurationSettings.AppSettings["connectionString"];
sqlcom.Connection = sqlcon;
sqlcom.CommandType = CommandType.Text;
sqlcom.CommandText = "SELECT * FROM rates";
sqlDA.SelectCommand = sqlcom;
sqlDA.Fill(dsRates);
DataGrid1.DataSource = dsRates;
BoundColumn bc2 = new BoundColumn();
BoundColumn bc3 = new BoundColumn();
ButtonColumn bc5 = new ButtonColumn();
bc2.DataField = "country";
bc2.HeaderText = "Fiyat";
DataGrid1.Columns.Add(bc2);
bc3.DataField = "rate";
bc3.HeaderText = "Bilgi";
DataGrid1.Columns.Add(bc3);
bc5.ButtonType = ButtonColumnType.LinkButton;
bc5.CommandName = "SendMail";
bc5.HeaderText = "BaÅŸvur";
bc5.Text = "Satın al";
DataGrid1.Columns.Add(bc5);
DataGrid1.DataBind();
}
//End of the MyDataGridBind() Function//
private void DataGrid1_PageIndexChanged(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
MyDataGridBind();
}