Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
1.38/5 (3 votes)
hi friends,
i am new to asp.net ...i need a help from you people...
i am creating a page like service bill for car showroom...so while billing...i need to add item lists into a grid view... here is used drop down list to select the specific tools which will be connect to the database so if select the value it automatically shows the price,no of qty in textboxes...so in another textbox i will give the sales quantity and total price will be generate automatically by calculating unit price and sales quantity...now i need to add this detail to view in gridview....can anyone help me in this??? here the code what i did....

VB
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Partial Class ServiceInvoice
Inherits System.Web.UI.Page
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Dim dr As SqlDataReader
Dim dt As New DataTable

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim dt As New DataTable
Dim i As Integer
i = GridView1.Rows.Count

Dim gvr As New DataTable
gvr.Columns.Add(i + 1)
gvr.Columns.Add(DropDownList15.SelectedValue.ToString)
gvr.Columns.Add(DropDownList16.SelectedValue.ToString)
gvr.Columns.Add(TextBox3.Text)
gvr.Columns.Add(TextBox4.Text)

End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
dt.Columns.Add(New DataColumn(" S.NO "))
dt.Columns.Add(New DataColumn(" TOOLS "))
dt.Columns.Add(New DataColumn(" UNIT PRICE "))
dt.Columns.Add(New DataColumn(" SALES QTY "))
dt.Columns.Add(New DataColumn(" AMOUNT "))

Dim dr As DataRow
dr = dt.NewRow
dt.Rows.Add(dr)
dt.AcceptChanges()
GridView1.DataSource = dt
GridView1.DataBind()

End Sub




This is what i did but unable to add row into grid view

Thank You
Posted
Updated 1-Oct-15 10:09am
v3
Comments
phil.o 30-Sep-15 13:57pm    
What have you tried? Where are you stuck? Did you search for basic ASP.NET examples? And why .NET 1.0?
Suvendu Shekhar Giri 30-Sep-15 14:21pm    
We can't help much unless you try something of your own.
First try what you have in your mind and then if you stuck in between then come back here and ask a specific question.
mano6 1-Oct-15 7:21am    
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Partial Class ServiceInvoice
Inherits System.Web.UI.Page
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Dim dr As SqlDataReader
Dim dt As New DataTable

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim dt As New DataTable
Dim i As Integer
i = GridView1.Rows.Count

Dim gvr As New DataTable
gvr.Columns.Add(i + 1)
gvr.Columns.Add(DropDownList15.SelectedValue.ToString)
gvr.Columns.Add(DropDownList16.SelectedValue.ToString)
gvr.Columns.Add(TextBox3.Text)
gvr.Columns.Add(TextBox4.Text)

End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
dt.Columns.Add(New DataColumn(" S.NO "))
dt.Columns.Add(New DataColumn(" TOOLS "))
dt.Columns.Add(New DataColumn(" UNIT PRICE "))
dt.Columns.Add(New DataColumn(" SALES QTY "))
dt.Columns.Add(New DataColumn(" AMOUNT "))

Dim dr As DataRow
dr = dt.NewRow
dt.Rows.Add(dr)
dt.AcceptChanges()
GridView1.DataSource = dt
GridView1.DataBind()

End Sub

Thanks for your comment.

This is what i did but unable to add row into grid view
But where is the issue? What is the exact problem?
Richard Deeming 1-Oct-15 14:46pm    
None of the code you've posted is even trying to add a new row to the gridview.

Your Page_Load code creates a DataTable with a single row, and binds the grid to it. You do this every time the page loads, so when you post back to the server, you're throwing away any previous changes. The entire contents of this method should be wrapped in a If Not IsPostBack Then ... End If block.

Your Button1_Click method creates two new DataTable objects; adds some columns to one of them; and then throws them both away.

At no point do you try to add a new row to the gridview.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900