DetailsView DataControlFields - Update

G

Guest

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
 
G

Guest

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.DetailsViewUpdateEventArgs) 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top