简体   繁体   English

在Webform(ASP.NET)中将选定的行从一个GridView传输到另一个GridView

[英]Transfer selected rows from one GridView to another GridView in webform (ASP.NET)

I have two Gridview controls. 我有两个Gridview控件。 In the first one I bound the data from a stored procedure using SQL, and I want to export selected rows from Gridview1 to GridView2. 在第一个示例中,我使用SQL绑定了存储过程中的数据,我想将选定的行从Gridview1导出到GridView2。

This is my code for binding the data of Gridview1: 这是我的代码,用于绑定Gridview1的数据:

// Load the data of [Student_Registration] store procedured
// from SQL to gridview1
sqlcom.CommandType = CommandType.StoredProcedure;
sqlcom.CommandText = "Student_Registration";
sqlcom.Parameters.Add("@SSID", SqlDbType.Int).Value = Int32.Parse(LblSubjectStudyId.Text.Trim());
sqlcom.Connection = con;
try
{
    con.Open();
    GridView1.EmptyDataText = "No Records Found";
    GridView1.DataSource = sqlcom.ExecuteReader();
    GridView1.DataBind();
}
catch (Exception ex)
{
    throw ex;
}
finally
{
    con.Close();
    con.Dispose();
}

How can I do this? 我怎样才能做到这一点?

Okay, first of all you need to add a check box control in item Template and then you will have to put an export button on page. 好的,首先,您需要在模板模板中添加一个复选框控件,然后您必须在页面上放置一个导出按钮。

At a button click, find all the selected rows in the grid view by using value of the checked items and then convert the whole row into a data row and add it to a table. 单击按钮后,使用选中项的值在网格视图中找到所有选定的行,然后将整个行转换为数据行并将其添加到表中。

Now bind this datatable to the gridview source. 现在将此数据表绑定到gridview源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM