再加个全选功能
前台需要怎么改进下 <asp:GridView runat="server" ID="gdv" AutoGenerateColumns="false" AllowPaging="true" PageSize="6"> <Columns> <asp:TemplateField HeaderText="选择"> <ItemStyle Width="100px"/> <ItemTemplate> <asp:CheckBox runat="server" DataField="pid"/> </ItemTemplate> </asp:TemplateField> <asp:BoundField HeaderText="标题" DataField="title" ItemStyle-Width="700px"/> <asp:CommandField HeaderText="操作" ShowEditButton="true" ShowDeleteButton="true" ItemStyle-Width="100px"/> </Columns> </asp:GridView> 后台处理,分页就不行了 DataTable dt = new DataTable(); dt.Columns.Add("pid"); dt.Columns.Add("title"); if (dt.Rows.Count == 0) { dt.Rows.Add(dt.NewRow()); dt.Rows.Add(dt.NewRow()); dt.Rows.Add(dt.NewRow()); dt.Rows.Add(dt.NewRow()); dt.Rows.Add(dt.NewRow()); } this.gdv.DataSource = dt; this.gdv.DataBind();
你是需要别人帮你写一套出来?
能写出来最好,小弟初学还不是很懂,感谢前辈!
前端: <asp:GridView runat="server" ID="gdv" AutoGenerateColumns="false" AllowPaging="true" PageSize="6" onpageindexchanging="gdv_PageIndexChanging"> <Columns> <asp:TemplateField HeaderText="选择"> <ItemStyle Width="100px"/> <ItemTemplate> <asp:CheckBox runat="server" Text='<%# Eval("pid") %>'/> </ItemTemplate> </asp:TemplateField> <asp:BoundField HeaderText="标题" DataField="title" ItemStyle-Width="700px"/> <asp:CommandField HeaderText="操作" ShowEditButton="true" ShowDeleteButton="true" ItemStyle-Width="100px"/> </Columns> </asp:GridView> 后端: protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DataBinder(); } } public void DataBinder() { DataTable dt = new DataTable(); dt.Columns.Add("pid"); dt.Columns.Add("title"); if (dt.Rows.Count == 0) { for (int i = 0; i < 10; i++) { var row = dt.NewRow(); row[0] = i; row[1] = "标题" + i; dt.Rows.Add(row); } } gdv.DataSource = dt; gdv.DataBind(); } protected void gdv_PageIndexChanging(object sender, GridViewPageEventArgs e) { gdv.PageIndex = e.NewPageIndex; DataBinder(); }
@单诗诚:
@Rich.T:
谢谢前辈,还有个问题就是下图是控件吗?
怎么弄出来?
分页通过sql语句来控制。。。
感谢前辈!