本文介绍了我点击按钮一个接一个地显示问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在pageload中加载了问题1。点击按钮后,将显示问题2。现在我需要通过单击相同的按钮来显示问题3。但我无法做到。任何人都可以帮助我吗?
使用System;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Web.UI;
使用System.Web.UI.WebControls;
使用System.Data;
使用System.Data.SqlClient;
public partial class Default6:System.Web.UI.Page
{
int i = 1;
SqlConnection con = new SqlConnection(Data Source = DS-70; Initial Catalog = model; Integrated Security = True;);
protected void Page_Load(object sender,EventArgs e)
{
SqlCommand cmd = new SqlCommand(select * from exam where qno = @ qno,con );
cmd.Parameters.AddWithValue(@ qno,i);
con.Open();
SqlDataReader sdr = cmd.ExecuteReader();
while(sdr.Read())
{
Label1.Text = sdr [0] .ToString()。Trim();
RadioButtonList1.Items [0] .Text = sdr [1] .ToString()。Trim();
RadioButtonList1.Items [1] .Text = sdr [2] .ToString()。Trim();
RadioButtonList1.Items [2] .Text = sdr [3] .ToString()。Trim();
RadioButtonList1.Items [3] .Text = sdr [4] .ToString()。Trim();
}
con.Close();
}
protected void Button1_Click(object sender,EventArgs e)
{
this.i = i + 1;
SqlCommand cmd = new SqlCommand(select * from exam where qno = @ qno,con);
cmd.Parameters.AddWithValue(@ qno,i);
con.Open();
SqlDataReader sdr = cmd.ExecuteReader();
while(sdr.Read())
{
Label1.Text = sdr [0] .ToString()。Trim();
RadioButtonList1.Items [0] .Text = sdr [1] .ToString()。Trim();
RadioButtonList1.Items [1] .Text = sdr [2] .ToString()。Trim();
RadioButtonList1.Items [2] .Text = sdr [3] .ToString()。Trim();
RadioButtonList1.Items [3] .Text = sdr [4] .ToString()。Trim();
}
con.Close();
}
}
解决方案
I have loaded the question 1 in pageload. After clicking the button question 2 will be displayed. Now I need to display the question 3 by clicking the same button. But I am unable to do it. Can any one help me ?
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; public partial class Default6 : System.Web.UI.Page { int i = 1; SqlConnection con = new SqlConnection("Data Source=DS-70;Initial Catalog=model;Integrated Security=True;"); protected void Page_Load(object sender, EventArgs e) { SqlCommand cmd = new SqlCommand("select * from exam where qno=@qno", con); cmd.Parameters.AddWithValue("@qno", i); con.Open(); SqlDataReader sdr = cmd.ExecuteReader(); while (sdr.Read()) { Label1.Text = sdr[0].ToString().Trim(); RadioButtonList1.Items[0].Text = sdr[1].ToString().Trim(); RadioButtonList1.Items[1].Text = sdr[2].ToString().Trim(); RadioButtonList1.Items[2].Text = sdr[3].ToString().Trim(); RadioButtonList1.Items[3].Text = sdr[4].ToString().Trim(); } con.Close(); } protected void Button1_Click(object sender, EventArgs e) { this.i = i + 1; SqlCommand cmd = new SqlCommand("select * from exam where qno=@qno", con); cmd.Parameters.AddWithValue("@qno", i); con.Open(); SqlDataReader sdr = cmd.ExecuteReader(); while (sdr.Read()) { Label1.Text = sdr[0].ToString().Trim(); RadioButtonList1.Items[0].Text = sdr[1].ToString().Trim(); RadioButtonList1.Items[1].Text = sdr[2].ToString().Trim(); RadioButtonList1.Items[2].Text = sdr[3].ToString().Trim(); RadioButtonList1.Items[3].Text = sdr[4].ToString().Trim(); } con.Close(); } }
解决方案
这篇关于我点击按钮一个接一个地显示问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!