Add Duplicate Row & Columns OnClick C#

Mar 28, 2011

I Have an ASP:Table that has a row with cells in I need to be able to add a row to this by clicking the Add button at the end which duplicates the existing row. My Table code

<asp:Table ID="Table1" runat="server" Height="50%" Width="100%">
<asp:TableHeaderRow CssClass="lblrow2" HorizontalAlign="Left" BackColor="AliceBlue">
<asp:TableHeaderCell ID="haccountref">Account Ref:</asp:TableHeaderCell>
<asp:TableHeaderCell ID="hproduct">Product</asp:TableHeaderCell>
<asp:TableHeaderCell ID="hqty">Qty:</asp:TableHeaderCell>
<asp:TableHeaderCell ID="hunitprice">Unit Price:</asp:TableHeaderCell>
<asp:TableHeaderCell ID="hdiscount">Discount:</asp:TableHeaderCell>
<asp:TableHeaderCell ID="htotal">Total Line Amount:</asp:TableHeaderCell>
</asp:TableHeaderRow>
<asp:TableRow CssClass="r1">
<asp:TableCell><asp:TextBox ID="vaccountref" ReadOnly="True" runat="server"></asp:TextBox></asp:TableCell>
<asp:TableCell><asp:DropDownList runat="server" ID="vproduct"></asp:DropDownList></asp:TableCell>
<asp:TableCell><input id="Qty" type="text" /></asp:TableCell>
<asp:TableCell><input id="Unit Price" type="text" /></asp:TableCell>
<asp:TableCell><input id="Discount" type="text" /></asp:TableCell>
<asp:TableCell><input id="Total" type="text" /></asp:TableCell>
<asp:TableCell><input id="Button1" type="image" src="plusButton.png" value="button" /></asp:TableCell>
</asp:TableRow>
</asp:Table>

My c# code behind - I get no errors but no duplicate row

protected void Button1_Click(object sender, System.EventArgs e)
{
// Total number of rows.
int rowCnt;
// Current row count.
int rowCtr;
// Total number of cells per row (columns).
int cellCtr;
// Current cell counter
int cellCnt;
rowCnt = int.Parse(TextBox1.Text);
cellCnt = int.Parse(TextBox2.Text);
for (rowCtr = 1; rowCtr <= rowCnt; rowCtr++)
{
// Create new row and add it to the table.
TableRow tRow = new TableRow();
Table1.Rows.Add(tRow);
for (cellCtr = 1; cellCtr <= cellCnt; cellCtr++)
{
// Create a new cell and add it to the row.
TableCell tCell = new TableCell();
tCell.Text = "Row " + rowCtr + ", Cell " + cellCtr;
tRow.Cells.Add(tCell);
}
}
}

View 1 Replies


Similar Messages:

DataSource Controls :: SQL Statement - Don't Want To Return Duplicate Columns

Mar 11, 2010

I have the following simple stored procedure:

ALTER PROCEDURE GetadiByPhiNo

@PhiNo int

SELECT adirefno, adidescription

FROM aditable

WHERE adiphino = @PhiNo

Here is an example of data returned:

1 Skin diesease

2 Cough

3 Cough

4 Rash

You notice "Cough" is in the adidescription column twice. I would like to return only one row for adidescription with the same value. So what I want returned is this:

1 Skin diesease

2 Cough

4 Rash

View 8 Replies

Data Controls :: GridView Showing Duplicate Columns?

May 7, 2015

when i populate data from datatable or dataset into gridview ,the gridview has boundfield then the gridview is displaying the same table repeated twice and displayed in one table.
 
but when i do not use any boundfield it is displaying correctly how to solve this issue .

SqlDataAdapter adp = new SqlDataAdapter("select * from dumb", conn);
DataTable dt = new DataTable();
adp.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
  <asp:GridView ID="GridView1" runat="server">

[Code]......

View 1 Replies

SQL Reporting :: Matrix Date Columns Are Showing Duplicate Days?

Dec 17, 2010

I am building a report using the Matrix for the first time. It's showing duplicate days across the columns and I can't figure how to filter so that a unique day appears.

I have 2 row groups, quality_code and product_name, and 1 column group repair_dt. In the Date column I showing count of serial_id - associated with product_name this is what I am getting

12/15/2010 12/16/2010 12/17/2010 12/15/2010 12/17/2010
code A
product 1 1 2 0 0 1

