求助:将c# repeater套嵌代码 转换为vb
网上查了好久,比较实用的repeater套嵌代码基本都是C#写的,不便于vb新手学习。麻烦将cs代码转换为vb,并作相关的注释。
数据库以SQL自带的Pubs为例。
网页代码
<asp:repeater id="repeaterMain" Runat="server" OnItemDataBound="repeaterMain_ItemDataBound">
<ItemTemplate>
<table>
<tr><td>
<a href= " <%#"Details.aspx?au_id=" + DataBinder.Eval(Container,"DataItem.au_id")%> "> <%#DataBinder.Eval(Container,"DataItem.au_id")%> </a> 大类<br>
</td>
</tr>
<asp:repeater ID="repeaterSub" Runat="server">
<ItemTemplate>
<tr>
<td>
<a href= " <%#"Details.aspx?title_id=" + DataBinder.Eval(Container,"DataItem.title_id")%> "> <%#DataBinder.Eval(Container, "DataItem.title_id")%> </a> 小类
</td>
</tr>
</ItemTemplate>
</asp:repeater>
</table>
</ItemTemplate>
</asp:repeater>
cs代码
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindMain();
}
}
private void BindMain()
{
SqlConnection cn = new SqlConnection(@"server=(local);uid=sa;pwd=1234567890;database=pubs");
SqlDataAdapter da = new SqlDataAdapter("select au_id from authors", cn);
DataSet ds = new DataSet();
cn.Open();
da.Fill(ds);
repeaterMain.DataSource = ds.Tables[0].DefaultView;
repeaterMain.DataBind();
cn.Close();
}
protected void repeaterMain_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
string au_id = ((DataRowView)e.Item.DataItem).Row["au_id"].ToString();
Repeater repeaterSub = (Repeater)e.Item.FindControl("repeaterSub");
if (repeaterSub != null)
{
SqlConnection cn = new SqlConnection(@"server=(local);uid=sa;pwd=1234567890;database=pubs");
SqlCommand cmd = new SqlCommand("select title_id from titleauthor where au_id = @au_id", cn);
cmd.Parameters.Add("@au_id", SqlDbType.VarChar, 11).Value = au_id;
cn.Open();
repeaterSub.DataSource = cmd.ExecuteReader();
repeaterSub.DataBind();
cn.Close();
}
}
}
补充:.NET技术 , VB.NET