how to place a selected row from a gridview into another gridview by clicking a button

hi,

In my application  i have binded the data from data base table to a grid view. my database table attributes are prodid,prodname ,price and qty. my grid view columns includes qty,prodname,price.i placed checkbox into my gridview and i placed a textboxes in the last column for placing required  qty from the available qty.after clicking on a checkbox of a perticular row  that selected row should be placed into another grid view by clicking on a submit button. the second gridview columns are serial no,prodname,qty(user required qty ), total price. in the last row of gridview i should get total payment by merging columns.

plz help to me 

0
radhakrishna001
8/20/2008 8:41:12 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

5 Replies
1791 Views

Similar Articles

[PageSpeed] 24
Get it on Google Play
Get it on Apple App Store

Hi ,

 

Here,i am giving you some Code .In my code when  you select checkbox ,it placed the checked row into another gridview.

this is code behinfd

Imports System.Data

Imports System.Data.SqlClient

Partial Class _DefaultInherits System.Web.UI.Page

 

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

If Not Page.IsPostBack Then

BindData()

MakeDataTable()

End If

End Sub

Protected Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)Dim chk As CheckBox = DirectCast(sender, CheckBox)

 

If chk.Checked Then

'Do your thing here

Dim Dt As New Data.DataTable Dt = CType(Session("DT"), Data.DataTable)

If Dt.Rows.Count > 0 Then

Dt.Rows.Clear()

End If

Dim dn As Data.DataRow

 

 

For k As Int32 = 0 To GridView1.Rows.Count - 1

Dim lb As Label = CType(GridView1.Rows(k).FindControl("Name"), Label)

Dim chk1 As CheckBox = CType(GridView1.Rows(k).FindControl("CheckBox1"), CheckBox)

Dim prof As String = GridView1.Rows(k).Cells(0).Text

Dim strname1 As String = lb.Text.ToString

If chk1.Checked Then

dn = Dt.NewRow

dn(
"Name") = strname1dn("Profession") = prof

Dt.Rows.Add(dn)

 

End If

 

Next

GridView2.DataSource = Dt

GridView2.DataBind()

Session("DT") = Dt

Else Dim Dt As New Data.DataTable Dt = CType(Session("DT"), Data.DataTable)

If Dt.Rows.Count > 0 Then

Dt.Rows.Clear()

End If

Dim dn As Data.DataRow

For k As Int32 = 0 To GridView1.Rows.Count - 1

Dim lb As Label = CType(GridView1.Rows(k).FindControl("Name"), Label)

Dim chk1 As CheckBox = CType(GridView1.Rows(k).FindControl("CheckBox1"), CheckBox)

Dim prof As String = GridView1.Rows(k).Cells(0).Text Dim strname1 As String = lb.Text.ToString

If chk1.Checked Then

dn = Dt.NewRow

dn(
"Name") = strname1dn("Profession") = prof

Dt.Rows.Add(dn)

 

End If

 

Next

GridView2.DataSource = Dt

GridView2.DataBind()

Session(
"DT") = Dt

End If

End Sub

Public Function BindData()

Dim con As New SqlConnection()

con.ConnectionString = ConfigurationManager.ConnectionStrings("testConnectionString").ConnectionString

 

con.Open()

Dim adp As New SqlDataAdapter("select * from Test_demo", con)Dim ds As New DataSet()

adp.Fill(ds)

GridView1.DataSource = ds

GridView1.DataBind()

Return Nothing

End Function

Private Sub MakeDataTable() Dim Dt As New Data.DataTable

If Session("DT") Is Nothing Then

Dt.Columns.Add("Name")

Dt.Columns.Add("Profession")

Session("DT") = Dt

GridView2.DataSource = Dt

GridView2.DataBind()

Else

Dt = CType(Session("DT"), Data.DataTable)

Dt.Rows.Clear()

Session(
"DT") = Dt

GridView2.DataSource = Dt

GridView2.DataBind()

End If

End Sub

