repeater控件用法_propertygrid控件
大家好,又见面了,我是你们的朋友全栈君。
在我们编写程序的时候经常会遇到控件嵌套的问题。 通常最经常用到的控件时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
相关文章
- Delphi xe5 控件TIdhttp的用法post,get解决中文乱码问题
- C#控件splitContainer用法
- 最小角回归 LARS算法包的用法以及模型参数的选择(R语言 )
- CSS3高级选择器用法
- android控件大全及用法_学双人舞一步一步教学
- vb api函数用法_VB调用apdl
- android 中 TextView的用法[通俗易懂]
- Python break用法详解
- Java中CountDownLatch用法详解编程语言
- Oracle Var用法初探深层次变量定义功能(Oracle var用法)
- ASP.NET服务器端控件RadioButtonList,DropDownList,CheckBoxList的取值、赋值用法
- JavaScript中instanceof运算符的用法总结
- javascript中parseInt()函数的定义和用法分析
- VC++的combobox控件用法汇总
- PHPSession机制简介及用法