从数据集按钮下一行只进行一次功能 [英] Next row from dataset button only performing function once

查看:106
本文介绍了从数据集按钮下一行只进行一次功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨天我问了一下使用通过下一/ previous按钮窗体的文本框中显示一个单行的数据集分页的问题。从那时起,我已经成功地得到下一个按钮,进入到下一行,但只有一次。以后每点击什么也不做。这里的一些code。

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.

在code。该用户后执行选择搜索的价值和presses值:

The code that executes after the the user selects a search value and presses a value:

  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用于填充文本框的第一次:

The code that populates the text boxes for the first time:

    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:
    保护无效ButtonNext_Click(对象发件人,EventArgs的发送)
    {
        如果(会话[DS]!= NULL)
        {
            dataSetH =(数据集)会话[DS];
            INC =(INT)会议[增值];
            INC ++;

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++;

        if (inc != dataSetH.Tables[0].Rows.Count)
        {
            NavigateCopies();
        }
        else
        {
            Label1.Text = "No More Rows";
        }
    }
}

因此​​,当下一步按钮是pressed之一,选择下一行。以后每次点击什么也不做。页面状态栏符号旋转而文本框不与下一个记录填充。我不知道这有什么用形式重装但每次我见过的例子有​​填充负载表或网格,而我的情况我需要用户输入后填充文本框的事实进行。任何帮助,这将是非常美联社preciated。

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.

因为我已经编辑了code。它现在的工作,使下一个按钮来翻阅整个数据集。我从现在开始要超过最大行上创建按钮渔获prevent用户。

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.

推荐答案

作为一样的,你把会话[DS] 需要把 INC 价值,以及

as same as you put Session["ds"] need to put inc value as well

protected void ButtonNext_Click(object sender, EventArgs e)
{
    if (Session["ds"] != null)
    {
        int inc;
        if(Session["inc"]==null)
        {
          Session["inc"] =0;
        }
        if(int.TryParse(Session["inc"], out inc)
        {
            inc++;
            Session["inc"] = inc;
            DataSet dataSetH = (DataSet)Session["ds"];

            if (inc <= dataSetH.Tables[0].Rows.Count)
            {
                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();
            }
        }
    }
}

这篇关于从数据集按钮下一行只进行一次功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