End Class

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Untitled Page</title> </head>

<body>

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

<div>

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="id">

<Columns>

 

<asp:BoundField DataField="Profession" HeaderText="Profession" />

<asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" Visible="False" ReadOnly="True"/>

<asp:TemplateField HeaderText="Name">

<ItemTemplate>

<asp:Label ID="Name" Text='<%#Eval("Name")%>' runat="server"></asp:Label>

</ItemTemplate>

</asp:TemplateField>

<asp:TemplateField>

<ItemTemplate>

<asp:Label ID="Amount" Text='<%#Eval("amount")%>' runat="server"></asp:Label>

<asp:CheckBox ID="CheckBox1" runat="server" oncheckedchanged="CheckBox1_CheckedChanged" AutoPostBack="true" />

<asp:Button ID="Btndel" Text="Delete" CommandName="Delete" Enabled="false" runat="server" />

</ItemTemplate>

</asp:TemplateField>

</Columns>

</asp:GridView>

<asp:GridView ID="GridView2" runat="server">

</asp:GridView>

 

</div>

</form> </body>

</html>

 

if any problem,let me know.

0
sangeeta
8/20/2008 11:47:36 AM

Thank u for ur reply.. i did coding sm wht in this way. i wil make modifications to my code .let me see how it works.

0
radhakrishna001
8/21/2008 5:53:48 AM

hi sangeeta chhabra

thanks for ur reply can u send me the code in c#. i'm beginner to .net. little confused with vb.net.

0
radhakrishna001
8/21/2008 7:33:21 AM

hi sangeeth

thank u. i did modifications to my code by seing ur code now it is working correctly. actually my application includes

gridview1 with columns- checkbox,prodname,qty,price and textboxes( for placing the quantity tht the user required from the available quantity)

after selecting the required products by clicking submit button those rows are passed to my 2nd gridview.

my gridview 2 columns are prodname,qty(user required quantity),price ,total price,and in the last row i should get total payment to pay.

my doubt is after selecting the quantity of product required by the user that quantity should be subtracted from the available quantity (qty should be updated)

we hav to place edit button in the source and make visibility to false when edit button is clicked we will get update and cancel buttons on clicking update btn we hav to write the code in tht button click

or

directly in the source we should place update button and in the btn click we should write code for update.

regards

radhakrishna

0
radhakrishna001
8/21/2008 8:36:45 AM

If you want to update something,you must write the code on the update button.

 thanks

 

Please Mark as answer,if my post provides you desire solution.

0
sangeeta
8/21/2008 8:57:24 AM
Reply:

Similar Artilces:

Iwant to select a row and column in gridview with select radiobutton. but No checked change event.below put a button .if click that button to seleced row values will select
I want to select a row and column in gridview using radiobutton in gridview . if which radio button is select that row will select and i want that row column values in outside individual textboxes of next page.  but in that only single radiobutton will select and no post back="true" bcz iam not using checked change property. i inserted button below gridview. if i click the that selected row and columns values are stored into textboxes of next page im using this code .but im getting one column in that row. but i want all columns in that selected row so plz repla...

How to access the row cells value of gridview on Select button click in Gridview
Hi Friends I am trying to getting the Row cells value on the Select command click. PLz any one know then reply me.  just add the code below between <Columns> element<asp:CommandField ShowSelectButton="True" />  then in you code add GridView1_SelectedIndexChanging events . inside the events you can get te id either  by writig id=GridView1.SelectedRow.cells[0].tostring or temp string= ctype(GridView1.Rows(e.NewSelectedIndex).FindControl(controlname),label)).textnote : assume that the ID is handled by label control in your datagrid.good luck&quo...

