something on class
OleDbConnection conn=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\db\\mydb.mdb");
string strSql="select * from problem where pub='true' order by type desc";
OleDbCommand cmd=new OleDbCommand(strSql,conn);
conn.Open();
OleDbDataReader dr=cmd.ExecuteReader();
int i=1;
while(dr.Read())
{
Label mylabel=new Label();
TableRow Row=new TableRow();
TableCell Cell=new TableCell();
string mystr="",typeStr="";
if(dr["type"].ToString()=="s")
typeStr="(单选)";
else
typeStr="(多选)";
mystr+=i.ToString()+dr["title"]+typeStr+"<br><br>";
mystr+="A、 "+dr["ans1"]+" B、 "+dr["ans2"]+" C、"+dr["ans3"]+" D、"+dr["ans4"];
mystr+="<br><br>答题";
mylabel.Text=mystr;
Cell.Controls.Add(mylabel);
if(dr["type"].ToString()=="s")
{
RadioButtonList radio=new RadioButtonList();
radio.RepeatDirection=RepeatDirection.Horizontal;
radio.Items.Add("A");
radio.Items.Add("B");
radio.Items.Add("C");
radio.Items.Add("D");
Cell.Controls.Add(radio);
}
else
{
CheckBoxList check=new CheckBoxList();
check.RepeatDirection=RepeatDirection.Horizontal;
check.ID="mycontrol"+i.ToString();
check.Items.Add("A");
check.Items.Add("B");
check.Items.Add("C");
check.Items.Add("D");
Cell.Controls.Add(check);
}
Label mylabel2=new Label();
if(dr.Read())
{
mylabel2.Text="<br><br>";
}
else
{
mylabel2.Text="<br><br>********************************************************************";
}
Cell.Controls.Add(mylabel2);
Row.Cells.Add(Cell);
Table4.Rows.Add(Row);
i=i+1;
}
conn.Close();
浙公网安备 33010602011771号