Hi,
May be this is silly, or I just need a second pair eyes to look at this.
I am trying to get values that I have edited in a datagrid and update the
values with those values. Here is the code that I am using in my update
command.
TextBox txtProdName = (TextBox)e.Item.Cells[1].Controls[0];
TextBox txtSuppID = (TextBox)e.Item.Cells[2].Controls[0];
TextBox txtCatID = (TextBox)e.Item.Cells[3].Controls[0];
TextBox txtQtyPerUnit = (TextBox)e.Item.Cells[4].Controls[0];
TextBox txtUnitPrice = (TextBox)e.Item.Cells[5].Controls[1];
TextBox txtUnitsInStock = (TextBox)e.Item.Cells[6].Controls[0];
TextBox txtUnitsOnOrder = (TextBox)e.Item.Cells[7].Controls[0];
TextBox txtReorderLevel = (TextBox)e.Item.Cells[8].Controls[0];
CheckBox ChkDiscontinued = (CheckBox)e.Item.Cells[9].Controls[1];
string strSQL;
strSQL = "UPDATE Products SET ";
strSQL += "ProductName = '" + txtProdName.Text.Replace("'","'''") + "',";
strSQL += "SupplierID = " + txtSuppID.Text + "," ;
strSQL += "CategoryID = " + txtCatID.Text + ",";
strSQL += "QuantityPerUnit = '" + txtQtyPerUnit.Text + "',";
strSQL += "UnitPrice = " + txtUnitPrice.Text + ",";
strSQL += "UnitsInStock = " + txtUnitsInStock.Text + ",";
strSQL += "UnitsOnOrder = " + txtUnitsOnOrder.Text + ",";
strSQL += "ReorderLevel = " + txtReorderLevel.Text + ",";
strSQL += "Discontinued = " +
Convert.ToInt32(Convert.ToBoolean(ChkDiscontinued. Checked));
strSQL += " WHERE ProductID = " + e.Item.Cells[0].Text;
I am only getting values that I already have before I edited the cells. What
Am I doing wrong here.
--
Thanks
Pinjala. 2 1679
Try:
if(!this.IsPostback)
{
datagrid.DataSource = dataObject;
datagrid.DataBind();
}
Otherwise, once posting back, editing values are replaced by values from
data source.
HTH
Elton Wang
"Kiran Kumar Pinjala" wrote: Hi, May be this is silly, or I just need a second pair eyes to look at this.
I am trying to get values that I have edited in a datagrid and update the values with those values. Here is the code that I am using in my update command.
TextBox txtProdName = (TextBox)e.Item.Cells[1].Controls[0]; TextBox txtSuppID = (TextBox)e.Item.Cells[2].Controls[0]; TextBox txtCatID = (TextBox)e.Item.Cells[3].Controls[0]; TextBox txtQtyPerUnit = (TextBox)e.Item.Cells[4].Controls[0]; TextBox txtUnitPrice = (TextBox)e.Item.Cells[5].Controls[1]; TextBox txtUnitsInStock = (TextBox)e.Item.Cells[6].Controls[0]; TextBox txtUnitsOnOrder = (TextBox)e.Item.Cells[7].Controls[0]; TextBox txtReorderLevel = (TextBox)e.Item.Cells[8].Controls[0]; CheckBox ChkDiscontinued = (CheckBox)e.Item.Cells[9].Controls[1];
string strSQL;
strSQL = "UPDATE Products SET "; strSQL += "ProductName = '" + txtProdName.Text.Replace("'","'''") + "',"; strSQL += "SupplierID = " + txtSuppID.Text + "," ; strSQL += "CategoryID = " + txtCatID.Text + ","; strSQL += "QuantityPerUnit = '" + txtQtyPerUnit.Text + "',"; strSQL += "UnitPrice = " + txtUnitPrice.Text + ","; strSQL += "UnitsInStock = " + txtUnitsInStock.Text + ","; strSQL += "UnitsOnOrder = " + txtUnitsOnOrder.Text + ","; strSQL += "ReorderLevel = " + txtReorderLevel.Text + ","; strSQL += "Discontinued = " + Convert.ToInt32(Convert.ToBoolean(ChkDiscontinued. Checked)); strSQL += " WHERE ProductID = " + e.Item.Cells[0].Text;
I am only getting values that I already have before I edited the cells. What Am I doing wrong here. -- Thanks Pinjala.
Thanks, This worked.
--
Thanks
Kiran Kumar Pinjala
"Elton W" wrote: Try:
if(!this.IsPostback) { datagrid.DataSource = dataObject; datagrid.DataBind(); }
Otherwise, once posting back, editing values are replaced by values from data source.
HTH
Elton Wang
"Kiran Kumar Pinjala" wrote:
Hi, May be this is silly, or I just need a second pair eyes to look at this.
I am trying to get values that I have edited in a datagrid and update the values with those values. Here is the code that I am using in my update command.
TextBox txtProdName = (TextBox)e.Item.Cells[1].Controls[0]; TextBox txtSuppID = (TextBox)e.Item.Cells[2].Controls[0]; TextBox txtCatID = (TextBox)e.Item.Cells[3].Controls[0]; TextBox txtQtyPerUnit = (TextBox)e.Item.Cells[4].Controls[0]; TextBox txtUnitPrice = (TextBox)e.Item.Cells[5].Controls[1]; TextBox txtUnitsInStock = (TextBox)e.Item.Cells[6].Controls[0]; TextBox txtUnitsOnOrder = (TextBox)e.Item.Cells[7].Controls[0]; TextBox txtReorderLevel = (TextBox)e.Item.Cells[8].Controls[0]; CheckBox ChkDiscontinued = (CheckBox)e.Item.Cells[9].Controls[1];
string strSQL;
strSQL = "UPDATE Products SET "; strSQL += "ProductName = '" + txtProdName.Text.Replace("'","'''") + "',"; strSQL += "SupplierID = " + txtSuppID.Text + "," ; strSQL += "CategoryID = " + txtCatID.Text + ","; strSQL += "QuantityPerUnit = '" + txtQtyPerUnit.Text + "',"; strSQL += "UnitPrice = " + txtUnitPrice.Text + ","; strSQL += "UnitsInStock = " + txtUnitsInStock.Text + ","; strSQL += "UnitsOnOrder = " + txtUnitsOnOrder.Text + ","; strSQL += "ReorderLevel = " + txtReorderLevel.Text + ","; strSQL += "Discontinued = " + Convert.ToInt32(Convert.ToBoolean(ChkDiscontinued. Checked)); strSQL += " WHERE ProductID = " + e.Item.Cells[0].Text;
I am only getting values that I already have before I edited the cells. What Am I doing wrong here. -- Thanks Pinjala. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Filippo Pandiani |
last post by:
I have a grid that shows the file list from a folder.
On the postback, how do I get a Dataset from this grid?
Thanks,
Filippo.
|
by: Colin McGuigan |
last post by:
This is a translation of an ASP page to ASP.Net. First, the background:
The goal is to have a grid of different settings for the application --
think something along the lines of the Property...
|
by: Richard Dixson |
last post by:
Under ASP.NET (C#) I want to create a page that people can use to submit
questions. This page will consist of a table with several rows of
information, like:
Name: Bill Smith
Job title:...
|
by: charliewest |
last post by:
Hello -
I'm using a Repeater control to render information in a very customized
grid-like table. The Repeater control is binded to a DataSet with several
records of information. Within the...
|
by: Larry Grady |
last post by:
Anyone up for a challenge?
I've been struggling with this for a few days and was hoping someone could
help me. Pouring through all the messageboards I just can't find the
solution.
We have a...
|
by: OceanBreeze |
last post by:
I am new to .Net. I am using ASP 2.0 and C#.
I want to pupolate a data grid programatically using the values obtained from a list conating domain objects.
E.g., DAL.GetEmployee() returns a...
|
by: ruthboaz |
last post by:
Hi,
I am upgrading the current ms access .mdb file to a .adp with sql server back end.
I have been converted tables, forms, reports to .adp..
The tables are reflected at the server.
a)
...
|
by: John Wright |
last post by:
I have a datagrid that contains a list of decimal values. I want to compare
the values of one datatable to the other datatable and update my data grid.
For example my first datatable has the...
|
by: Mike |
last post by:
I have code that is doing some updating to a record. Its getting the ID to update from the Grid. I'm passing an INT to my method to update the record. My code is working though I'm still getting an...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |