473,396 Members | 1,975 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

DetailsView DataControlFields - Update

Hi,

I am a newbie to ASP.NET 2.0. This is driving me nuts! I think I might have
a fundamental misunderstanding of how this all works!

I am using a DetailsView which is populated dynaically at runtime:

table = DataTable from Dataset passed back from Data Access Layer
DV1 = DetailsView

foreach (DataColumn col in table.Columns)
{
TemplateField TF = new TemplateField();
TF.HeaderText = col.ColumnName.ToString();

if (col.ColumnName == "ID")
{
TF.ItemTemplate = new
DetalsViewTemplate(ListItemType.Item, col.ColumnName);
DV1.Fields.Add(TF);
}
else
{
switch
(table.Rows[0][col.ColumnName].GetType().ToString())
{
case "System.String":
TF.ItemTemplate = new
DetalsViewTemplate(ListItemType.EditItem, col.ColumnName);
break;
case "System.Int32":
TF.ItemTemplate = new
DetalsViewTemplate(ListItemType.EditItem, col.ColumnName);
break;
case "System.Boolean":
TF.ItemTemplate = new
CheckBoxTemplate(col.ColumnName);
break;
case "System.DateTime":
TF.ItemTemplate = new
DateTimeTemplate(col.ColumnName);
break;
}
DV1.Fields.Add(TF);
}
}

I also have a custom "Save" button which fires the DV1.UpdateItem event.

In the event handler I try to access the e.NewValues collection to pass back
to the DAL to update the table.

My problem is that the NewEvents, OldEvents and Keys collections are all
empty. So Ihave been trying to access the DetailsView Fields collection to
get at the new values entered by the user.

Can anybody tell me how to get at those new values please?

Many thanks
Mike
May 23 '07 #1
1 1868
Mike,

try something like this in your Item update handler:

Protected Sub dvCustomer_ItemUpdating(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DetailsViewUpdateEventAr gs) Handles
dvCustomer.ItemUpdating

Dim records(e.NewValues.Count - 1) As DictionaryEntry
e.NewValues.CopyTo(records, 0)
Dim dataEntry As DictionaryEntry

For Each dataEntry In records
If IsDBNull(dataEntry.Value) = False Then 'check for null value
If dataEntry.Value IsNot Nothing Then ' checks for no value
If dataEntry.Value.ToString <"" Then 'checks for string
value
Dim i As String
i = dataEntry.Value.ToString()
'do whatever
end if
end if
end if
Next
end sub

"Mike" wrote:
Hi,

I am a newbie to ASP.NET 2.0. This is driving me nuts! I think I might have
a fundamental misunderstanding of how this all works!

I am using a DetailsView which is populated dynaically at runtime:

table = DataTable from Dataset passed back from Data Access Layer
DV1 = DetailsView

foreach (DataColumn col in table.Columns)
{
TemplateField TF = new TemplateField();
TF.HeaderText = col.ColumnName.ToString();

if (col.ColumnName == "ID")
{
TF.ItemTemplate = new
DetalsViewTemplate(ListItemType.Item, col.ColumnName);
DV1.Fields.Add(TF);
}
else
{
switch
(table.Rows[0][col.ColumnName].GetType().ToString())
{
case "System.String":
TF.ItemTemplate = new
DetalsViewTemplate(ListItemType.EditItem, col.ColumnName);
break;
case "System.Int32":
TF.ItemTemplate = new
DetalsViewTemplate(ListItemType.EditItem, col.ColumnName);
break;
case "System.Boolean":
TF.ItemTemplate = new
CheckBoxTemplate(col.ColumnName);
break;
case "System.DateTime":
TF.ItemTemplate = new
DateTimeTemplate(col.ColumnName);
break;
}
DV1.Fields.Add(TF);
}
}

I also have a custom "Save" button which fires the DV1.UpdateItem event.

In the event handler I try to access the e.NewValues collection to pass back
to the DAL to update the table.

My problem is that the NewEvents, OldEvents and Keys collections are all
empty. So Ihave been trying to access the DetailsView Fields collection to
get at the new values entered by the user.

Can anybody tell me how to get at those new values please?

Many thanks
Mike

May 23 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Andrew Robinson | last post by:
Is there any way to accomplish two way data binding in a Details View with a DataSet or DataTable as the DataSource. All I want is to get an updated DataSet or DataTable back from the...
12
by: Jim Hammond | last post by:
I am passing the whole object instead or parameters in my select and update methods. I can get the updated object if I set UpdateMethod, let ASP.NET autogenerate an update button, and then press...
0
by: jeffmagill | last post by:
Hi Everybody, I'm really hoping that someone can help me out because I have spent too much time on this project already! Basically, I have a DetailsView that handles all the Edits for a...
4
by: Kjell Arne | last post by:
Hi! I have a detailsview control in a webpart with some templated fields on. I set the ValidationGroup property to som value on these fields to distinguish from other web parts on the page....
7
by: studio60podcast | last post by:
I have a gridview and a details view in a page. The two are hooked up, so that when a row is selected in the GridView, the DetailsView displays the details. But, what I'm trying to accomplish is...
1
by: Timothy H. Schilbach | last post by:
Hi Everyone, I am having a massive issue trying to get custom data into my DV. What I want to do is sooo simple: 1. I have a single DV on a page 2. I created my own template (see below) 3....
2
by: mike | last post by:
I have a page with a LoginView which contains a Gridview and a DetailsView, each in its own UpdatePanel The problem that I am experiencing is that when I select a record in the Gridview (using a...
0
by: sansie | last post by:
Hi, I have a page which is basically a details view(in inset mode) inside a datalist. The problem is I want to set the field "invoiceID" (of the detailsview) to an invoiceID coming through the...
1
by: ledneh | last post by:
I've been working on concurrency checking for an application I'm building, and a minor part of it has me slightly stumped. I've got a DetailsView that populates from an ObjectDataSource, using...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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...
0
Oralloy
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
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,...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.