Adding data to gridview from two textboxes and then deleting them by delete button in each gridview row.


my app has 2 textboxes

if i enter data and click add button they shud be added to gridview with 2 columns

ex: custid from txtbox1 ... and custname frm txtbox2

added to gridview   with columns custid and custname

then    foreach row a delete button shud appear in gridview and on clicking it shud delete the row

can any one send me code for dis


thanks in advance

5/29/2008 6:15:00 AM 72751 articles. 3 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 42


In your Button Click Event write this code.

DataControlField dCusId;

 DataControlField dCustName;

dCusId.HeaderText = textbox1.text;

dCustName.HeaderText = textbox2.text



if you find this is helpful. Please click Mark as Answered

5/29/2008 7:15:59 AM

Try with this:

        <table cellpadding="0" cellspacing="5" class="style1">
                <td align="right">
                    <asp:TextBox ID="txtId" runat="server"></asp:TextBox>
                <td align="right">
                    <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
                    <asp:Button ID="btnAdd" runat="server" Text="Add to GridView"
                        onclick="btnAdd_Click" />
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
                <asp:BoundField DataField="ID" HeaderText="ID" />
                <asp:BoundField DataField="Name" HeaderText="Name" />
                        <asp:LinkButton ID="btnDelete" runat="server"
                            CommandArgument='<%# Eval("ID") %>' onclick="btnDelete_Click">Delete</asp:LinkButton>
    protected void btnAdd_Click(object sender, EventArgs e)
        DataTable gridTable;
        if (ViewState["gridTable"] == null)
            gridTable = new DataTable();
            DataColumn colId = new DataColumn("ID");
            colId.Unique = true;
            DataColumn colName = new DataColumn("Name");
            gridTable.Columns.AddRange(new DataColumn[] { colId, colName });
            gridTable.PrimaryKey = new DataColumn[] { colId };
            gridTable = (DataTable)ViewState["gridTable"];
        DataRow newRow = gridTable.NewRow();
        newRow["ID"] = txtId.Text;
        newRow["Name"] = txtName.Text;
        GridView1.DataSource = gridTable;
        ViewState["gridTable"] = gridTable;
    protected void btnDelete_Click(object sender, EventArgs e)
        LinkButton btnDelete = (LinkButton)sender;
        DataTable gridTable = (DataTable)ViewState["gridTable"];
        GridView1.DataSource = gridTable;
        ViewState["gridTable"] = gridTable;

5/29/2008 7:20:08 AM

gr8 !!! Yes 

thanks a million Big Smile



5/30/2008 11:42:45 AM

Similar Artilces:

How to delete controls in GridView when the delete button in a row is clicked
Hi,   I am having issues with my gridview.....i added 2 dropdown and 2 compare validators....whenever i delete a row though......the dropdown and compare validators are becoming null........thus when i click a button, it is still validating.............anyway to delete this when i click the delete button or even handle?   Please help.  ...

When I delete something in my GridView, my data is delete in the database but not on my GridView
I've got a GridView, when I click on the delete button, my data is deleted in the database but not on my GridView. When I press on F5 for refresh my browser, my datarow is deleted. So is it possible the clear the cache of the GridView ? Or is there an other solution for this problem ? Kind Regards,Joeri Pansaerts.From Bruges, Belgium :) rebind your gridview... Regards,MhaeyPlease remember to click “Mark as Answer” on the post that helps you.. =) darkcat02: rebind your gridview...  rebinding is the process u have to do if u re manually binding to the gridview. in case ...

How to determine the row number when clicking a delete button I added to a template column from a GridView control???
Hello all,I am working using the codebehinde the page with VB.NET 2005 (web application).  I have a gridview where I added a template column, inside that templated column I added a delete button.  I would like to know how could I determine which row number corresponds to the clicked button so I can delete the current record.This is what I have: Protected Sub LinkButtonDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Try Dim cmd As SqlCommand Dim objConnection As SqlConnection objConnection = New SqlConnecti...

Gridview Delete Button that Deletes data and file at the same time.
Hi :i have a gridview for my news administration. I insert news title, news details, news picture's path ( like news_image457.gif ) to my MSSQL database. I store news pictures in a Folder. ( like /mysite/newsimages )When i delete a record from the gridview, i can only delete the record from my database.But i can not delete the pictures from the Folder that i have uploaded before. How can i do that? ( please by using VB ) I mean i have to delete the news records from database and picture of the news from folder at the same time. Really sorry for my poor Engl...

delete row or delete all in Gridview?
Hi there, I have a Gridview that bind the data from the .mdb  and I want to have 2 delete buttions, one is delete a row and the other one is delete all from the database.  How do I do it in code behind in c#?  thanks a lot row delete  (temp call rowDel) all delete (temp call allDel) with rowDel: i think you should bound one column in gridview  (or datagrid)<asp:ButtonColumn... and bout allDel: i think you should use a button distinct with gridview.Becoz your required is not complex , when allDel be push you don't care...

Delete Control Button in Gridview Row at RowDataBound
I'd like to Delete a Control Button in a Gridview Row at RowDataBound, based on certain criteria.  I can locate the control during the event routine, but:Set = nothing gives "read only"Dispose =  has no effect Any suggestions on how I might be able to delete this button in this situation would be appreciated.Thanks!(PS:  one alt is to ADD the button in row created under the opposite criteria...I was hoping the get the above approach to work first, since it allows vanilla generation of the button.)  got RowDatabound....If e.Row.RowType = D...

Error with Gridview when i delete the row that have only one row in gridview
 Dear all, i develop with 2005 and use gridview and set enable deleteing =true. I can delete record in gridview properly but when gridveiw has only one row and then i'm clike delete button , the error occurs :   Server Error in '/it' Application. Specified argument was out of the range of valid values.Parameter name: value Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.ArgumentOutOfRangeExce...

