本文介绍了在btnclick evnet的下一页中将选定的行从一个网格视图传输到另一个网格视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在btnclick evnet上的下一页中将选定的行从一个网格视图传输到另一个网格视图



我尝试了什么:



在下一页的btnclick evnet

transfer selected rows from one gridview to another in next page on btnclick evnet

What I have tried:

transfer selected rows from one gridview to another in next page on btnclick evnet

推荐答案

<form id="form1" runat="server">

       <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" Height="310px" Style="margin-right: 56px" Width="704px">
           <Columns>
               <asp:TemplateField HeaderText="Select">
                   <ItemTemplate>
                       <asp:CheckBox ID="cbSelect"
                           CssClass="gridCB" runat="server"></asp:CheckBox>

                   </ItemTemplate>
               </asp:TemplateField>

               <asp:BoundField DataField="Title" HeaderText="Title" />
               <asp:BoundField DataField="Date" HeaderText="Date" />
               <asp:BoundField DataField="events" HeaderText="events" />
           </Columns>
       </asp:GridView>
       <asp:Button ID="btnCopy" runat="server" Text="Copy Rows" OnClick="btnCopy_Click" />

   </form>







public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                SPWeb web = SPContext.Current.Web;
                SPList list = web.Lists["Calender event selection list"];
                SPListItemCollection items = list.Items;
                GridView1.DataSource = items.GetDataTable();
                GridView1.DataBind();
            }
        }

      

        protected void btnCopy_Click(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("Title");
            dt.Columns.Add("Date");
            dt.Columns.Add("events");

            foreach (GridViewRow row in GridView1.Rows)
                if (((CheckBox)row.Cells[0].FindControl("cbSelect")).Checked)
                    dt.Rows.Add(row.Cells[1].Text, row.Cells[2].Text, row.Cells[3].Text);

            Session["Data"] = dt;
            Response.Redirect("WebForm2.aspx");
        }
    }





Page 2





Page 2

<form id="form1" runat="server">
   <div>

       <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" Height="310px" Style="margin-right: 56px" Width="704px">
           <Columns>
               <asp:BoundField DataField="Title" HeaderText="Title" />
               <asp:BoundField DataField="Date" HeaderText="Date" />
               <asp:BoundField DataField="events" HeaderText="events" />
           </Columns>
       </asp:GridView>
   </div>
   </form>







 public partial class WebForm2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack) {
                DataTable dt = (DataTable)Session["Data"];
                GridView1.DataSource = dt;
                GridView1.DataBind();
            }

        }
    }
}


这篇关于在btnclick evnet的下一页中将选定的行从一个网格视图传输到另一个网格视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 20:13