how to add multiple rows in a data table against a button click event

how to add multiple rows in a data table against a button click event, and then show it in a gridview


mahmood
0
AhmadRock51
8/5/2008 4:01:49 AM
asp.net.getting-started 91979 articles. 0 followers. Follow

4 Replies
167 Views

Similar Articles

[PageSpeed] 42

0
vik20000in
8/5/2008 4:34:04 AM

Refer to this link. 

http://bytes.com/forum/thread524698.html 

Hope this helps.

 

0
santa_1975
8/5/2008 4:58:38 AM

Hi,
Use the following code (VB.Net)

 

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

        'Assign DataTable
        Dim dtTable As DataTable = Nothing

        'Add Columns to DataTable
        dtTable.Columns.Add("Column1")
        dtTable.Columns.Add("Column2")

        'Create a new DataRow for dtTable
        Dim dr1 As DataRow = dtTable.NewRow

        'Assign column values for the row
        dr1("Column1") = "Value"
        dr1("Column2") = "Value"

        'Add the datarow to DataTable
        dtTable.Rows.Add(dr1)

        'For Second Row...
        Dim dr2 As DataRow = dtTable.NewRow
        dr2("Column1") = "Value"
        dr2("Column2") = "Value"
        dtTable.Rows.Add(dr2)

        'Bind the dataTable to Gridview.
        GridView1.DataSource = dtTable

    End Sub
   ../Saravanan
0
saravananr
8/5/2008 8:44:45 AM

Once you have describe datatable then for ever new row you have to create the new row and add it to the datatable by doing this you can add n number of rows into the datatable and code is already posted by one of the member.


ROAMER!

if (myReply.Equals(YourAnswer))
{
MarkThisThread = "Answerd";
}
0
ROAMER
8/5/2008 8:49:45 AM
Reply:

Similar Artilces:

