The data used to display the list on the webpage is found to be more flexible than repeater, such as gridview and detailview. Therefore, we will summarize some of the situations we encountered recently and keep them for future reference, don't ask du Niang now...
You may find something wrong.
1. The Repeater control can be an array, for example, an instance array of a class.
1 // front-end Code 2 <asp: repeater id = "Repeater" runat = "server" 3 onitemcommand = "repeater_itemcommand"> 4
1 // background Code 2 newsclass [] array = is. Business. newsclassbll. getfirstlevelclass (); 3 repeater. datasource = array; 4 repeater. databind ();
2. Use commondargument to pass parameters to the background, and process the corresponding commands for buttons in the control in the itemcommand event.
protected void repeater_ItemCommand(object source, RepeaterCommandEventArgs e) { switch (e.CommandName) { case "edit": ((Panel)e.Item.FindControl("pnl_display")).Visible = false; ((Panel)e.Item.FindControl("pnl_edit")).Visible = true; break; case "cancel": ((Panel)e.Item.FindControl("pnl_display")).Visible = true; ((Panel)e.Item.FindControl("pnl_edit")).Visible = false; break; case "delete": try { IS.Business.NewsClassBLL.Delete(int.Parse(e.CommandArgument.ToString())); this.bindData(); } catch (Exception ex) { Functions.AlertMsg(ex.Message, Page); } break; case "update": string oldname = e.CommandArgument.ToString(); string newname = ((TextBox)e.Item.FindControl("txtBigClassName")).Text; try { IS.Business.NewsClassBLL.RenameFirstLevelClassName(oldname, newname); this.bindData(); } catch (Exception ex) { Functions.AlertMsg(ex.Message, Page); } break; default: break; } }
3. Two panels are used to implement functions similar to local editing. It seems that it is better to use placeholder without generating additional HTML tags.
4. The bound class contains an instance of another class as its property member. It is used to bind an attribute of its property member:
<%#DataBinder.Eval(((IS.Model.Exhibition)Container.DataItem).Area,"Name") %>
5. Add a row number:
<%#Container.ItemIndex+1 %>
6. format some input variables. Take the time as an example:
<%#DataBinder.Eval(Container.DataItem,"StartTime","{0:yyyy-MM-dd}") %>