How to copy data from one gridview to another gridview in c#?
Answers
Answered by
6
hello...
ur answer....
I've been working in a project for some time now, and I'm having some hard times trying to figure out how to copy data from one gridview to another.
What I want to do is this: My web aplication will list all content the user have in a gridview (dynamically binded to a database), and it will have a button "+" that when clicked, it will copy that 2 columns of that row to another gridview.
I've tried some times and it works copy the very first row (no matter what row is that), but then it do not work anymore.
Here is the asp.net code:
<div id="Musicas">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Name" DataSourceID="ObjectDataSource1" OnRowCommand="GridView1_RowCommand">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Gender" HeaderText="Gender" SortExpression="Gender" />
<asp:BoundField DataField="Album" HeaderText="Album" SortExpression="Album" />
<asp:BoundField DataField="ReleaseYear" HeaderText="ReleaseYear" SortExpression="ReleaseYear" />
<asp:BoundField DataField="Composer" HeaderText="Composer" SortExpression="Composer" />
<asp:BoundField DataField="Artist" HeaderText="Artist" SortExpression="Artist" />
<asp:ButtonField ButtonType="Button" CommandName="Select" HeaderText="AddPlayList" ShowHeader="True" Text="+" />
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" OnSelecting="ObjectDataSource1_Selecting" SelectMethod="GetMusic" TypeName="BLL.GetUserInformation">
<SelectParameters>
<asp:Parameter Name="id" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" />
</Columns>
</asp:GridView>
</div>...
click me in thank u. .
ur answer....
I've been working in a project for some time now, and I'm having some hard times trying to figure out how to copy data from one gridview to another.
What I want to do is this: My web aplication will list all content the user have in a gridview (dynamically binded to a database), and it will have a button "+" that when clicked, it will copy that 2 columns of that row to another gridview.
I've tried some times and it works copy the very first row (no matter what row is that), but then it do not work anymore.
Here is the asp.net code:
<div id="Musicas">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Name" DataSourceID="ObjectDataSource1" OnRowCommand="GridView1_RowCommand">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Gender" HeaderText="Gender" SortExpression="Gender" />
<asp:BoundField DataField="Album" HeaderText="Album" SortExpression="Album" />
<asp:BoundField DataField="ReleaseYear" HeaderText="ReleaseYear" SortExpression="ReleaseYear" />
<asp:BoundField DataField="Composer" HeaderText="Composer" SortExpression="Composer" />
<asp:BoundField DataField="Artist" HeaderText="Artist" SortExpression="Artist" />
<asp:ButtonField ButtonType="Button" CommandName="Select" HeaderText="AddPlayList" ShowHeader="True" Text="+" />
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" OnSelecting="ObjectDataSource1_Selecting" SelectMethod="GetMusic" TypeName="BLL.GetUserInformation">
<SelectParameters>
<asp:Parameter Name="id" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" />
</Columns>
</asp:GridView>
</div>...
click me in thank u. .
Similar questions