473,385 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

DataGrid Pagin Problem

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.DataGridPageChangedEvent Args e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
MyDataGridBind();
}
Nov 26 '05 #1
1 1071
When you add the columns dynamically during the data bind (as you did below)
then you should redo the data binding upon each post back, i.e. if you remove
the condition: if (!IsPostBack) your code will work.

Otherwise, if you know before hand the number of columns to add to the grid
you can use the declarative syntaxand then your code would work just as good:

<Columns>
<asp:BoundColumn HeaderText="Fiyat" DataField="Country" ></asp:BoundColumn>
<asp:BoundColumn HeaderText="Rate" DataField="Rate" ></asp:BoundColumn>
</Columns>
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"alexmaster_2004" wrote:
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.DataGridPageChangedEvent Args e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
MyDataGridBind();
}

Nov 26 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jeff | last post by:
IDE: VS 2003 :NET OS: XP Pro My app have a form with a tab-control on it. The tab-control have 2 tabpages. One of the tabpages displays a datagrid, and the other tabpage displays details (order...
1
by: Rick | last post by:
Hello all, I hope all is well with you. I am having a seriously difficult time with this problem. Allow me to set up the problem. I have a System.Web.UI.Page with the following controls...
0
by: alexmaster_2004 | last post by:
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...
0
by: Jyothihathwar | last post by:
Hi Friends, I am displaying data using Datagrid and i have set properties as Allow Pagin = "True" and PageSize as 10.So for ex if there are records then first 10 records will be displayed first...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.