I have a datagrid with two columns, the first a normal bound column,
the second is a template column created from a bound column. For the
ItemTemplate of the Template Column, I removed the label and replaced
it with a textbox. Displaying the data from the datasource is not a
problem, however when I change the data in the textbox and click on an
update button (the thought being that multiple rows will have been
changed and I can simply use the update command of the DataAdapter),
the underlying datasource (a DataSet) has HasChanges()=fa lse. What am
I not doing to cause the DataSet to be updated when the user changes
the text in the textbox?
Thanks.
private DataSet ds = new DataSet();
private SqlDataAdapter sda = new SqlDataAdapter( "SELECT orderid,
shipname FROM orders", new
SqlConnection(" Server=(local)\ \NetSDK;Integra ted Security=true;I nitial
Catalog=Northwi nd"));
private void Page_Load(objec t sender, System.EventArg s e)
{
if (!IsPostBack)
{
sda.Fill(ds, "orders");
DataGrid1.DataS ource = ds.Tables["orders"];
DataGrid1.DataB ind();
}
}
Private void Button1_Click(o bject sender, System.EventArg s e)
{
if (ds.HasChanges( )) <- ALWAYS FALSE
{
ds.AcceptChange s();
sda.Update(ds);
sda.Fill(ds, "orders");
DataGrid1.DataS ource = ds;
DataGrid1.DataB ind();
}
} 3 1646
Private void Button1_Click(o bject sender, System.EventArg s e)
{
foreach(DataGri dItem i in DataGrid1.Items )
{
TextBox tb = ((i.Cells[1].Controls[1]));
... Your code;
}
}
Michael.
"matthew schouppe" <ms*****@excite .com> wrote in message
news:be******** *************** ***@posting.goo gle.com... I have a datagrid with two columns, the first a normal bound column, the second is a template column created from a bound column. For the ItemTemplate of the Template Column, I removed the label and replaced it with a textbox. Displaying the data from the datasource is not a problem, however when I change the data in the textbox and click on an update button (the thought being that multiple rows will have been changed and I can simply use the update command of the DataAdapter), the underlying datasource (a DataSet) has HasChanges()=fa lse. What am I not doing to cause the DataSet to be updated when the user changes the text in the textbox?
Thanks.
private DataSet ds = new DataSet(); private SqlDataAdapter sda = new SqlDataAdapter( "SELECT orderid, shipname FROM orders", new SqlConnection(" Server=(local)\ \NetSDK;Integra ted Security=true;I nitial Catalog=Northwi nd"));
private void Page_Load(objec t sender, System.EventArg s e) { if (!IsPostBack) { sda.Fill(ds, "orders"); DataGrid1.DataS ource = ds.Tables["orders"]; DataGrid1.DataB ind(); } }
Private void Button1_Click(o bject sender, System.EventArg s e) { if (ds.HasChanges( )) <- ALWAYS FALSE { ds.AcceptChange s(); sda.Update(ds); sda.Fill(ds, "orders"); DataGrid1.DataS ource = ds; DataGrid1.DataB ind(); } }
I don't understand the reference to '...Your code;'. How is the
ds.HasChanges() affected by the foreach statement?
I thought that at some point I saw an article that had an example of
this where the entire grid was saved using sqlDataAdapter. Update(ds),
I just don't know how to get my textbox to register a change to the
dataset.
Matthew
"Michael Tkachev" <m_*******@hotm ail.com> wrote in message news:<OT******* *******@TK2MSFT NGP11.phx.gbl>. .. Private void Button1_Click(o bject sender, System.EventArg s e) { foreach(DataGri dItem i in DataGrid1.Items ) { TextBox tb = ((i.Cells[1].Controls[1])); ... Your code; } }
Michael.
Matthew:
The data binding in ASP.NET is "one way". In order to get values from
the controls on the page back into your data source, you need to write
code to move the values. Michael was demonstrating some code to
iterate through the grid to pull out all the values in the TextBox
controls. Using this loop you could then put the text into your
populated DataSet, than use the Update method to push the values into
the database.
HTH,
--
Scott http://www.OdeToCode.com
On 30 Apr 2004 05:33:05 -0700, ms*****@excite. com (matthew schouppe)
wrote: I don't understand the reference to '...Your code;'. How is the ds.HasChanges( ) affected by the foreach statement?
I thought that at some point I saw an article that had an example of this where the entire grid was saved using sqlDataAdapter. Update(ds), I just don't know how to get my textbox to register a change to the dataset.
Matthew
"Michael Tkachev" <m_*******@hotm ail.com> wrote in message news:<OT******* *******@TK2MSFT NGP11.phx.gbl>. .. Private void Button1_Click(o bject sender, System.EventArg s e) { foreach(DataGri dItem i in DataGrid1.Items ) { TextBox tb = ((i.Cells[1].Controls[1])); ... Your code; } }
Michael. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: lu |
last post by:
I have a page with datagrid (for viewing,
delete,edit,update) and text fields with button to add
info to database.
When user comes to page the datagrid selects info from
database, binds in columns, and adds a delete buttoncolumn
and editcommandcolumn. Below that, I have several text
boxes with a button with an onclick event to add new
information to the database table the grid pulls from.
A)Select Info binds fine.
|
by: shamila |
last post by:
</asp:label><asp:datagrid id="DataGrid3" runat="server"
cssclass="DataGrid" showfooter="True"
onupdatecommand="DataGrid3_Update"ondeletecommand="DataGrid3_Delete"
oneditcommand="DataGrid3_Edit" oncancelcommand="DataGrid3_Cancel"
caption="Pricing Schedules" autogeneratecolumns="False"
OnItemDataBound="ItemDataBoundEventHandler">
<alternatingitemstyle cssclass="DataGrid_AlternatingItemStyle" />
<columns>
<asp:templatecolumn...
|
by: Jim Heavey |
last post by:
Trying to figure out the technique which should be used
to add rows to a datagrid. I am thinking that I would
want an "Add" button on the footer, but I am not quite
sure how to do that. Is that the best method? Do you
have a sample of how to do this?
|
by: Josh |
last post by:
Hi Guys,
I have been stuck on this problem for several days now, i have a set of
nested datagrids. Inside the second datagrid i have a dropdown list, a
textbox and a label. I want the textbox to update the label with the value
of the dropdown list * the text box quantity. I am using an onTextChaged
even on the textbox, the problem i have is that i can not find the lblPrice
control.
Thanks for the help,
|
by: tshad |
last post by:
I am having trouble with links in my DataGrid.
I have Links all over my page set to smaller and they are consistant all
over the page in both Mozilla and IE, except for the DataGrid.
Here is a snippet from my .css file:
***************************
body {
margin:0;
padding:0;
| |
by: pmud |
last post by:
Hi,
I have 2 questions:
1. I have an editable data grid with 21 columns. I need to edit only 2
cloumns in this data grid. But when the grid is displayed in Edit mode, all
the columns show long text boxes whichmakes the user to SCROLL a lot.
I need only these 2 cloumns to be displayed in Edit mode. Is that possible &
how?
2. Also, even when the data grid is not displayed in the edit mode, it
|
by: jason |
last post by:
Pardon my ignorance on this. The below code works, except, when I edit
a record and update the two drop downs take the first entry in the
dropdownlist if not selected. I'd also like the dropdown to show the
current value in edit mode. I'm sure this is a common question. I've
reviewed several related post and tried them out to no avial. Some of
the offerings in listgroup look right on, but are not clear on where to
handle the suggested...
|
by: Luis Esteban Valencia Muñoz |
last post by:
I have a datagrid that displays editable text fields (2 different price
fields) and a checkbox in every row.
It has a "SaveChanges" button at the bottom, which, when pressed, looks at
every checkbox in the datagrid, if it is checked, it updates the
corresponding rows prices.
That works, no problem.
What I need to do is that when a user clicks into either of the price text
fields, the checkbox automatically checks itself.
This will save...
|
by: Frank |
last post by:
Hello,
I am developing with VS.Net 2003 on the asp 1.1 platform.
I am a few days new to using a datagrid. I found a nice tutorial and had no
problems using an editable datagrid with textboxes and an additional
buttoncolumn where I used a delete button to delete a specific row.
Once I had finished that, I trnsformed the grid tso it will display a
dropdownlist indtead of a textbox. After much grappling, I pretty much have
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |