Note that there are some explanatory texts on larger screens.

plurals
  1. PONext row from dataset button only performing function once
    primarykey
    data
    text
    <p>I asked a question yesterday about paging through a data set using next / previous buttons displaying a single row in a forms text boxes. Since then I've managed to get the next button to go to the next row but only once. every subsequent click does nothing. here's some code.</p> <p>The code that executes after the the user selects a search value and presses a value:</p> <pre><code> public static int inc = 0; protected void ExecuteSelectCopies(string sName) { SqlConnection connection = new SqlConnection(GetConnectionString()); try { string sql = "SELECT tblCopies.CopyID, tblSoftware.SoftwareName, tblCopies.AssetName, tblCopies.Location," + " tblCopies.LicenceKey, tblCopies.OEM, tblCopies.State, tblCopies.InstallationDate" + " FROM tblCopies" + " INNER JOIN tblSoftware ON tblCopies.SoftwareID = tblSoftware.SoftwareID" + " WHERE tblSoftware.SoftwareName = @SoftwareName" + " ORDER BY tblCopies.CopyID"; SqlDataAdapter adapterH = new SqlDataAdapter(); SqlCommand select = new SqlCommand(sql, connectionHWM); adapterH.SelectCommand = select; select.Parameters.Add(new SqlParameter("@SoftwareName", sName)); //open the connection connection.Open(); dataSetH = new DataSet(); adapterH.Fill(dataSetH, "Copies"); } catch (Exception ex) { string msg = "fetch Error:"; msg += ex.Message; throw new Exception(msg); } finally { connection.Close(); } NavigateCopies(); } </code></pre> <p>The code that populates the text boxes for the first time:</p> <pre><code> private void NavigateCopies() { DataRow dRow = dataSetH.Tables[0].Rows[inc]; TextBoxCopyID.Text = dRow.ItemArray.GetValue(0).ToString(); TextBoxSoftwareName.Text = dRow.ItemArray.GetValue(1).ToString(); DropDownListAssetName.SelectedItem.Text = dRow.ItemArray.GetValue(2).ToString(); DropDownListLocation.SelectedItem.Text = dRow.ItemArray.GetValue(3).ToString(); TextBoxLicence.Text = dRow.ItemArray.GetValue(4).ToString(); DropDownListType.SelectedItem.Text = dRow.ItemArray.GetValue(5).ToString(); DropDownListState.SelectedItem.Text = dRow.ItemArray.GetValue(6).ToString(); TextBoxInstall.Text = dRow.ItemArray.GetValue(7).ToString(); Session["ds"] = dataSetH; Session["increment"] = inc; } </code></pre> <p>The next row button code: protected void ButtonNext_Click(object sender, EventArgs e) { if (Session["ds"] != null) { dataSetH = (DataSet)Session["ds"]; inc = (int)Session["increment"]; inc++;</p> <pre><code> if (inc != dataSetH.Tables[0].Rows.Count) { NavigateCopies(); } else { Label1.Text = "No More Rows"; } } } </code></pre> <p>So when the Next button is pressed one it selects the next row. each subsequent click does nothing. The pages status bar symbol spins but the text boxes are not populated with the next record. I'm not sure if this has something to done with the fact the form is reloading but every example I've seen has a table or grid populated on load whereas my situation requires me to populate text boxes after user input. Any help with this would be much appreciated. </p> <p>I have since edited the code. Its now working, allowing the next button to page through the whole data set. I shall create a catch on the button to prevent the user from going over the maximum rows now.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload