tag:blogger.com,1999:blog-5557928922282685284.post692294370068428748..comments2023-10-19T09:47:02.908-07:00Comments on DotNetOcean: Adding Dynamic Rows in ASP.Net GridView Control with TextBoxesAnonymoushttp://www.blogger.com/profile/04730238970222809678noreply@blogger.comBlogger12125tag:blogger.com,1999:blog-5557928922282685284.post-7500122093313834812014-06-05T08:21:50.993-07:002014-06-05T08:21:50.993-07:00Hie I am trying to do this in using vb. and would ...Hie I am trying to do this in using vb. and would also like to calculate totals from the textboxes here is my code so far. Please help.<br /><br />Imports System.Data<br />Public Class Trial<br /> Inherits System.Web.UI.Page<br /><br /> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load<br /> If Not Page.IsPostBack Then<br /> SetInitialRow()<br /> End If<br /> End Sub<br /><br /> Protected Sub Gridview1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles Gridview1.SelectedIndexChanged<br /><br /> End Sub<br /><br /> Private Sub SetInitialRow()<br /><br /> Dim dt As New DataTable()<br /> Dim dr As DataRow = Nothing<br /> dt.Columns.Add(New DataColumn("RowNumber", GetType(String)))<br /> dt.Columns.Add(New DataColumn("Column1", GetType(String)))<br /> dt.Columns.Add(New DataColumn("Column2", GetType(String)))<br /> dt.Columns.Add(New DataColumn("Column3", GetType(String)))<br /> dr = dt.NewRow()<br /> dr("RowNumber") = 1<br /> dr("Column1") = String.Empty<br /> dr("Column2") = String.Empty<br /> dr("Column3") = String.Empty<br /> dt.Rows.Add(dr)<br /> ViewState("CurrentTable") = dt<br /> Gridview1.DataSource = dt<br /> Gridview1.DataBind()<br /><br /> End Sub<br /><br /><br /> Private Sub AddNewRowToGrid()<br /><br /> Dim rowIndex As Integer = 0<br /><br /> If ViewState("CurrentTable") IsNot Nothing Then<br /> Dim dtCurrentTable As DataTable = DirectCast(ViewState("CurrentTable"), DataTable)<br /> Dim drCurrentRow As DataRow = Nothing<br /><br /> If dtCurrentTable.Rows.Count > 0 Then<br /> For i As Integer = 1 To dtCurrentTable.Rows.Count<br /> Dim box1 As TextBox = DirectCast(Gridview1.Rows(rowIndex).Cells(1).FindControl("TextBox1"), TextBox)<br /> Dim box2 As TextBox = DirectCast(Gridview1.Rows(rowIndex).Cells(2).FindControl("TextBox2"), TextBox)<br /> Dim box3 As TextBox = DirectCast(Gridview1.Rows(rowIndex).Cells(3).FindControl("TextBox3"), TextBox)<br /> drCurrentRow = dtCurrentTable.NewRow()<br /> drCurrentRow("RowNumber") = i + 1<br /> dtCurrentTable.Rows(i - 1)("Column1") = box1.Text<br /> dtCurrentTable.Rows(i - 1)("Column2") = box2.Text<br /> dtCurrentTable.Rows(i - 1)("Column3") = box3.Text<br /> rowIndex += 1<br /> Next<br /><br /> dtCurrentTable.Rows.Add(drCurrentRow)<br /> ViewState("CurrentTable") = dtCurrentTable<br /> Gridview1.DataSource = dtCurrentTable<br /> Gridview1.DataBind()<br /><br /> End If<br /> Else<br /> Response.Write("ViewState is null")<br /> End If<br /> SetPreviousData()<br /><br /> End Sub<br /><br /> Private Sub SetPreviousData()<br /><br /> Dim rowIndex As Integer = 0<br /><br /> If ViewState("CurrentTable") IsNot Nothing Then<br /> Dim dt As DataTable = DirectCast(ViewState("CurrentTable"), DataTable)<br /> If dt.Rows.Count > 0 Then<br /> For i As Integer = 0 To dt.Rows.Count - 1<br /> Dim box1 As TextBox = DirectCast(Gridview1.Rows(rowIndex).Cells(1).FindControl("TextBox1"), TextBox)<br /> Dim box2 As TextBox = DirectCast(Gridview1.Rows(rowIndex).Cells(2).FindControl("TextBox2"), TextBox)<br /> Dim box3 As TextBox = DirectCast(Gridview1.Rows(rowIndex).Cells(3).FindControl("TextBox3"), TextBox)<br /> box1.Text = dt.Rows(i)("Column1").ToString()<br /> box2.Text = dt.Rows(i)("Column2").ToString()<br /> box3.Text = dt.Rows(i)("Column3").ToString()<br /> rowIndex += 1<br /> Next<br /> End If<br /> End If<br /><br /> End Sub<br /><br /> Protected Sub ButtonAdd_Click(sender As Object, e As EventArgs)<br /><br /> AddNewRowToGrid()<br /><br /> End Sub<br /><br />End Class<br /><br /><br /><br />Anonymoushttps://www.blogger.com/profile/03477667000802633904noreply@blogger.comtag:blogger.com,1999:blog-5557928922282685284.post-79095086267459293272013-07-16T12:03:47.742-07:002013-07-16T12:03:47.742-07:00 Hi, I am working on project on ASP.NET and Oracle... Hi, I am working on project on ASP.NET and Oracle 11g Express. I need to search a table, retrieve data and populate a gridview or list view whichever is more efficient. Any ideas i will really appreciate. Code sample will even be more handy. ThanksAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-5557928922282685284.post-88496997453168666232012-12-05T18:01:47.808-08:002012-12-05T18:01:47.808-08:00hi,
can you help me??how about i want to make 12r...hi,<br /><br />can you help me??how about i want to make 12rows at first time load page.then only user add new 1 row..i tried but it failed at the set previous data function.all the 12 rows data is gone!please help me.i really need your help.urgent!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5557928922282685284.post-76320707279975210132012-11-14T05:13:24.233-08:002012-11-14T05:13:24.233-08:00Thank you :)Thank you :)Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5557928922282685284.post-52160897279728018522012-11-13T21:39:24.244-08:002012-11-13T21:39:24.244-08:00http://shibashishdotnetocean.blogspot.in/2012/08/a...http://shibashishdotnetocean.blogspot.in/2012/08/adding-and-removing-dynamic-rows-in.html <br />check this one<br /> regards <br /> shibashish mohantyAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-5557928922282685284.post-88090974832753428032012-11-13T08:22:41.178-08:002012-11-13T08:22:41.178-08:00That's au very nice article, but I have a prob...That's au very nice article, but I have a problem when I display Data and I want to Add new Row.<br />Can you help me ? <br />Thank you :)Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5557928922282685284.post-129016488827642412012-07-15T09:20:04.208-07:002012-07-15T09:20:04.208-07:00Thank you... nice one...Thank you... nice one...Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5557928922282685284.post-73271532483374333962012-07-06T21:40:18.568-07:002012-07-06T21:40:18.568-07:00if you want to save data in database then go for t...if you want to save data in database then go for this link<br />http://shibashishdotnetocean.blogspot.in/2012/02/save-dynamic-textbox-values-from.htmlAnonymoushttps://www.blogger.com/profile/04730238970222809678noreply@blogger.comtag:blogger.com,1999:blog-5557928922282685284.post-28036130447920097922012-07-06T21:37:59.997-07:002012-07-06T21:37:59.997-07:00sure i will work for that and shortly i am going t...sure i will work for that and shortly i am going to post that one thanks a lotAnonymoushttps://www.blogger.com/profile/04730238970222809678noreply@blogger.comtag:blogger.com,1999:blog-5557928922282685284.post-752805724893957362012-07-06T20:28:43.186-07:002012-07-06T20:28:43.186-07:00Dear shivashish.
I am tryinging to add a edit, up...Dear shivashish.<br /><br />I am tryinging to add a edit, update and delete button at run time and fetch the data from database but did not success.<br /><br />please let me know the code for this.<br /><br />one thing again as you have given the code insert the row at run time but how we can insert the data with this text box using insert button.<br /><br />Thanks and regards.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5557928922282685284.post-30053981481133355242012-07-06T20:23:53.183-07:002012-07-06T20:23:53.183-07:00Good morning and thank you so much shivashish
Thi...Good morning and thank you so much shivashish<br /><br />This code is running perfectly.<br /><br />YOu have mentioned the code which is very easy to understand.<br /><br />I really appreciate.<br /><br />Thank you so much again.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5557928922282685284.post-4399471242007211142012-07-06T20:20:52.775-07:002012-07-06T20:20:52.775-07:00DFDFDDFDFDAnonymousnoreply@blogger.com