In a gridview, can I programatically control display of edit/delete buttons for selected row?
Hi there, I'm sure this is something fairly straight forward but I'm only just getting used to working with gridviews so please help me, I am displaying the select button on my gridview, and on the SelectedIndexChanged event I would like to add (or make visible) the edit and delete buttons just for the selected row - can I do this?  All help appreciated, JoH are you using template field with button / link button for edit or delete button  ?Thanx, [KaushaL] || BloG || Profile || Microsoft MVP"I would love to change the world, but they won’t give me ...

Gridview Delete not Deleting
I am trying to use a command button to delete a row from a gridview. When I click the command button though, the page posts but my record is still there... no errors, just nothing seems to happen. Below is what I think is the relevant code, let me know if you need to see anything else.  I'm kinda new to working with gridview objects, it would be nice if I could see what SQL command is acctually ran... maybe there are other things I can check too, I'm just not sure how.   <asp:GridView ID="GridView1" runat="server" AllowSorting="True"&nbs...

Data Controls insert rows into gridview then insert rows from gridview into SQL Table
Hello there, I'm still new at performing miracles with code . Currently I am having trouble with my latest coding adventure I have a web application which records jobs and labour assigned to jobs. The issue in particular I'm having is the way in which labour is to be assigned. I want to use standard controls (Textbox, Dropdownlist) to record the values into a gridview (ie,put multiple rows into the gridview using the controls). Then, when all the inserting is complete, the user clicks a submit button to insert all the rows from the gridview into a database table. The reason for...

Adding row (one at a time) in gridview on a button click. And cells of added row should contain controls like DROPDOWN LIST or TEXT BOX.
Dear Friends, I am in great need for the solution/hints/guidance of my requirement, if anyone can help with.  Let me explain what I need."I need a Gridview control on a webpage having following 5 columns/fields.     Column 1: It just has a "+" button in its header only (other cells for this column is empty)    Column 2: The Column header here is "FIELD" and  it should contain dropdown list (which is populated from some database)    Column 3: The Column header here is "Operator" and  it should ...

after pressing delete button in gridview, the gridview disappear :/
well i have a gridview. when i press the delete button , it delete the row but on page postback there is no gridview ?! then i refresh again and it appear. :D   here is my selectcommand :if (string.IsNullOrEmpty(ImageName)) {DefaultPhotoParser df1 = new DefaultPhotoParser(); string foo = df1.GetDefaultphoto(nick);string DefImageName = System.IO.Path.GetFileNameWithoutExtension(foo); SqlDataSource1.SelectCommand = "select * from tb_comments where Picture_ID = @pic_id";SqlDataSource1.SelectParameters.Add("pic_id", DefImageName); } else {string AlternativeI...

Buttons to delete a row in a gridview?
Hey guys, I have a gridview with a "revise" button, and a "remove" button.  Each row in the gridview has a unique id.  I need to make it delete the current row when the remove button is pressed, so far i bound the uniqueID column to the "CommandName" of the button.  and then my code is: Dim btn3 As Button = CType(GridView1.FindControl("Button3"), Button) SqlDataSource1.DeleteCommand = "DELETE FROM db_UserListings WHERE (UniqueID =" & btn3.CommandName & ")" SqlDataSource1.Delete()   This always retu...

Delete a Row From A GridView Control
Well it is not just an ordinary delete. I have a Gridview which I populated manually. Then I need to delete a row which will be selected using a checkbox inside the gridview. I cant seem to find the way to just remove the specific row. I have already taken the rowIndex, but Gridview doesnt seem to allow me to delete a row unless I remove from a dataset or so. Anyhelp would be appreciated. Thanks - Mike use the property "DataKeyName" of the GridView. get the index and delete/remove the perticular row which you got through datakeyname property. and again bind your GridView. Thanx, [K...

Web resources about - Adding data to gridview from two textboxes and then deleting them by delete button in each gridview row. -

Notes Plus on the App Store on iTunes
Get Notes Plus on the App Store. See screenshots and ratings, and read customer reviews.

Training - Algodoo
Navigation Home For Fun Algodoo Play Algodoo Physics Scenes Demo Buy For Education Algodoo for Education Lessons User stories Solutions Demo ...

Automated Test Design
... tests along with doing ET. Here's my take on a UI test for Alan's app: Open the page Check that text "Total" exists. Check that the 6 textboxes ...

Quick Answers - CodeProject
Questions - Free source code and tutorials for Software developers and Architects.; Updated: 11 Jul 2012

Cyprus By Bus Route Planner - Find your bus journey in Cyprus
Cyprus By Bus route planner for finding the best possible bus route between two bus stops in Cyprus. Based on origin bus stop, destination bus ...

Issues - gwen - GUI system aimed at games - Google Project Hosting
My favorites ▼ - Sign in gwen GUI system aimed at games Project Home Downloads Wiki Issues Source New issue Search Search within: All issues ...

ASP.NET Web Forms DynamicData FieldTemplates for DbGeography Spatial Types
... Those templates are simple. Here's the Edit example. You might say, hang on, this is just a text box! I thought we weren't using TextBoxes? ...

uCan Post WordPress Plugin Demo - Cartpauj & iComNow
This is a demo for the uCan Post WordPress plugin by cartpauj. This plugin lets users create posts and site content without having to access ...

Jennifer Semtner [ Web Designer / Developer ] » CSS
If you're using Grails and the Grails UI plugin's autocomplete feature, you may have noticed all of your textboxes have disappeared in Chrome ...

Resources last updated: 1/20/2016 2:39:44 AM