使用c#中的下一个按钮 [英] using next button in c#

查看:98
本文介绍了使用c#中的下一个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

protected void Page_Load(object sender, EventArgs e)
    {
                con = new SqlConnection();
        con.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True";
        con.Open();

        ds = new DataSet();
        string sql = "SELECT * FROM Internet";
        da = new SqlDataAdapter(sql, con);
        da.Fill(ds, "Internet");
        Maxrows = ds.Tables["Internet"].Rows.Count;

        Label2.Text = inc.ToString();
        Label3.Text = Maxrows.ToString(); // displays the number of rows
       Records();
        con.Close();
    }

    private void Records()
    {
        drow = ds.Tables["Internet"].Rows[inc];
        Label1.Text = drow.ItemArray.GetValue(1).ToString();
        inc++;

    }


protected void Button1_Click(object sender, EventArgs e)
    {
if (inc <= Maxrows )
        {

            Records();
            Label2.Text = inc.ToString(); // outputs the row number which is being displayed
        }
    }
}

I have this above code and I am trying to display a number of records from a database on a web application. when I first load the page it load the first record. I click the next button and displays the second button. I have 3 records but the 3rd record never displays why? please can anyone help?

推荐答案

正如你所说,有3条记录,那么inc应该从0到2不等。

&条件if(inc <= Maxrows)应为if(inc
请调试代码并检查值是什么。
As you said there are 3 records then inc should vary from 0 to 2.
& Condition if (inc <= Maxrows ) should be if (inc < Maxrows ).
Please debug you code & check what r the values.


这篇关于使用c#中的下一个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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