简体   繁体   English

如何从一个网格视图传输和删除单个选定的行到另一个网格视图

[英]how can i transfer and remove single selected row from one grid view to another

i have two grid views when i check the check box it transfer multiple rows but it didn't transfer single checked row i tried code is: i want to transfer and remove single selected and multiple selected rows. 我有两个网格视图,当我选中它传输多行的复选框但它没有传输单个检查行我尝试的代码是:我想传输和删除单个选定和多个选定的行。

gvDetails is selected row transfer gridview. 选择gvDetails行转移gridview。

private void GetRemoveRows()
        {

            if (Session["GetRecords"] != null)
            DataTable  dtre = (DataTable)Session["GetRecords"];

            Session["GetRecords"] = dtre ;

            gvDetails.DataSource = dtre; 
            gvDetails.DataBind();

        } 

can anyone help me out. 谁能帮我吗。

look at these code. 看看这些代码。

HTML: HTML:

<asp:GridView ID="GridView1" runat="server" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
AutoGenerateColumns="false" OnSelectedIndexChanged = "OnSelectedIndexChanged">
<Columns>
    <asp:BoundField DataField="Name" HeaderText="Name" ItemStyle-Width="150" />
    <asp:TemplateField HeaderText="Country" ItemStyle-Width="150">
        <ItemTemplate>
            <asp:Label ID="lblCountry" runat="server" Text='<%# Eval("Country") %>'></asp:Label>
        </ItemTemplate>
    </asp:TemplateField>
    <asp:ButtonField Text="Select" CommandName="Select" ItemStyle-Width="150" />
</Columns>
</asp:GridView>
<br />
<u>Selected Row Values: </u>
<br />
<br />
<asp:Label ID="lblValues" runat="server" Text=""></asp:Label>

C# code: C#代码:

Page Load: 页面加载:

protected void Page_Load(object sender, EventArgs e)
{
  if (!this.IsPostBack)
 {
    DataTable dt = new DataTable();
    dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Id"), new DataColumn("Name"), new DataColumn("Country") });
    dt.Rows.Add(1, "John Hammond", "United States");
    dt.Rows.Add(2, "Mudassar Khan", "India");
    dt.Rows.Add(3, "Suzanne Mathews", "France");
    dt.Rows.Add(4, "Robert Schidner", "Russia");
    GridView1.DataSource = dt;
    GridView1.DataBind();
 }
}

And Selected Row Index.. 和选择行索引..

protected void OnSelectedIndexChanged(object sender, EventArgs e)
{
 //Accessing BoundField Column
 string name = GridView1.SelectedRow.Cells[0].Text;

 //Accessing TemplateField Column controls
 string country = (GridView1.SelectedRow.FindControl("lblCountry") as Label).Text;

 lblValues.Text = "<b>Name:</b> " + name + " <b>Country:</b> " + country;
}

Comment if you have any query. 如果您有任何疑问,请评论。

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

相关问题 如何从网格控件中删除选定的行 - How can I remove selected row from a grid control 在运行时从网格视图中删除单个选定的行 - Delete the single selected row from a grid view at run time 如何将选定的行从网格视图绑定到另一个网格视图 - How to Bind Selected Rows From Grid View to Another Grid View 我如何在asp.net中将一个gridview行转移到另一个gridview行 - How can i transfer one gridview row to another gridview row in asp.net 如何将数据从数据网格视图中的选定行传递到另一种形式的标签 - How to pass data from the selected row in data grid view to a label of another form 如何通过按钮将数据从文本框传输到另一个 Winform 中的数据网格视图? - How do I transfer data from a textbox to a data grid view in another winform via a button? 单击行时如何从网格视图重定向 - How can I redirect from a grid view when a row is clicked 如何将选定的行从一个datagridview传输到另一个? - How to transfer selected rows from one datagridview to another? 如何从表中删除一行并将其通过SQL语句插入另一行? - How can I remove one row from a table and insert it into another via a SQL statement? 如何将comboBox中选定值的数据从一种形式传输到另一种形式 - How to transfer data of selected value in comboBox from one form to another
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM