checkboxlist传值问题 急 在线等
做了一个试题生成系统 选择checkboxlist中的多道试题然后点击添加到试卷 生成试卷,会输出一个word两个按钮一个添加一个生成,questionbanktb是数据库,courses是上个页面选择的科目
public partial class manual_select : System.Web.UI.Page
{
string myString = "";
protected void Page_Load(object sender, EventArgs e)
{
string courses = Request.QueryString["courses"];
string str = "select * from questionbanktb where coursename='" + courses + "' ";
conn db5 = new conn();
System.Data.SqlClient.SqlDataReader datas5 = db5.exceutereader(str);
this.CheckBoxList1.DataSource = datas5;
this.CheckBoxList1.DataTextField = "question";
this.CheckBoxList1.DataValueField = "id";
this.CheckBoxList1.DataBind();
datas5.Close();
}
protected void Submit1_ServerClick(object sender, EventArgs e)
{
System.Text.StringBuilder builder = new System.Text.StringBuilder();
for (int i = 0; i < CheckBoxList1 .Items .Count ; i++)
{
if (CheckBoxList1 .Items [i].Selected ==true )
{
builder.AppendLine (CheckBoxList1 .Items [i].Text );
builder.AppendLine ("@");
}
}
myString=builder.ToString();
}
protected void Submit2_ServerClick(object sender, EventArgs e)
{
string numsingle = "";
for (int i = 0; i < myString.Length; i++)
{
if (!myString.Substring(i, 1).Equals("@"))
{
numsingle = numsingle + myString.Substring(i, 1);
}
else
{
numsingle = numsingle + "\n";
}
}
OutPut("attachment;filename=peper.doc", "application/ms-word", numsingle);
}
private void OutPut(string fileType, string strType, String text)
{
Response.Clear();
Response.Buffer = true;
Response.Charset = "GB2312";
Response.AppendHeader("Content-Disposition", fileType);
Response.ContentType = strType;
this.EnableViewState = false;
Response.Write(text);
Response.End();
}
}
不知道为什么输出的word是空白的 哪位大侠教教我啊
其中conn类定义为
public class conn
{
SqlConnection con = null;
SqlCommand cmd = new SqlCommand();
public conn()
{
//
// TODO: 在此处添加构造函数逻辑
//
con = new SqlConnection("SERVER=.;uid=sa;pwd=1234;database=questionbank;");
}
public SqlConnection getconn()
{
if (con.State == ConnectionState.Closed)
con.Open();
return con;
}
public void clear()
{
if (con.State == ConnectionState.Open)
{
con.Close();
}
}
public SqlDataReader exceutereader(string sql)
{
cmd.Connection = getconn();
cmd.CommandText = sql;
SqlDataReader str = cmd.ExecuteReader();
return str;
}
public string exceutescalar(string sql)
{
string str = "";
try
{
cmd.Connection = getconn();
cmd.CommandText = sql;
str = cmd.ExecuteScalar().ToString();
clear();
}
catch (Exception e)
{
e.GetHashCode();
}
return str;
}
public void excuteupdate(string sql)
{
cmd.Connection = getconn();
cmd.CommandText = sql;
cmd.ExecuteNonQuery();
clear();
}
}
--------------------编程问答-------------------- 单步跟踪查看值
public string myString
{
get{return ViewState["myString"].ToString();}
set{ViewState["myString"]=value;}
} --------------------编程问答-------------------- 是把一开始的string myString = "";改成
public string myString
{
get{return ViewState["myString"].ToString();}
set{ViewState["myString"]=value;}
}吗?
还是不对啊
word还是空白的
补充:.NET技术 , ASP.NET