你丫的GridView

 机能需求:对数据列表的数据进行拆分合并操作。
拆分:根据用户选择的girdview中的一条或多条数据,动态生成相应个gridview,每个gridview中显示n条改数据(原gridview中有一数量列,n表示其值);
合并:根据用户选择的动态生成的多个gridview中的数据,合并成一条数据(只数量合并),然后替换原gridview中的选择数据。

好久没玩GridView了,发觉不怎么有感情了。。。
先留下个记号,回头再来总结!
上代码:
前台
  1. <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="total" OnRowCreated="GridView1_RowCreated"
  2.             >
  3.             <Columns>
  4.                 <asp:TemplateField>
  5.                     <ItemTemplate>
  6.                         <asp:CheckBox ID="CheckBox1" runat="server" />
  7.                     </ItemTemplate>
  8.                 </asp:TemplateField>
  9.                 <asp:BoundField DataField="inqmxid" HeaderText="inqmxid" ReadOnly="True" SortExpression="inqmxid" />
  10.                 <asp:BoundField DataField="fname" HeaderText="fname" SortExpression="fname" />
  11.                 <asp:BoundField DataField="unit" HeaderText="unit" SortExpression="unit" />
  12.                 <asp:BoundField DataField="qty" HeaderText="qty" SortExpression="qty" />
  13.                 <asp:BoundField DataField="total" HeaderText="total" SortExpression="total" />
  14.                 <asp:BoundField DataField="maker" HeaderText="maker" SortExpression="maker" />
  15.                 <asp:BoundField DataField="makedate" HeaderText="makedate" SortExpression="makedate" />
  16.                 
  17.             </Columns>
  18.         </asp:GridView>
  19.  
  20.         <asp:Panel ID="Panel1" runat="server" Height="455px" Width="654px" BorderColor="Silver" BorderStyle="Solid" ScrollBars="Vertical">
  21.         </asp:Panel>
后台  动态生成GridView,并添负数据
  1. Panel1.Controls.Clear();
  2.             for (int i = 0; i < GridView1.Rows.Count; i++)
  3.             {
  4.                 CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
  5.                 if (cbox.Checked)
  6.                 {
  7.                     int con = Convert.ToInt32(GridView1.DataKeys[i].Value);
  8.                     if (con > 0)
  9.                     {
  10.                         DataTable dt2=dt.Clone();
  11.                         for (int j = 0; j < con; j++)
  12.                         {
  13.                             dt2.Rows.Add(dt.Rows[i].ItemArray);
  14.                             dt2.Rows[j]["total"] = "1";
  15.                         }
  16.                         GridView grv = new GridView();
  17.                         grv.Width = Unit.Pixel(500);
  18.                         grv.RowCreated+=new GridViewRowEventHandler(grv_RowCreated);
  19.                         Panel1.Controls.Add(grv);
  20.                         grv.DataSource = dt2;
  21.                         grv.DataBind();
  22.                     }
  23.                 }
  24.             }

动态插入CheckBox
  1. protected void grv_RowCreated(object sender, GridViewRowEventArgs e)
  2.         {
  3.             GridViewRow row = e.Row;
  4.             if (row.RowType == DataControlRowType.Header)
  5.             {
  6.                 TableCell cell = new TableCell();
  7.                 cell.Wrap = Wrap;
  8.                 cell.Width = Unit.Pixel(50);
  9.                 cell.Text = "<label>选择</label>";
  10.                 row.Cells.AddAt(0, cell);
  11.             }
  12.             else if (row.RowType == DataControlRowType.DataRow)
  13.             {
  14.                 TableCell cell = new TableCell();
  15.                 cell.Wrap = Wrap;
  16.                 CheckBox cb = new CheckBox();
  17.                 cell.Width = Unit.Pixel(50);
  18.                 cb.ID = "ItemCheckBox";
  19.                 cell.Controls.Add(cb);
  20.                 row.Cells.AddAt(0, cell);
  21.                 
  22.             }
  23.         }
完事,走人。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值