昨天我问了一个关于使用下一个/上一个按钮在窗体文本框中显示单个行的数据集进行分页的问题。从那时起,我设法让下一个按钮进入下一行,但只有一次。随后的每一次点击均不起作用这里有一些代码。数据集按钮的下一行只执行一次函数
该用户之后,执行该代码选择搜索值并按下一个值:
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