repeater控件用法_propertygrid控件

2022-11-04 16:11:39 浏览数 (1)

大家好,又见面了,我是你们的朋友全栈君。

在我们编写程序的时候经常会遇到控件嵌套的问题。 通常最经常用到的控件时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;

}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/182526.html原文链接:https://javaforall.cn

0 人点赞