Selecting the multiple rows in GridView and inserting the selected rows to another Gridview & Performing some operations on it
 Dear All, I have become mad for solving this problem. Please Help me. I have a Gridview bound to a datasource. I inserted the CheckBox Control in Templet to select certain rows. Gridview1 contains some products id & name.I want to insert the selected rows in to second Gridview  and in the second Gridview I need to add two more colums AdvicedQty & AcceptedQty(TextBox Cotrol).The user will select few products in Gridview1 & clicks add which will be added another gridview then in second Gridview he enters the AdviceQty & AcceptedQty.After entering the data he cli...

I want to remove a row from gridview by clicking a button placed in gridview and want to show changes immediately there
Hii all. I want to remove a row from gridview by clicking a button placed in gridview itself in a template field. I have written the code for deleting the row in "btnremove_click" event and has binded my gridview in "page_load" event. When I used to click the button to remove that particular row, the details of that row still displayed untill the page will load again cuz gridview had binded there...  Now can anyone help me in this case, what could be done? Either "page_load" event has to be called in "btnremove_click" event OR if a condition co...

Using a row selection in a gridview to create database rows for another gridview
Hi there, I have 2 gridviews on a form, the first displays some template rows from a database table.  The second displays some user specific rows (with additional data added to the template info) from the same table. They both work fine for displaying the info.  Now what I want to do, is allow users to 'select' a template row on the first gridview, and have that action automatically: create a new user-specific row, with added fields from profile data etc. insert it into the table then refresh the second gridview in order to show the new added row. C...

How to find a outer gridview row when a button in inner gridview row is clicked
Hi, I have a gridview within a gridview. In the inner gridview, I have a column of imagebuttons. I cannot figure out how to find out the row of the outer gridview when I click on the imagebutton in the inner gridview. I modifies the code below to get rid of some of the unnecessary stuff. <asp:GridView ID="SitePrepMainGV" runat="server" DataKeyNames="SitePrepItemID" DataSourceID="SitePrepMasterDS" OnRowDataBound="SitePrepMainGV_RowDataBound" OnRowEditing="SitePrepMainGV_RowEditing" OnRowCreated="SitePrepMainGV_RowCreated"> <Columns> <asp:BoundField DataField="S...

populate a gridview from a selected row in another gridview
can someone give me an overview of how to grab a row from a gridview with a select button that is clicked to populate another gridview   Here is the markup for my gridview<asp:GridView ID="grdContacts" runat="server" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2" AutoGenerateColumns="False"> <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" /> <RowStyle BackColor="#FFF7E7" ForeCol...

gridview control in another gridview control
Hi ia have a questioni have a gridview control which contains button in one colum.now my question is i need another gridview to be placed in the  first gidviewso that when i click on the button the second gridview will populate the data.now my question is how to place second gridview in first gridview.or is there any approach like first grid itself acting as parent and child.please help me  Hi sirikalavalapalli:                I think nested gridview will help you. Check this link and it will show you how...

Selecting a gridview row and keeping the last selected row in a gridview highlighted after mouse moves over a new row.
What is the best way to show a gridview row highlighted once selected and keep it highlighted once the mouse moves over a different row? Thanks, Steve hi,you can use <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="#FFFFFF" /> plz let me know if i misunderstood you Thanks for your help. One problem; however, is that after the row has been selected and I check the "grid.SelectedIndex" it has a value of -1 and not the index of the row that was selected on the grid. What do you recommend? Thanks, Steve hi, sorry i din...

Add new controls to a gridview row; when editing that row using the edit row feature in the gridview control.
Hi all  I have a questions that looks hard / complex to me, and i know you can help me in this. Q {  I have row in a Gridview and i have an edit option to it. I press the edit button, to edit the values in that row and update data all the way back to the database. Now when i press the edit button, i want a drop down list to be displayed that contain values for a particular field in my grid view. (for now only plain text boxes appear.) } I hope you understand my question, all i need to do is replace the text box controls with a dropdown list when i am editing a row in ...

