昨天我問了一個關於使用下一個/上一個按鈕在窗體文本框中顯示單個行的數據集進行分頁的問題。從那時起,我設法讓下一個按鈕進入下一行,但只有一次。隨後的每一次點擊均不起作用這裏有一些代碼。數據集按鈕的下一行只執行一次函數
該用戶之後,執行該代碼選擇搜索值並按下一個值:
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();
}
用於填充的文本框的第一時間代碼:
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;
}
下一行按鈕代碼: protected void ButtonNext_Click(object sender,EventArgs e) if(Session [「ds」]!= null) { dataSetH = (數據集)的會話[ 「DS」]; inc =(int)Session [「increment」]; inC++;
if (inc != dataSetH.Tables[0].Rows.Count)
{
NavigateCopies();
}
else
{
Label1.Text = "No More Rows";
}
}
}
所以當按下下一步按鈕時,它會選擇下一行。隨後的每次點擊都不起作用頁面狀態欄符號旋轉,但文本框未填入下一條記錄。我不確定這是否需要重新加載表單,但我看到的每個示例都有一個表格或網格填充,而我的情況要求我在用戶輸入後填充文本框。任何幫助,將不勝感激。
我已經編輯過代碼。它現在正在工作,允許下一個按鈕翻閱整個數據集。我將在按鈕上創建一個catch,以防止用戶現在超過最大行數。
我也很想知道如何在沒有按鈕導航功能的情況下工作的需要。 – Tinydan