Add a row to table Dynamically for each click of Add Button
Dear All, I need to add one row to the existing table each time when I click Add button. I tried with the below code. It adds one row for the first click and for the next clicks it does nothing.. could you please recify where I am wrong? private void Button1_Click(object sender, System.EventArgs e){     int cnt = Convert.ToInt32(Session[COUNT]) + 1;    HtmlTableRow tRow1 = new HtmlTableRow();tRow1.ID = "rowID" + cnt;tblCR.Rows.Add(tRow1);HtmlTableCell tCel1 = new HtmlTableCell();tCel1.InnerText  = "aaa";tRow1.Cells....

add data from multiple rows in table to one row in gridview
 heya is there any way of adding data from multiple rows in table to one row in gridview. eg. ipc                 column 1 ,            2 ,                       3,                 4  1,    11111                 33                  &nbs...

Add row to table with table.row.add()
Everytime I click on a button I want to add a tableRow to a table like this:        TextBox TB = new TextBox();                TableCell Cell = new TableCell();        Cell.Controls.Add(TB);        TableRow Row = new TableRow();        Row.Cells.Add(Cell);        table.Rows.Add(Row);It works the first time, but when I click the button again the last r...

Add table rows when button is clicked
I want to be able to add table rows every time a user clicks a button. I tried something but it just adds one row and then it keeps adding the same one and not adding other. Any help appreciated How are you adding the rows to the table? Could you post your code? BrianBrian"Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4). The code is this Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ...

Button clicked
I'm using the following VB code per DW .Net docs to try to get the name of the button I've clicked on in a Win Forms datawindow control. Dim buttonClicked As String buttonClicked = dw_setup.ObjectUnderMouse.Gob.Name.ToString() If buttonClicked = "b_1" Then MsgBox("Button 1 was Clicked!") ElseIf buttonClicked = "b_2" Then MsgBox("Button 2 was clicked!") ElseIf buttonClicked = "b_3" Then MsgBox("Button 3 was clicked!") End If It always returns "DataWindow" instead of the button name. It d...

Add rows to GridView on Button Click Event
Hai All, I have one gridview control and some textboxes are placed inside the update panel in my form. What I want is If I click the button (Add) the value of the textboxes are added to the gridview. How do i implement this? For example , Textbox1 = 'Value1', Textbox2 = 'Value2', Textbox3 = 'Value3', Textbox4 = 'Value4'. This four values are added to the gridview. Hi,I haven't tried it yet but i think this would do the trick, Try it this way            DataTable dt = new DataTable();...

How could add a javascript function to a button click event as a part of its click event handler?
Hi, The title might be confusing. What I want is simply two pages, Page1 and Page2, when I click on a linkbutton on page1, page2 pops up. I used to use a little bit of javascript to do this, and it worked just fine. I just added the following line of code to the Page_Load event of Page1:   protected void Page_Load(object sender, EventArgs e) { LinkButton1.Attributs.Add("onclick","javacript:window.open('Page2.aspx',null,'height=500,width=650,status=no,resizable=yes,scrollbars=yes,toolbar=no,location=no,menubar=no')"); } But now, I have...

how to add new blank row in table on button click
hi, can someone help me, i have problem to insert a new blank row in table on button click. i tried many links that show how to add row in table using database but it's not working. i don't want to use database. my situation is simple. i have table with 2 columns. everytime user want to add data, user will click "insert" button & new row will be added. then user will add data to the table. i dont want to retrieve any data from database or insert data to database. please help. tQ This has a sample: http://www.w3schools.com/js/tryit.asp?filename=try_dom_table_in...

How can we add a new row to the gridview in the button click event
I have a button,3 textboxes and a gridview.Iam adding the textboxes to the gridview and iam binding a datatable . Now my question is that how can i add a new row to my gridview in the button click event. in the button click event, if u update the datatable, the grid view should read/refresh  the new rows into the page. what are u thring to  do , you want to do this thorguh to UI . . if so what is the use of text boxes.  Sunil Okay that's not difficult but the consequences are. you may need to write a good deal of code to add row manange the user created row.&...

What to get the confirm msg on button click event stored data...
How can i confirm that the data entered within the standard controls and after the click event for the particular sql query the data is been stored in the database tables (depending insert,update,delete).I want to display the different messages on the click event and that after the changes made into the tables.How can i do it ?? I m using ASP.Net with C#,VB and the sql server to store data.I also want to know where are the database tables exactly get stored which are made in the Microsoft SQL Server Management Studio Express.I want to use as the existing item in .Net but could not find..&nbs...

Table Cell click event
Hi, I used to have a custom server control inhirted from TableCell control to implement click event in VS.NET 2003.  When I use the custom control in VS.NET 2003 Web application (dynamically adding to table object), everything works fine.  Below is the code from 2003 project, and everything works good in this way.                 Dim c As New MyCustomTableCell                  c.Width = 200     &nb...

how to add a new row into a datatable each time a button click event is fired
how to add a new row into a database each time a button click event is fired with values selected in a dropdownlist     its very urgent please give me a relevent help Hi  U can add  a row to data table using the following code DataTable dt; DataRow dr = dt.NewRow(); //If u add any data in cells of new row use the next line of code //dr[0] = "SampleData"; dt.Rows.Add(dr);    HTHPlease: Don't forget to click "Mark as Answer" on the post that helped you. Psalm 23 : 1-2 1 The LORD is my shepherd, I shall not be in want. 2 He mak...

need a button click event that references data table and redirects user??
I am using VWD, Sql Express and C Sharp. On my website users, can view a list of footballers binded to a data  list. In the item template is a button which when clicked adds the footballer to a junction table called favourites.This has two fields UserID and Footballer ID. This allows visitors to store their favourite players once the user is logged in.  In the button click event I have included the code below which makes the button disappear if it has been selected already. Instead what I would like to happen is the following, a, When cli...

How to add multiple instances of web usercontrol on page on button click event ???
How to add multiple instances of web usercontrol on page on button click event ??? ThanksASP.NET 3.5VISUAL STUDIO 2008 PROMS SQL SERVER 2005 You can do Control1 control1Instance = (Control1)Page.LoadControl(@"Controls\Control1.ascx"); Control2 control2Instance = (Control2)Page.LoadControl(@"Controls\Control2.ascx"); Keep in mind to pass the correct path of the control. Here I have assumed that I have the Control1.ascx and Control2.ascx placed in the Controls folder. Please mark answer if it solves ur problem. ThanksAchintya JhaMCAD I want on button c...

Web resources about - how to add multiple rows in a data table against a button click event - asp.net.getting-started

Code division multiple access - Wikipedia, the free encyclopedia
Code division multiple access ( CDMA ) is a channel access method used by various radio communication technologies. It should not be confused ...

Police officer Daniel Holtzclaw guilty of raping multiple women
For months, accusers, authorities and now an Oklahoma jury say, police officer Daniel Holtzclaw preyed on vulnerable women.

Facebook Tweaks Power Editor for Users With Multiple Ad Accounts
Facebook rolled out a new feature for its Power Editor that should greatly speed up the process for users with multiple advertising accounts. ...

Rockies trade rumors: Carlos Gonzalez could fit on multiple teams
The oft-injured slugger has two years left on his deal. There are three types of teams in the NL West. Subdividing five teams into three categories ...

Google Ventures reportedly closed its European fund after multiple stalled deals
Earlier this week, Google Ventures announced it was closing down its dedicated European fund . It had been assigned $125 million to invest, but ...

OKC Police Officer Found Guilty On Multiple Counts Of Raping Black Women
Former Oklahoma City Police officer Daniel Holtzclaw will be going to prison for a very, very long time. After deliberating for well over 45 ...

Big Pharma bro arrested by federal agents in overnight raid, faces multiple investigations
Big Pharma bro Martin Shkreli gained international notoriety when his company bought the rights to Daraprim—a drug used to treat parasitic infections, ...

Report: Robert Nkemdiche Fell From A 4th-Story Window And Suffered "Multiple Cuts"
Probable top-five NFL draft pick and Ole Miss star Robert Nkemdiche reportedly fell from the 4th floor of a building, and suffered “multiple ...

Google's Chromecast Audio beams music to multiple rooms
If you're been eyeing Google's Chromecast Audio for your holiday shopping spree, Mountain View just added some new features to sweeten the deal. ...

Apple Loop: Multiple iPhone 7 Designs Leak, Tim Cook's $24 Billion NFL Dream, Apple Fights Microsoft
This week’s Apple Loop includes five major design leaks around the iPhone 7, thoughts on the viability of the iPhone 6C, a discussion on 'peak ...

Resources last updated: 12/20/2015 3:45:25 PM