62,074
社区成员
发帖
与我相关
我的任务
分享
public string connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\_workshop\\ASP\\AutoPaged_test_111015\\data.mdb;";//note
protected void Page_Load(object sender, EventArgs e)
{
using (OleDbConnection oledbConn = new OleDbConnection(connstr))//note
{
oledbConn.Open();
OleDbCommand oledbCmd=new OleDbCommand("SELECT * FROM [tbQuestion] WHERE tid='2'", oledbConn);
OleDbDataReader odr = oledbCmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);//note
DataTable dt = new DataTable();
dt.Load(odr);
this.prov.DataSource = dt;
this.prov.DataBind();
oledbConn.Close();
}
}
protected void prov_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)//note
{
Repeater rpt = (Repeater)e.Item.FindControl("city");
DataRowView drv = (DataRowView)e.Item.DataItem;
string QuestionID = drv["qid"].ToString();
using (OleDbConnection oledbConn = new OleDbConnection(connstr))
{
oledbConn.Open();
OleDbCommand oledbCmd = new OleDbCommand("SELECT ctxt FROM [tbChoice] WHERE qid='" + QuestionID + "'", oledbConn);
OleDbDataReader odr = oledbCmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
DataTable dt = new DataTable();
dt.Load(odr);
rpt.DataSource = dt;
rpt.DataBind();
oledbConn.Close();
}
}
}
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<table>
<tr>
<td>
题目
</td>
</tr>
<asp:Repeater ID="prov" runat="server" OnItemDataBound="prov_ItemDataBound">
<ItemTemplate>
<tr>
<td id='prov<%#Eval("qtxt") %>' type="prov">
<%#Eval("qtxt") %>
</td>
</tr>
<tr>
<td id='city<%#Eval("qid") %>' style="display: none;">
<asp:Repeater ID="city" runat="server">
<ItemTemplate>
<table>
<tr>
<td>
<%#Eval("ctxt") %>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
</div>
</form>
</body>
</html>