View 2 Replies

Forms Data Controls :: Delete One Duplicate Record Of Many Duplicate Records

Mar 15, 2010

I have a gridview with delete buttons for each record (I've used AccessDataSource). I have loaded the data in and have many duplicate records.

I just want to use the delete button delete each duplicate record while remains many duplicate records. For example:

I used the following query to load in duplicate records:

SELECT * FROM TableA WHERE ([ControlA] IN (SELECT [ControlA] FROM TableA GROUP BY [ControlA] HAVING (COUNT [ControlA]) > 1)))

ID ControlA PIN# FaceValue Date
delete 76637 128232 1234 5 6/4/2006
delete 72722 128232 1234 5 6/4/2006
delete 76638 234567 2345 10 7/3/2006
delete 72723 234567 2345 10 7/3/2006

What is the query to delete single duplicate record instead of deleting all duplicate records?

View 25 Replies

Parent Columns And Child Columns Don't Have Type-matching Columns

Aug 3, 2010

i am making relation between two datatables and m getting this error

in this ds.Tables(0).Columns("In_ID") datatype is string
ds.Tables(1).Columns("row_id") datatype is integer

how i do the type casting here to make dataset relation

ds.Relations.Add("Rel_1", ds.Tables(0).Columns("In_ID"), ds.Tables(1).Columns("row_id"), True)

View 3 Replies

C# - Stop Setting Onclick Event For LinkButton If No OnClick Event Was Explicitly Defined?

Feb 25, 2010

How do I setup a default setting so that if I do not set an OnClick (i.e the asp.net OnClick attribute) explicitly for an asp:LinkButton tag, it will not render an onclick(html attribute for javascript) attribute client side? By default, asp.net adds an onclick='doPostBack....' for the LinkButton.

Case for use:

There is a LinkButton tag on the page. For this page, if the user has one friend, I only want to run client side code if the button is clicked and would not for any reason want to make a post back. If the user has more than one friend I would want a click to trigger a postback.

Using any asp.net Ajaxtoolkit

Dynamically switching the control type (i.e. if friends == 1 use a asp:Hyperlink)

-I want to avoid this because it is not scalable. There might be many cases where I want an asp:Link tag to do a postback or to not do a postback depending on the user context or user attributes Using OnClientClick (I am using jQuery would like to avoid this)

View 2 Replies

ADO.NET :: Getting SQL Duplicate Key Exception With No Duplicate Key?

Jan 20, 2011

Regarding Linq to SQL with .SQLEXPRESS and VS2010 on Windows 7, I am trying to add a list of entries to an empty table that I have confirmed programmatically does not have duplicate keys. Some info about the situation:Note: The key strings have Unicode characters (English and Chinese mixed).

View 6 Replies

DataSource Controls :: Removing Duplicates From Two Similar Columns Or Any Other Columns In A Database Schema

Apr 21, 2010

I have two columns first name and last name , that have duplicates, how can i remove the duplicates and only leave the distinct members intact?

View 6 Replies

C# - GridView - Columns.Insert() Cause Data To Vanish On Postback But Columns.Add() Works OK?

Oct 13, 2010

I have a GridView that has several dynamic columns (I do not know how many at design time and it could be 0-12 columns, hence need for dynamic columns). I have the columns in the grid and data bound to them - works great. There are other standard, design-time TemplateField columns with TextBox controls in them. These are bound with values that the user can edit. The grid is posted back via a Submit button. My question is "Why does gv.Columns.Insert() cause all my TextBox data to be null on Postback, but gv.Columns.Add() works like a champ?"

protected void BuildColumns()
{
// The first column to begin to insert the columns in the GridView
int columnIndex = 5;
BoundField aoColumn = new BoundField();
aoColumn.HeaderText = "New Column 1";
gvMyGrid.Columns.Insert(columnIndex, aoColumn); // kills txtQuantity.Text on postback
gvMyGrid.Columns.Add(aoColumn); // works fine
columnIndex++;
foreach (MyEntity my in _myEntityCollection)
{
BoundField myColumn = new BoundField();
myColumn.HeaderText = String.Format("{0:d}", my.StartDate);
gvMyGrid.Columns.Insert(columnIndex, myColumn);
columnIndex++;
}
}