gridview, replace image in select button with another image when new row is selected
I am trying to replace an image from the select button command when another row is selected. This is the code that I have so far:  1 Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)2 Dim row As GridViewRow = GridView1.SelectedRow3 4 Select Case row.RowState5 Case DataControlRowState.Selected, DataControlRowState.Selected Or DataControlRowState.Alternate6 CType(row.Cells(0).Controls(0), ImageButton).ImageUrl = "Images/2.gif" 7 End Select8 End Sub ...

how to select row in Gridview on button click
Hi Friends      I have one problem with Gridview. I have Gridview with the Select button column. My problem is that i want to select this particular row when i click on the Select button in Gridview. How it is possible reply me.     on row data bound.. set row index as a attribute to your button.. then on button click set that indxex as a selectedindex of gridview..  "Mark as answered if you feel this helps you""Curiosity is Bliss"Regards,Ravi Kant Srivastava(Sr. Consultant I)NeudesicHyd'badINDIA Hi bluearc Can u give expla...

How to update Gridview through a Button(button
Hi there,I was wondering, if any one can help me in updating a Gridview through a button outside the grid (a button in the Form)I managed to do the same with a Datagrid..and the code goes...protected void button1_click (...){     foreach(datagriditem grdItem in datagrid.Items)    {     /// My update query     }}I'd be happy if I get one, similar to Gridview..  Cheers,Vino.     protected void button1_click (...){     foreach(GridViewRow grdItem in gridview.Rows)&n...

Gridview control embedded in another gridview control
I am writing an ambulance crew scheduling application on the web and I need some help completing the last part.  I have an access database that has three tables: user table, shift table (describing the shifts available), and a schedule table (that stores shift by shift_id and user by user_id).  I have a gridview control that will display the available shifts but I cannot get the embedded gridview control that will display the user that is signed up for each shift to display because I cannot figure out how to use the OnRowDataBound method.  I need a simple VB example of how to...

Web resources about - how to place a selected row from a gridview into another gridview by clicking a button - asp.net.presentation-controls

Portal:Bollywood/Selected biography - Wikipedia, the free encyclopedia
Write three or four paragraphs in the text field using information from the selected notable article, you may find it useful to examine the existing ...

F8: Facebook’s FbStart Initiative Will Give Selected Developers A $30K Kick-Start
... successful applications is likely a whole lot easier with $30,000 in free tools and services to start off with, and that’s exactly what selected ...

LEGO Shop - The LEGO Technic team has selected the winner... - Facebook
The LEGO Technic team has selected the winner of the Co-Creation Challenge! LEGO will be producing a limited run of 20,000 of this stunning set.... ...

Grand Doctor Ma Selected Students-baby365 on the App Store on iTunes
Get Grand Doctor Ma Selected Students-baby365 on the App Store. See screenshots and ratings, and read customer reviews.

Selected Cheney Vice Presidential Photographs
... for photos found within these albums are Paul Morse, Karen Ballard, Kimberlee Hewitt, Shealah Craighead, and Chris Greenberg. These selected ...

[iOS Advice] How To Clarify Your Email Replies By Quoting Selected Text - YouTube
Follow me on Twitter: http://www.twitter.com/macmixing Like my Facebook page: http://www.facebook.com/macmixing RATE, COMMENT, SUBSCRIBE! :-) ...

UAE Under-19 cricketers for ACC Premier League tour of Malaysia selected - The National
Coach Aaqib Javed seeking fresh blood for senior team after missing out on World Twenty20

Animal of the Day: Lucius Has Been Selected as the U.K.’s ‘Happiest Cat’
He’s got one blue eye, one green eye and a heart of gold. British mobile phone company O2 recently held some “cat auditions” to find “the UK’s ...

Boyd Cordner selected for Kangaroos squad
Sydney Roosters stars Michael Jennings and Boyd Cordner have capped a grand-final win with selection in the Australian squad for the World Cup ...

Redlands LNP branch blood-letting after Matt McEachan pre-selected
There was more blood-letting in the seat of Redlands on the weekend when a motorcycle instructor was named LNP candidate for the embattled electorate ...

Resources last updated: 12/1/2015 4:18:04 AM