|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
DataGrid Pagin Problemmy 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(); } 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> Show quoteHide quote "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.DataGridPageChangedEventArgs e) > { > DataGrid1.CurrentPageIndex = e.NewPageIndex; > MyDataGridBind(); > }
Other interesting topics
TreeView problem
Deploying ASP.NET 2.0 how to parse deeper nested tags in custom control Forms authentication with images on the login page ## in ASP.NET 2.0 How and when should I use CacheItemPriority.NotRemovable? Strange Behavior ASPnet_Wp.exe Rols/rights in asp 2.0 Open and read/write ASPX file Tabel cells |
|||||||||||||||||||||||