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
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.PageProtected 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.ToStringIf chk1.Checked Then
dn = Dt.NewRow
dn("Name") = strname1dn("Profession") = profDt.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.DataRowFor 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.ToStringIf chk1.Checked Then
dn = Dt.NewRow
dn("Name") = strname1dn("Profession") = profDt.Rows.Add(dn)
End If
Next
GridView2.DataSource = Dt
GridView2.DataBind()
Session("DT") = DtEnd 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.DataTableIf Session("DT") Is Nothing Then
Dt.Columns.Add("Name")Dt.Columns.Add("Profession")
Session("DT") = DtGridView2.DataSource = Dt
GridView2.DataBind()
Else
Dt = CType(Session("DT"), Data.DataTable)Dt.Rows.Clear()
Session("DT") = DtGridView2.DataSource = Dt
GridView2.DataBind()
End If
End SubEnd 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 Pagetitle> 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.
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.
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.
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
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.