I then go on to assign values to these BoundFields in the _RowDataBound method and all of this works great. However, when I post back and try to reference some TextBox and they are all null. And yes, I have the BuildColumns() call wrapped in if (!IsPostBack) on Page_Load. Of course I would like to use .Insert() so that the columns can go in the proper location and not at the end of the Columns array.

View 1 Replies

Forms Data Controls :: Create An ASP Grid With Dynamic Columns With An Ability To Freeze Columns And Rows

Sep 20, 2010

I created a gridview that is made up of 4 gridviews and using a stored procedure to populate it. I create columns at runtime because the number of columns changes all the time.To make the grids editable I am adding template fields at runtime as I create the columns, this is to ensure that a user is able to edit the cells and some foot values update. Reason why I have four grids is to freeze rows and columns like in excel using javascript. The problem is that performance is very bad especially in IE, the grids take a long time to load. I am not sure if this is caused by the data load or the creation of text boxes. see some of the code below for my _aspx page:

[Code]....

View 1 Replies

Forms Data Controls :: In Page User Able To Select Gridview Columns And It Will Hide Remaining Columns

Mar 18, 2010

in asp.net page user able to select gridview Columns, and it will hide remaining columns and that selection done by check box with column list bellow is Image link , what exactly I am looking for [URL] it look bellow after selection of column done [URL]

View 1 Replies

Entity Framework: Substituting Primary Columns For Foreign Key Columns

Jun 30, 2010

I've created a new ASP.NET website. I've generated an Entity Data Model from my database and have dropped a entitydatasource and gridview onto my page and wired up the gridview to pull from the entitydatasource. Now I get columns like this: id extension prefix did_flag len ten_id restriction_class_id sfc_id name_display building_id floor room phone_id department_id

In each case where the item is named something_id this reflects a foreign key relationship in the database - and I did choose to have the EDM expose foreign key relationships. I'd like to make it so the gridview pulls in the values for these foreign keys rather than just showing the ID numbers - so, for example, department_id might have a value of "101" right now but it should pull from the department table "Marketing".

View 1 Replies

Hide Columns In GridView With Auto - Generated Columns?

Jan 19, 2010

GridView1.Columns.Count is always zero even SqlDataSource1.DataBind();

But Grid is ok I can do

for (int i = 0; i < GridView1.HeaderRow.Cells.Count;i++)

I rename request headers here but

GridView1.Columns[i].Visible = false;

I can't use it because of GridView1.Columns.Count is 0. So how can I hide them ?

View 5 Replies

Show Several Columns In Datasource As Autogenerate Columns In Gridview?

Jan 27, 2011

I have a datasource, which includes many columns, idealy, I need use a gridview to show:

1) first 3 columns: template fields, these fields depends on values in some columns of datasource. I use template fields, hard coded. works fine.

2) the other columns. This is I do not know how to do it. In the data source, there are about 10-20 columns data, each time, the # of columns of the data varies. idealy, I need show each of them as a seperated column in gridview. The entire data source may have 30 columns, but some of them are used in 1), and I only want show these 10-20 columns in gridview. Some columns in data source, I may not use them at all. is there a way to do this? or have to seperate them as a detail view style UI?

View 1 Replies

AJAX :: How To Display 4 Columns And It's Columns Name In AutoCompleteExtender Control

Feb 9, 2010

I am developing an web application. One of this form has a textbox. When the user enter chars i need to fetch the records from db and display as 4 columns in AUTOCOMPLETEEXTENDER CONTROL TOOL KIT and it's column name also. When the user click any one of the row, i need to get the 2nd clicked column name and display it in textbox.

how to display 4 columns and it column name in autocompleteextender control?

View 1 Replies

SQL Reporting :: Arrange The Report Parameters In Three Columns Instead Of Two Columns?

Feb 21, 2010

I am trying to arrange the report parameters in three columns instead of two columns. I have about 13 report parameters . Is there a setting anywhere to be done.

View 6 Replies

C# - Avoid Double Columns (predefined Columns + Selectcommand)?

Mar 17, 2011

I have a gridview with predefined columns and a selectcommand. Why do I get the columns twice? I want to keep the predefined columns and the selectcommand, but avoid getting the columns double.

<asp:GridView ID="gvMeldingen" runat="server"
AllowSorting="True" DataSourceID="MyDataSource"
onselectedindexchanged="GridView_SelectedIndexChanged"[code].....

