大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。
Jetbrains全系列IDE稳定放心使用
在我们编写程序的时候经常会遇到控件嵌套的问题。
通常最经常用到的控件时repeater,以下是一两个列子。
HTML
<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>
C#code
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();
}
}
}
C# code
checklistbox
如果是bind checklistbox
protected void group_manage_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
string au_id = ((DataRowView)e.Item.DataItem).Row[“id”].ToString();
CheckBox chk = (CheckBox)e.Item.FindControl(“chk_lock”);
chk.Text = au_id.ToString();
DABaseAccess DB = new DABaseAccess();
string Str = “select r.rolename from users u left join meun_userrole ur on u.id=ur.userid “
+ ” left join meun_role r on ur.roleid=r.id “
+ “where u.id=” + au_id;
Repeater repeaterSub = (Repeater)e.Item.FindControl(“repeaterSub”);
if (repeaterSub != null)
{
repeaterSub.DataSource = DB.Query(Str);
repeaterSub.DataBind();
}
}
}
取值关于控件取值问题
for (int i = 0; i < this.group_manage.Items.Count; i++)
{
CheckBox chk = (CheckBox)group_manage.Items[i].FindControl(“chk_lock”);
if (chk != null)
{
chk.Checked = false;
}
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/182526.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...