如何选择类别并显示与该类别相关的数据?

时间:2013-11-03 18:13:57

标签: c# asp.net webforms

如何选择年龄类别并将值传递给另一个表单以显示与年龄类别相关的问题?有没有更好的方法呢?

这是班级

public string getquestion()
    {
        string query = "SELECT * FROM category ";
        if (this.OpenConnection() == true)
        //connection.Open();
        {
            SqlCommand comm = new SqlCommand(query, connection);
            rdr = comm.ExecuteReader();
            while (rdr.Read())
            {
                Label2 += rdr["Category"].ToString();
            }
            this.CloseConnection();


        }
        return Label2;


    }

这是主页表格

public partial class Home : System.Web.UI.Page
{
    Database category;
    protected void Page_Load(object sender, EventArgs e)
    {
        category = new Database();
        Age_Category_Label.Text = category.getquestion();
    }
}

这是问题表格

public partial class Question_List : System.Web.UI.Page
{
    Database question;

    protected void Page_Load(object sender, EventArgs e)
    {
        question = new Database();
        showquestion();
    }
    public void showquestion()
    {
        string category = Request.QueryString["category"];
        string query = "SELECT top 10 * FROM question WHERE Age_group order by newid()='"  +category+ "'";
        if (question.OpenConnection() == true)
        {
            SqlCommand comm = new SqlCommand(query, question.connection);
            question.rdr = comm.ExecuteReader();
            while (question.rdr.Read())
            {
                this.Question_list_output.Text += question.rdr["Question"].ToString() + "<br />";
            }
            question.CloseConnection();



        }
    }
}

0 个答案:

没有答案