View 1 Replies

Table Colspan Span All Columns Regardless Of # Of Columns

Mar 5, 2010

I'm creating a table in an asp.net code behind dynamically, and I want to have a footer row that only has 2 cells. The first should span all the columns in the table-1. Is there some way other then keeping track of the # of columns in the table manually for me to set the colspan to be # of all the columns in the table-1? Preferably a HTML or CSS solution?

View 2 Replies

Averaging Columns In A Table - Ignoring Certain Columns

Feb 21, 2011

I've the following code which successfully makes an average for all the columns from a table. What I need to do though is ignore certain columns in this equation.

Dim totalNumber as Double = 0
Dim count as Integer = 0
For x = 0 To xyz123.Tables(0).Columns.Count - 1
Dim current as Double = 0
If Double.TryParse(xyz123.Tables(0).Rows(0)(x).ToString(), current) AndAlso current <> 0 Then
count += 1
totalNumber += current
End If
Next
Dim averageRating as Double = totalNumber / count

View 2 Replies

C# - Display GridView With Many Columns As Two Sets Of Columns?

Jan 20, 2010

I apologize for the odd title. I've been trying to figure out how to do this and can't quite put it into words. Basically, I need to try to display a GridView with a whole bunch of columns (37 in one case) in two "rows" of columns. More or less.

So instead of this:

Column1 Column2 Column3 Column4 Column5 Column6
Data Data Data Data Data Data
Data Data Data Data Data Data
Data Data Data Data Data Data

I'd like something like this:

Column1 Column2 Column3
Data Data Data
Data Data Data
Data Data Data

Column4 Column5 Column6
Data Data Data
Data Data Data
Data Data Data

As in the example there can be multiple rows returned which all need to be displayed. I'm trying to stop a very large horizontal scroll bar being required. I've been searching as much as I can but haven't found anything that fits what I'm looking for.

View 1 Replies

Forms Data Controls :: How To Convert Gridview Rows To Columns And Columns To Rows

Mar 4, 2011

I'm binding a gridview from a webservice with 30 columns and 10 rows, I need to print the same in a PORTRAIT, for that i decided to display columns as rows and

rows as columns like below:

EMP1 1 2 3 4
EMP2 1 2 3 4

View 3 Replies

Web Forms :: How To Duplicate A Page

Aug 11, 2010

I have a very simple question. How do I simply duplicate a page that has already been created?

View 1 Replies

MVC Not Duplicate Forms When Edit / Add?

May 18, 2010

When we have anything that requires user input (Eg adding a product to a database) the Edit screen looks the same as the add screen. When using MVC .Net how do you handle this? Do you return the same view? Just adjust the model to reflect the change?

View 4 Replies

ADO.NET :: Check For Duplicate Records

Dec 14, 2010

I want to check for duplicate records,if the record is already inserted then "record has already been inserted" should appear or else if its a new record then it should be inserted.. This function is inserting even if it exists and showing the error msg..

Sub CheckForDuplicateRec()
Dim da As SqlDataAdapter
Dim ds As New DataSet
Dim dt As New DataTable
cmd = New SqlCommand("Select * from Table3 where Name='" & txtname.Text & "' AND FName='" & txtfathersname.Text & "' AND MName='" & txtmothername.Text & "' AND Add1='" & txtadd.Text & "' AND Add2='" & txtadd2.Text & "' AND Add3='" & txtadd3.Text & "'
AND City='" & txtcity.Text & "' AND State='" & ddlstates.SelectedValue & "' AND Pincode=" & txtpincode.Text & "", con)
da = New SqlDataAdapter(cmd)
da.Fill(ds)
dt = ds.Tables("Table3")
If dt.Rows.Count = 0 Then
cmd = New SqlCommand("Insert into Table3 (Name,FName,MName,Add1,Add2,Add3,City,State,PinCode) values('" & txtname.Text & "','" & txtfathersname.Text & "','" & txtmothername.Text & "','" & txtadd.Text & "','" & txtadd2.Text & "','" & txtadd3.Text & "','"
& txtcity.Text & "','" & ddlstates.SelectedValue & "','" & txtpincode.Text & "')", con)
cmd.ExecuteNonQuery()
Else
lblError.Text = "Records already exists"
End If
End Sub

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved