Hello,
I'm learning to code in C# and I created a DataGrid component, which I
couldn't get it to work properly either using "Next >>" and "<< Previous"
buttons or using actual page numbers.
When I use the "Next" and "Previous" buttons, I move on one page (going from
page 1 to 2). Then if I click next on page 2, it comes back to page 2. I
checked my code several times and I can't find anything wrong with it. If I
click on Previous, it comes back to page 1.
When I use the actual page numbers, on the very first time the applications
shows all possible page numbers possible (1 to 10 maybe). Then if I click on
page 2, it refreshes and shows the correct number of pages (4) and only
links 1 to 4 are displayed. Now, I can access any page I want and the
application displays it properly, the problem is on the first time it
displays the data.
Basically, it's a page when 2 TextBoxes and one Button. When the user clicks
on this button, the application adds data to a database and displays all
rows.
I'm not using Page_Load for that, let me know if I'm wrong. I'm just using
the Button_Click event:
private void Button1_Click(object sender, System.EventArgs e)
{
try
{
oleDbConnection1.Open();
if (name.Text.Trim().Length>0 &&
msg.Text.Trim().Length>0)
{
oleDbDataAdapter1.InsertCommand.CommandText =
"INSERT INTO [msg log] "+
"(hour, name, msg) "+
"VALUES ("+
"'"+DateTime.Now.ToString()+"', "+
"'"+name.Text.Trim()+"', "+
"'"+msg.Text.Trim()+"')";
oleDbDataAdapter1.InsertCommand.ExecuteNonQuery();
name.Text = "";
msg.Text = "";
}
oleDbDataAdapter1.SelectCommand.CommandText =
"SELECT hora, nome, msg FROM [msg log]";
oleDbDataAdapter1.Fill(dataset11);
oleDbConnection1.Close();
DataGrid1.DataBind();
}
catch (System.Data.OleDb.OleDbException exception)
{
Error.Visible = true;
Error.Text = "Error on server: " + exception.ToString();
}
}
And here is my PageIndexChanged Event:
private void DataGrid1_PageIndexChanged(object source,
System.Web.UI.WebControls.DataGridPageChangedEvent Args e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
DataGrid1.DataBind();
}
Please, let me know if there is something very wrong with it.
Thanks.
Ruy. 6 1671
> private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEvent Args e) { DataGrid1.CurrentPageIndex = e.NewPageIndex; DataGrid1.DataBind(); }
Where is your DataSource??
--
Dave Sexton dave@www..jwaonline..com
-----------------------------------------------------------------------
"Ruy Castelli" <an****@newsgroup.com> wrote in message news:Oq**************@TK2MSFTNGP12.phx.gbl... Hello,
I'm learning to code in C# and I created a DataGrid component, which I couldn't get it to work properly either using "Next >>" and "<< Previous" buttons or using actual page numbers.
When I use the "Next" and "Previous" buttons, I move on one page (going from page 1 to 2). Then if I click next on page 2, it comes back to page 2. I checked my code several times and I can't find anything wrong with it. If I click on Previous, it comes back to page 1.
When I use the actual page numbers, on the very first time the applications shows all possible page numbers possible (1 to 10 maybe). Then if I click on page 2, it refreshes and shows the correct number of pages (4) and only links 1 to 4 are displayed. Now, I can access any page I want and the application displays it properly, the problem is on the first time it displays the data.
Basically, it's a page when 2 TextBoxes and one Button. When the user clicks on this button, the application adds data to a database and displays all rows.
I'm not using Page_Load for that, let me know if I'm wrong. I'm just using the Button_Click event:
private void Button1_Click(object sender, System.EventArgs e) { try { oleDbConnection1.Open(); if (name.Text.Trim().Length>0 && msg.Text.Trim().Length>0) { oleDbDataAdapter1.InsertCommand.CommandText = "INSERT INTO [msg log] "+ "(hour, name, msg) "+ "VALUES ("+ "'"+DateTime.Now.ToString()+"', "+ "'"+name.Text.Trim()+"', "+ "'"+msg.Text.Trim()+"')"; oleDbDataAdapter1.InsertCommand.ExecuteNonQuery(); name.Text = ""; msg.Text = ""; } oleDbDataAdapter1.SelectCommand.CommandText = "SELECT hora, nome, msg FROM [msg log]"; oleDbDataAdapter1.Fill(dataset11); oleDbConnection1.Close(); DataGrid1.DataBind(); } catch (System.Data.OleDb.OleDbException exception) { Error.Visible = true; Error.Text = "Error on server: " + exception.ToString(); } }
And here is my PageIndexChanged Event:
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEvent Args e) { DataGrid1.CurrentPageIndex = e.NewPageIndex; DataGrid1.DataBind(); }
Please, let me know if there is something very wrong with it.
Thanks. Ruy.
Hello Dave, thanks for your answer.
Now, I'm binding data on the Page_Loads and PageIndexChange events, but the
problem is worse, when I click on Next, the datagrid disapears.
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (!PostBack)
{
try
{
oleDbConnection1.Open();
oleDbDataAdapter1.SelectCommand.CommandText =
"SELECT hour, name, msg FROM [msg log]";
oleDbDataAdapter1.Fill(dataset11);
DataGrid1.DataBind();
}
catch (System.Data.OleDb.OleDbException exception)
{
Error.Visible = true;
Error.Text = "Server error: " + exception.ToString();
}
finally
{
oleDbConnection1.Close();
}
}
}
Here is my PageIndexChanged event:
private void DataGrid1_PageIndexChanged(
object source,
System.Web.UI.WebControls.DataGridPageChangedEvent Args e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
try
{
oleDbConnection1.Open();
oleDbDataAdapter1.SelectCommand.CommandText =
"SELECT hour, name, msg FROM [msg log]";
oleDbDataAdapter1.Fill(dataset11);
DataGrid1.DataBind();
}
catch (System.Data.OleDb.OleDbException exception)
{
Error.Visible = true;
Error.Text = "Server error: " + exception.ToString();
}
finally
{
oleDbConnection1.Close();
}
DataGrid1.DataBind();
}
"Dave" <NO*********@dotcomdatasolutions.com> escreveu na mensagem
news:%2***************@TK2MSFTNGP15.phx.gbl... private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEvent Args e) { DataGrid1.CurrentPageIndex = e.NewPageIndex; DataGrid1.DataBind(); }
Where is your DataSource??
-- Dave Sexton dave@www..jwaonline..com ----------------------------------------------------------------------- "Ruy Castelli" <an****@newsgroup.com> wrote in message news:Oq**************@TK2MSFTNGP12.phx.gbl... Hello,
I'm learning to code in C# and I created a DataGrid component, which I couldn't get it to work properly either using "Next >>" and "<< Previous" buttons or using actual page numbers.
When I use the "Next" and "Previous" buttons, I move on one page (going from page 1 to 2). Then if I click next on page 2, it comes back to page 2. I checked my code several times and I can't find anything wrong with it. If I click on Previous, it comes back to page 1.
When I use the actual page numbers, on the very first time the applications shows all possible page numbers possible (1 to 10 maybe). Then if I click on page 2, it refreshes and shows the correct number of pages (4) and only links 1 to 4 are displayed. Now, I can access any page I want and the application displays it properly, the problem is on the first time it displays the data.
Basically, it's a page when 2 TextBoxes and one Button. When the user clicks on this button, the application adds data to a database and displays all rows.
I'm not using Page_Load for that, let me know if I'm wrong. I'm just using the Button_Click event:
private void Button1_Click(object sender, System.EventArgs e) { try { oleDbConnection1.Open(); if (name.Text.Trim().Length>0 && msg.Text.Trim().Length>0) { oleDbDataAdapter1.InsertCommand.CommandText = "INSERT INTO [msg log] "+ "(hour, name, msg) "+ "VALUES ("+ "'"+DateTime.Now.ToString()+"', "+ "'"+name.Text.Trim()+"', "+ "'"+msg.Text.Trim()+"')"; oleDbDataAdapter1.InsertCommand.ExecuteNonQuery(); name.Text = ""; msg.Text = ""; } oleDbDataAdapter1.SelectCommand.CommandText = "SELECT hora, nome, msg FROM [msg log]"; oleDbDataAdapter1.Fill(dataset11); oleDbConnection1.Close(); DataGrid1.DataBind(); } catch (System.Data.OleDb.OleDbException exception) { Error.Visible = true; Error.Text = "Error on server: " + exception.ToString(); } }
And here is my PageIndexChanged Event:
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEvent Args e) { DataGrid1.CurrentPageIndex = e.NewPageIndex; DataGrid1.DataBind(); }
Please, let me know if there is something very wrong with it.
Thanks. Ruy.
Only bind onload if it's not a postback:
if (!IsPostBack)
{
// Todo: bind the grid
}
else
{
// we don't rebind here because the datagrid will "remember" it's contents upon postbacks using the ViewState.
// This is why the ViewState can be quite large on pages that contain datagrid controls filled with data.
}
--
Dave Sexton dave@www..jwaonline..com
-----------------------------------------------------------------------
"Ruy Castelli" <an****@newsgroup.com> wrote in message news:es**************@TK2MSFTNGP09.phx.gbl... Hello Dave, thanks for your answer.
Now, I'm binding data on the Page_Loads and PageIndexChange events, but the problem is worse, when I click on Next, the datagrid disapears.
private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here if (!PostBack) { try { oleDbConnection1.Open();
oleDbDataAdapter1.SelectCommand.CommandText = "SELECT hour, name, msg FROM [msg log]";
oleDbDataAdapter1.Fill(dataset11); DataGrid1.DataBind(); } catch (System.Data.OleDb.OleDbException exception) { Error.Visible = true; Error.Text = "Server error: " + exception.ToString(); } finally { oleDbConnection1.Close(); } } }
Here is my PageIndexChanged event:
private void DataGrid1_PageIndexChanged( object source, System.Web.UI.WebControls.DataGridPageChangedEvent Args e) { DataGrid1.CurrentPageIndex = e.NewPageIndex;
try { oleDbConnection1.Open();
oleDbDataAdapter1.SelectCommand.CommandText = "SELECT hour, name, msg FROM [msg log]";
oleDbDataAdapter1.Fill(dataset11); DataGrid1.DataBind(); } catch (System.Data.OleDb.OleDbException exception) { Error.Visible = true; Error.Text = "Server error: " + exception.ToString(); } finally { oleDbConnection1.Close(); }
DataGrid1.DataBind(); }
"Dave" <NO*********@dotcomdatasolutions.com> escreveu na mensagem news:%2***************@TK2MSFTNGP15.phx.gbl... private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEvent Args e) { DataGrid1.CurrentPageIndex = e.NewPageIndex; DataGrid1.DataBind(); }
Where is your DataSource??
-- Dave Sexton dave@www..jwaonline..com ----------------------------------------------------------------------- "Ruy Castelli" <an****@newsgroup.com> wrote in message news:Oq**************@TK2MSFTNGP12.phx.gbl... Hello,
I'm learning to code in C# and I created a DataGrid component, which I couldn't get it to work properly either using "Next >>" and "<< Previous" buttons or using actual page numbers.
When I use the "Next" and "Previous" buttons, I move on one page (going from page 1 to 2). Then if I click next on page 2, it comes back to page 2. I checked my code several times and I can't find anything wrong with it. If I click on Previous, it comes back to page 1.
When I use the actual page numbers, on the very first time the applications shows all possible page numbers possible (1 to 10 maybe). Then if I click on page 2, it refreshes and shows the correct number of pages (4) and only links 1 to 4 are displayed. Now, I can access any page I want and the application displays it properly, the problem is on the first time it displays the data.
Basically, it's a page when 2 TextBoxes and one Button. When the user clicks on this button, the application adds data to a database and displays all rows.
I'm not using Page_Load for that, let me know if I'm wrong. I'm just using the Button_Click event:
private void Button1_Click(object sender, System.EventArgs e) { try { oleDbConnection1.Open(); if (name.Text.Trim().Length>0 && msg.Text.Trim().Length>0) { oleDbDataAdapter1.InsertCommand.CommandText = "INSERT INTO [msg log] "+ "(hour, name, msg) "+ "VALUES ("+ "'"+DateTime.Now.ToString()+"', "+ "'"+name.Text.Trim()+"', "+ "'"+msg.Text.Trim()+"')"; oleDbDataAdapter1.InsertCommand.ExecuteNonQuery(); name.Text = ""; msg.Text = ""; } oleDbDataAdapter1.SelectCommand.CommandText = "SELECT hora, nome, msg FROM [msg log]"; oleDbDataAdapter1.Fill(dataset11); oleDbConnection1.Close(); DataGrid1.DataBind(); } catch (System.Data.OleDb.OleDbException exception) { Error.Visible = true; Error.Text = "Error on server: " + exception.ToString(); } }
And here is my PageIndexChanged Event:
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEvent Args e) { DataGrid1.CurrentPageIndex = e.NewPageIndex; DataGrid1.DataBind(); }
Please, let me know if there is something very wrong with it.
Thanks. Ruy.
I noticed that your are binding twice in the DataGrid1_PageIndexChanged event handler. Remove the last line and it should work
fine.
My last post was submitted because I searched for IsPostBack, and didn't find it... I assume this is a type-o? if (!PostBack)
Should be:
if (!IsPostBack)
--
Dave Sexton dave@www..jwaonline..com
-----------------------------------------------------------------------
"Ruy Castelli" <an****@newsgroup.com> wrote in message news:es**************@TK2MSFTNGP09.phx.gbl... Hello Dave, thanks for your answer.
Now, I'm binding data on the Page_Loads and PageIndexChange events, but the problem is worse, when I click on Next, the datagrid disapears.
private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here if (!PostBack) { try { oleDbConnection1.Open();
oleDbDataAdapter1.SelectCommand.CommandText = "SELECT hour, name, msg FROM [msg log]";
oleDbDataAdapter1.Fill(dataset11); DataGrid1.DataBind(); } catch (System.Data.OleDb.OleDbException exception) { Error.Visible = true; Error.Text = "Server error: " + exception.ToString(); } finally { oleDbConnection1.Close(); } } }
Here is my PageIndexChanged event:
private void DataGrid1_PageIndexChanged( object source, System.Web.UI.WebControls.DataGridPageChangedEvent Args e) { DataGrid1.CurrentPageIndex = e.NewPageIndex;
try { oleDbConnection1.Open();
oleDbDataAdapter1.SelectCommand.CommandText = "SELECT hour, name, msg FROM [msg log]";
oleDbDataAdapter1.Fill(dataset11); DataGrid1.DataBind(); } catch (System.Data.OleDb.OleDbException exception) { Error.Visible = true; Error.Text = "Server error: " + exception.ToString(); } finally { oleDbConnection1.Close(); }
DataGrid1.DataBind(); }
"Dave" <NO*********@dotcomdatasolutions.com> escreveu na mensagem news:%2***************@TK2MSFTNGP15.phx.gbl... private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEvent Args e) { DataGrid1.CurrentPageIndex = e.NewPageIndex; DataGrid1.DataBind(); }
Where is your DataSource??
-- Dave Sexton dave@www..jwaonline..com ----------------------------------------------------------------------- "Ruy Castelli" <an****@newsgroup.com> wrote in message news:Oq**************@TK2MSFTNGP12.phx.gbl... Hello,
I'm learning to code in C# and I created a DataGrid component, which I couldn't get it to work properly either using "Next >>" and "<< Previous" buttons or using actual page numbers.
When I use the "Next" and "Previous" buttons, I move on one page (going from page 1 to 2). Then if I click next on page 2, it comes back to page 2. I checked my code several times and I can't find anything wrong with it. If I click on Previous, it comes back to page 1.
When I use the actual page numbers, on the very first time the applications shows all possible page numbers possible (1 to 10 maybe). Then if I click on page 2, it refreshes and shows the correct number of pages (4) and only links 1 to 4 are displayed. Now, I can access any page I want and the application displays it properly, the problem is on the first time it displays the data.
Basically, it's a page when 2 TextBoxes and one Button. When the user clicks on this button, the application adds data to a database and displays all rows.
I'm not using Page_Load for that, let me know if I'm wrong. I'm just using the Button_Click event:
private void Button1_Click(object sender, System.EventArgs e) { try { oleDbConnection1.Open(); if (name.Text.Trim().Length>0 && msg.Text.Trim().Length>0) { oleDbDataAdapter1.InsertCommand.CommandText = "INSERT INTO [msg log] "+ "(hour, name, msg) "+ "VALUES ("+ "'"+DateTime.Now.ToString()+"', "+ "'"+name.Text.Trim()+"', "+ "'"+msg.Text.Trim()+"')"; oleDbDataAdapter1.InsertCommand.ExecuteNonQuery(); name.Text = ""; msg.Text = ""; } oleDbDataAdapter1.SelectCommand.CommandText = "SELECT hora, nome, msg FROM [msg log]"; oleDbDataAdapter1.Fill(dataset11); oleDbConnection1.Close(); DataGrid1.DataBind(); } catch (System.Data.OleDb.OleDbException exception) { Error.Visible = true; Error.Text = "Error on server: " + exception.ToString(); } }
And here is my PageIndexChanged Event:
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEvent Args e) { DataGrid1.CurrentPageIndex = e.NewPageIndex; DataGrid1.DataBind(); }
Please, let me know if there is something very wrong with it.
Thanks. Ruy.
Thanks Dave,
I followed your tips, but it still didn't work. Then I was checking some
configuration and I noticed that somehow the document properties
"enableSessionState" and "enableViewState" were set to false. When I set
then to true, everything worked.
Thanks.
Ruy.
"Dave" <NO*********@dotcomdatasolutions.com> escreveu na mensagem
news:eP**************@TK2MSFTNGP10.phx.gbl... I noticed that your are binding twice in the DataGrid1_PageIndexChanged event handler. Remove the last line and it should work fine.
My last post was submitted because I searched for IsPostBack, and didn't find it... I assume this is a type-o?
if (!PostBack)
Should be:
if (!IsPostBack)
-- Dave Sexton dave@www..jwaonline..com ----------------------------------------------------------------------- "Ruy Castelli" <an****@newsgroup.com> wrote in message news:es**************@TK2MSFTNGP09.phx.gbl... Hello Dave, thanks for your answer.
Now, I'm binding data on the Page_Loads and PageIndexChange events, but the problem is worse, when I click on Next, the datagrid disapears.
private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here if (!PostBack) { try { oleDbConnection1.Open();
oleDbDataAdapter1.SelectCommand.CommandText = "SELECT hour, name, msg FROM [msg log]";
oleDbDataAdapter1.Fill(dataset11); DataGrid1.DataBind(); } catch (System.Data.OleDb.OleDbException exception) { Error.Visible = true; Error.Text = "Server error: " + exception.ToString(); } finally { oleDbConnection1.Close(); } } }
Here is my PageIndexChanged event:
private void DataGrid1_PageIndexChanged( object source, System.Web.UI.WebControls.DataGridPageChangedEvent Args e) { DataGrid1.CurrentPageIndex = e.NewPageIndex;
try { oleDbConnection1.Open();
oleDbDataAdapter1.SelectCommand.CommandText = "SELECT hour, name, msg FROM [msg log]";
oleDbDataAdapter1.Fill(dataset11); DataGrid1.DataBind(); } catch (System.Data.OleDb.OleDbException exception) { Error.Visible = true; Error.Text = "Server error: " + exception.ToString(); } finally { oleDbConnection1.Close(); }
DataGrid1.DataBind(); }
"Dave" <NO*********@dotcomdatasolutions.com> escreveu na mensagem news:%2***************@TK2MSFTNGP15.phx.gbl... private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEvent Args e) { DataGrid1.CurrentPageIndex = e.NewPageIndex; DataGrid1.DataBind(); }
Where is your DataSource??
-- Dave Sexton dave@www..jwaonline..com ----------------------------------------------------------------------- "Ruy Castelli" <an****@newsgroup.com> wrote in message news:Oq**************@TK2MSFTNGP12.phx.gbl... Hello,
I'm learning to code in C# and I created a DataGrid component, which I couldn't get it to work properly either using "Next >>" and "<< Previous" buttons or using actual page numbers.
When I use the "Next" and "Previous" buttons, I move on one page (going from page 1 to 2). Then if I click next on page 2, it comes back to page 2. I checked my code several times and I can't find anything wrong with it. If I click on Previous, it comes back to page 1.
When I use the actual page numbers, on the very first time the applications shows all possible page numbers possible (1 to 10 maybe). Then if I click on page 2, it refreshes and shows the correct number of pages (4) and only links 1 to 4 are displayed. Now, I can access any page I want and the application displays it properly, the problem is on the first time it displays the data.
Basically, it's a page when 2 TextBoxes and one Button. When the user clicks on this button, the application adds data to a database and displays all rows.
I'm not using Page_Load for that, let me know if I'm wrong. I'm just using the Button_Click event:
private void Button1_Click(object sender, System.EventArgs e) { try { oleDbConnection1.Open(); if (name.Text.Trim().Length>0 && msg.Text.Trim().Length>0) { oleDbDataAdapter1.InsertCommand.CommandText = "INSERT INTO [msg log] "+ "(hour, name, msg) "+ "VALUES ("+ "'"+DateTime.Now.ToString()+"', "+ "'"+name.Text.Trim()+"', "+ "'"+msg.Text.Trim()+"')"; oleDbDataAdapter1.InsertCommand.ExecuteNonQuery(); name.Text = ""; msg.Text = ""; } oleDbDataAdapter1.SelectCommand.CommandText = "SELECT hora, nome, msg FROM [msg log]"; oleDbDataAdapter1.Fill(dataset11); oleDbConnection1.Close(); DataGrid1.DataBind(); } catch (System.Data.OleDb.OleDbException exception) { Error.Visible = true; Error.Text = "Error on server: " + exception.ToString(); } }
And here is my PageIndexChanged Event:
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEvent Args e) { DataGrid1.CurrentPageIndex = e.NewPageIndex; DataGrid1.DataBind(); }
Please, let me know if there is something very wrong with it.
Thanks. Ruy.
Yep, that'll do it to!
Sorry I couldn't help.
--
Dave Sexton dave@www..jwaonline..com
-----------------------------------------------------------------------
"Ruy Castelli" <an****@newsgroup.com> wrote in message news:eG**************@TK2MSFTNGP15.phx.gbl... Thanks Dave,
I followed your tips, but it still didn't work. Then I was checking some configuration and I noticed that somehow the document properties "enableSessionState" and "enableViewState" were set to false. When I set then to true, everything worked.
Thanks. Ruy.
"Dave" <NO*********@dotcomdatasolutions.com> escreveu na mensagem news:eP**************@TK2MSFTNGP10.phx.gbl...I noticed that your are binding twice in the DataGrid1_PageIndexChanged event handler. Remove the last line and it should work fine.
My last post was submitted because I searched for IsPostBack, and didn't find it... I assume this is a type-o?
if (!PostBack)
Should be:
if (!IsPostBack)
-- Dave Sexton dave@www..jwaonline..com ----------------------------------------------------------------------- "Ruy Castelli" <an****@newsgroup.com> wrote in message news:es**************@TK2MSFTNGP09.phx.gbl... Hello Dave, thanks for your answer.
Now, I'm binding data on the Page_Loads and PageIndexChange events, but the problem is worse, when I click on Next, the datagrid disapears.
private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here if (!PostBack) { try { oleDbConnection1.Open();
oleDbDataAdapter1.SelectCommand.CommandText = "SELECT hour, name, msg FROM [msg log]";
oleDbDataAdapter1.Fill(dataset11); DataGrid1.DataBind(); } catch (System.Data.OleDb.OleDbException exception) { Error.Visible = true; Error.Text = "Server error: " + exception.ToString(); } finally { oleDbConnection1.Close(); } } }
Here is my PageIndexChanged event:
private void DataGrid1_PageIndexChanged( object source, System.Web.UI.WebControls.DataGridPageChangedEvent Args e) { DataGrid1.CurrentPageIndex = e.NewPageIndex;
try { oleDbConnection1.Open();
oleDbDataAdapter1.SelectCommand.CommandText = "SELECT hour, name, msg FROM [msg log]";
oleDbDataAdapter1.Fill(dataset11); DataGrid1.DataBind(); } catch (System.Data.OleDb.OleDbException exception) { Error.Visible = true; Error.Text = "Server error: " + exception.ToString(); } finally { oleDbConnection1.Close(); }
DataGrid1.DataBind(); }
"Dave" <NO*********@dotcomdatasolutions.com> escreveu na mensagem news:%2***************@TK2MSFTNGP15.phx.gbl... > private void DataGrid1_PageIndexChanged(object source, > System.Web.UI.WebControls.DataGridPageChangedEvent Args e) >{ > DataGrid1.CurrentPageIndex = e.NewPageIndex; > DataGrid1.DataBind(); > }
Where is your DataSource??
-- Dave Sexton dave@www..jwaonline..com ----------------------------------------------------------------------- "Ruy Castelli" <an****@newsgroup.com> wrote in message news:Oq**************@TK2MSFTNGP12.phx.gbl... > Hello, > > I'm learning to code in C# and I created a DataGrid component, which I couldn't get it to work properly either using "Next >>" > and "<< Previous" buttons or using actual page numbers. > > When I use the "Next" and "Previous" buttons, I move on one page (going from page 1 to 2). Then if I click next on page 2, it > comes back to page 2. I checked my code several times and I can't find anything wrong with it. If I click on Previous, it > comes back to page 1. > > When I use the actual page numbers, on the very first time the applications shows all possible page numbers possible (1 to 10 > maybe). Then if I click on page 2, it refreshes and shows the correct number of pages (4) and only links 1 to 4 are displayed. > Now, I can access any page I want and the application displays it properly, the problem is on the first time it displays the > data. > > Basically, it's a page when 2 TextBoxes and one Button. When the user clicks on this button, the application adds data to a > database and displays all rows. > > I'm not using Page_Load for that, let me know if I'm wrong. I'm just using the Button_Click event: > > private void Button1_Click(object sender, System.EventArgs e) > { > try > { > oleDbConnection1.Open(); > if (name.Text.Trim().Length>0 && > msg.Text.Trim().Length>0) > { > oleDbDataAdapter1.InsertCommand.CommandText = > "INSERT INTO [msg log] "+ > "(hour, name, msg) "+ > "VALUES ("+ > "'"+DateTime.Now.ToString()+"', "+ > "'"+name.Text.Trim()+"', "+ > "'"+msg.Text.Trim()+"')"; > oleDbDataAdapter1.InsertCommand.ExecuteNonQuery(); > name.Text = ""; > msg.Text = ""; > } > oleDbDataAdapter1.SelectCommand.CommandText = > "SELECT hora, nome, msg FROM [msg log]"; > oleDbDataAdapter1.Fill(dataset11); > oleDbConnection1.Close(); > DataGrid1.DataBind(); > } > catch (System.Data.OleDb.OleDbException exception) > { > Error.Visible = true; > Error.Text = "Error on server: " + exception.ToString(); > } > } > > And here is my PageIndexChanged Event: > > private void DataGrid1_PageIndexChanged(object source, > System.Web.UI.WebControls.DataGridPageChangedEvent Args e) > { > DataGrid1.CurrentPageIndex = e.NewPageIndex; > DataGrid1.DataBind(); > } > > Please, let me know if there is something very wrong with it. > > Thanks. > Ruy. >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Coleen |
last post by:
Sorry about the multi-posting, but it does not seem as though the other
newsgroups are frequented enough to get any advice on this problem...If
anyone can possibly help, I would greatly appreciate...
|
by: Maziar Aflatoun |
last post by:
Hi,
I'm having problems with Custom Paging. Most of the articles out there show
that the custom paging is done as the following article.
...
|
by: Danny Ni |
last post by:
Hi,
We use ASP.Net datagrid paging a lot and we have been experiencing "Index
out of bound" error messages when we click on rows of datagrid on differnet
pages every now and then. The...
|
by: GD |
last post by:
Got a simple ASPX page (.NET v1.1) with a DataGrid displaying a list of
widgets. If the page has a QueryString called WidgetId specific, I need
to automatically mark the specific DataGridItem as...
|
by: Mrozik |
last post by:
Hi!
I'm looking for a solution to show data in a table.
I think about DataView control - but I see one problem.
My data source is a WebService returning paged pieces
of data (I can't change...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
| |