DetailsView EditItemTemplate DropdownList Update Problem

T

Trevor Bezotte

Hi!

I have a DetailsView with a DropDownList in an EditItemTemplate, I know,
pretty cool right? But when I try to Update the table with a new value from
the DropDownList the table does not get updated with the new value. I'm new
at this and I'm sure I'm overlooking something simple here. I'll post the
ASP code, hopefully someone can help me with this one.

Thank you!


<%@ Page Language="C#" masterpagefile="~/software.master"
AutoEventWireup="true" CodeFile="MasterDetail.aspx.cs" Debug="true"
Inherits="MasterDetail" %>

<asp:Content ID="SoftwareData" runat="server"
ContentPlaceHolderID="PageBody">



<table><tr>

<td valign="top" style="width: 280px">

<asp:GridView ID="SummaryGrid" runat="server"
DataSourceID="AppsDBDataSource"

EnableViewState="False"

DataKeyNames="ci_id" AllowPaging="True"

AutoGenerateSelectButton="True"

AutoGenerateColumns="False" style="left: 73px; position: relative; top: 9px"
BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px"
CellPadding="3" Font-Names="Arial" Font-Size="X-Small" GridLines="Vertical"
Width="492px" PageSize="5">

<Columns>

<asp:BoundField DataField="manufacturer" HeaderText="Manufacturer" />

<asp:BoundField DataField="title" HeaderText="Title" />

<asp:BoundField DataField="version" HeaderText="Version" />

</Columns>

<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />

<RowStyle BackColor="#EEEEEE" ForeColor="Black" />

<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />

<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center"
/>

<HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />

<AlternatingRowStyle BackColor="Gainsboro" />

</asp:GridView>

</td>

<td valign="top">

<asp:DetailsView ID="DetailsView1" runat="server"

DataKeyNames="ci_id, media_type_id"

HeaderText="Software Package Details"

EmptyDataText="No package currently selected"

DataSourceID="RowDataSource"

AutoGenerateInsertButton="True"

AutoGenerateDeleteButton="True"

AutoGenerateEditButton="True" OnItemUpdated="DetailsView1_ItemUpdated"
style="left: 73px; position: relative; top: 9px" BackColor="White"
BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3"
Font-Names="Arial" Font-Size="X-Small" GridLines="Vertical" Width="320px"
AutoGenerateRows="False">

<Fields>

<asp:BoundField DataField="ci_id" HeaderText="ID" ReadOnly="True" />

<asp:CheckBoxField DataField="active" HeaderText="Active"
SortExpression="active" />

<asp:BoundField DataField="title" HeaderText="Title" >

<ControlStyle Width="225px" />

</asp:BoundField>

<asp:BoundField DataField="version" HeaderText="Version" />

<asp:BoundField DataField="other_version_info" HeaderText="Version Info" />

<asp:BoundField DataField="manufacturer" HeaderText="Manufacturer" />

<asp:TemplateField HeaderText="Media">

<EditItemTemplate>

&nbsp;

<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SQLMediaTypes"

DataTextField="media_type" DataValueField="media_type_id" Style="left: -6px;

position: relative; top: 0px" Width="161px" SelectedValue='<%#
Bind("media_type_id") %>'>

</asp:DropDownList>

</EditItemTemplate>

<InsertItemTemplate>

<asp:DropDownList ID="DropDownList2" runat="server"
DataSourceID="SQLMediaTypes"

DataTextField="media_type" DataValueField="media_type_id" Style="left: 0px;

position: relative; top: 0px" Width="161px" SelectedValue='<%#
Bind("media_type_id") %>'>

</asp:DropDownList>

</InsertItemTemplate>

<ItemTemplate>

<asp:Label ID="Label1" runat="server" Text='<%# Bind("media_type")
%>'></asp:Label>

</ItemTemplate>

</asp:TemplateField>

<asp:BoundField DataField="license_info" HeaderText="License Info" />

<asp:BoundField DataField="date_purchased" HeaderText="Purchase Date"
SortExpression="date_purchased" />


</Fields>

<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />

<EditRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White"
Font-Names="Arial" Font-Size="X-Small" />

<RowStyle BackColor="#EEEEEE" ForeColor="Black" />

<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center"
/>

<HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />

<AlternatingRowStyle BackColor="Gainsboro" />

</asp:DetailsView>

</td>

</tr></table>

<asp:Label ID="Label2" runat="server" Font-Names="Courier New" Height="28px"
Style="z-index: 103;

left: 28px; position: absolute; top: -298px" Width="379px">Application
Management Database</asp:Label>

<asp:SqlDataSource ID="AppsDBDataSource" runat="server"

EnableCaching="false" CacheKeyDependency="AppsDBDataSource_Controller"

ConnectionString='<%$ ConnectionStrings:LocalAppsDB %>'

SelectCommand="SELECT * FROM vwSoftware">

</asp:SqlDataSource>

<asp:SqlDataSource ID="RowDataSource" runat="server"

EnableCaching="false"

ConnectionString='<%$ ConnectionStrings:LocalAppsDB %>'

SelectCommand="SELECT * FROM vwSoftware WHERE ci_id=@ci_id"

UpdateCommand="UPDATE software SET active=@active, title=@title,
version=@version, other_version_info=@other_version_info,
manufacturer=@manufacturer, media_type_id=@media_type_id,
license_info=@license_info, date_purchased=@date_purchased WHERE
ci_id=@ci_id"

InsertCommand="INSERT INTO software(active, title, version,
other_version_info, manufacturer, media_type_id, license_info,
date_purchased) VALUES(@active, @title, @version, @other_version_info,
@manufacturer, @media_type_id, @license_info, @date_purchased)"

DeleteCommand="DELETE FROM software WHERE ci_id=@ci_id">

<SelectParameters>

<asp:ControlParameter Name="ci_id" ControlID="SummaryGrid"
PropertyName="SelectedValue" />

</SelectParameters>

</asp:SqlDataSource>

<asp:SqlDataSource ID="SQLMediaTypes" runat="server" ConnectionString="<%$
ConnectionStrings:LocalAppsDB %>"

OnSelecting="SQLMediaTypes_Selecting" ProviderName="<%$
ConnectionStrings:LocalAppsDB.ProviderName %>"

SelectCommand="SELECT [media_type_id], [media_type] FROM
[media_type]"></asp:SqlDataSource>


</asp:Content>
 
S

Steven Cheng[MSFT]

Hi Trevor,

Welcome to ASPNET newsgroup.
Regarding on the DetailsView TemplateField updating problem, based on my
experience, for template fields, we can just enable two -way databinding
as long as we use the <%# bind(....) %> expression in databinding
expression. Also, I've checked the code snippet you provide and compare to
my local test page, seem haven't found any particular difference...
Have you tried create a new page and regenerate such steps(maybe you can
just use a detailsView without GridView to make the things
simplified....)...

Also, one way for testing is register the DetailsView's ItemUpdating event
and printout all the new paramters' value there , e.g:

=============
protected void DetailsView1_ItemUpdating(object sender,
DetailsViewUpdateEventArgs e)
{
foreach(string key in e.NewValues.Keys)
{
Response.Write("<br>" + key + " " + e.NewValues[key]);
}

e.Cancel = true;
}
============

we can have a look whether all the parameters are provided correclty....
Also, on sqlserver side, we can using sqlprofiler to monitor whether the
final sqlstatement has contained the correctly paratmeters....

BTW, I've also pasted my test page's aspx template below for your reference:

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

==================================
<div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:databaseConnectionString %>"
DeleteCommand="DELETE FROM [items] WHERE [id] = @id"
InsertCommand="INSERT INTO [items] ([name], [priority]) VALUES (@name,
@priority)"
SelectCommand="SELECT [id], [name], [priority] FROM [items]"
UpdateCommand="UPDATE [items] SET [name] = @name, [priority] = @priority
WHERE [id] = @id">
<DeleteParameters>
<asp:parameter Name="id" Type="Int64" />
</DeleteParameters>
<UpdateParameters>
<asp:parameter Name="name" Type="String" />
<asp:parameter Name="priority" Type="Int32" />
<asp:parameter Name="id" Type="Int64" />
</UpdateParameters>
<InsertParameters>
<asp:parameter Name="name" Type="String" />
<asp:parameter Name="priority" Type="Int32" />
</InsertParameters>
</asp:SqlDataSource>
<asp:DetailsView ID="DetailsView1" runat="server"
AllowPaging="True" AutoGenerateRows="False"
DataKeyNames="id" DataSourceID="SqlDataSource1" Height="50px"
Width="125px" OnItemUpdating="DetailsView1_ItemUpdating">
<Fields>
<asp:BoundField DataField="id" HeaderText="id"
InsertVisible="False" ReadOnly="True"
SortExpression="id" />
<asp:BoundField DataField="name" HeaderText="name"
SortExpression="name" />
<asp:TemplateField HeaderText="priority"
SortExpression="priority">
<EditItemTemplate>
<asp:DropDownList ID="lstPriority" runat="server"
SelectedValue='<%# Bind("priority") %>' DataSourceID="SqlDataSource3"
DataTextField="pname" DataValueField="pid">
<asp:ListItem Value="0">low</asp:ListItem>
<asp:ListItem Value="1">middle</asp:ListItem>
<asp:ListItem Value="2">high</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource3"
runat="server" CacheDuration="300" ConnectionString="<%$
ConnectionStrings:databaseConnectionString %>"
EnableCaching="True" SelectCommand="SELECT
DISTINCT [pid], [pname] FROM [priorities]">
</asp:SqlDataSource>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#
Bind("priority") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:DropDownList ID="lstPriority" runat="server"
Enabled="False" SelectedValue='<%# Bind("priority") %>'
DataSourceID="SqlDataSource2" DataTextField="pname" DataValueField="pid">
<asp:ListItem Value="0">low</asp:ListItem>
<asp:ListItem Value="1">middle</asp:ListItem>
<asp:ListItem Value="2">high</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2"
runat="server" CacheDuration="600" ConnectionString="<%$
ConnectionStrings:databaseConnectionString %>"
EnableCaching="True" SelectCommand="SELECT
DISTINCT [pid], [pname] FROM [priorities]">
</asp:SqlDataSource>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True"
ShowEditButton="True" ShowInsertButton="True" />
</Fields>
</asp:DetailsView>

</div>
=======================




--------------------
| From: "Trevor Bezotte" <[email protected]>
| Subject: DetailsView EditItemTemplate DropdownList Update Problem
| Date: Thu, 1 Dec 2005 14:53:40 -0600
| Lines: 234
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| X-RFC2646: Format=Flowed; Original
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| NNTP-Posting-Host: global.erdman.com 12.20.65.30
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet.datagridcontrol:14838
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
|
| Hi!
|
| I have a DetailsView with a DropDownList in an EditItemTemplate, I know,
| pretty cool right? But when I try to Update the table with a new value
from
| the DropDownList the table does not get updated with the new value. I'm
new
| at this and I'm sure I'm overlooking something simple here. I'll post the
| ASP code, hopefully someone can help me with this one.
|
| Thank you!
|
|
| <%@ Page Language="C#" masterpagefile="~/software.master"
| AutoEventWireup="true" CodeFile="MasterDetail.aspx.cs" Debug="true"
| Inherits="MasterDetail" %>
|
| <asp:Content ID="SoftwareData" runat="server"
| ContentPlaceHolderID="PageBody">
|
|
|
| <table><tr>
|
| <td valign="top" style="width: 280px">
|
| <asp:GridView ID="SummaryGrid" runat="server"
| DataSourceID="AppsDBDataSource"
|
| EnableViewState="False"
|
| DataKeyNames="ci_id" AllowPaging="True"
|
| AutoGenerateSelectButton="True"
|
| AutoGenerateColumns="False" style="left: 73px; position: relative; top:
9px"
| BackColor="White" BorderColor="#999999" BorderStyle="None"
BorderWidth="1px"
| CellPadding="3" Font-Names="Arial" Font-Size="X-Small"
GridLines="Vertical"
| Width="492px" PageSize="5">
|
| <Columns>
|
| <asp:BoundField DataField="manufacturer" HeaderText="Manufacturer" />
|
| <asp:BoundField DataField="title" HeaderText="Title" />
|
| <asp:BoundField DataField="version" HeaderText="Version" />
|
| </Columns>
|
| <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
|
| <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
|
| <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White"
/>
|
| <PagerStyle BackColor="#999999" ForeColor="Black"
HorizontalAlign="Center"
| />
|
| <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
|
| <AlternatingRowStyle BackColor="Gainsboro" />
|
| </asp:GridView>
|
| </td>
|
| <td valign="top">
|
| <asp:DetailsView ID="DetailsView1" runat="server"
|
| DataKeyNames="ci_id, media_type_id"
|
| HeaderText="Software Package Details"
|
| EmptyDataText="No package currently selected"
|
| DataSourceID="RowDataSource"
|
| AutoGenerateInsertButton="True"
|
| AutoGenerateDeleteButton="True"
|
| AutoGenerateEditButton="True" OnItemUpdated="DetailsView1_ItemUpdated"
| style="left: 73px; position: relative; top: 9px" BackColor="White"
| BorderColor="#999999" BorderStyle="None" BorderWidth="1px"
CellPadding="3"
| Font-Names="Arial" Font-Size="X-Small" GridLines="Vertical" Width="320px"
| AutoGenerateRows="False">
|
| <Fields>
|
| <asp:BoundField DataField="ci_id" HeaderText="ID" ReadOnly="True" />
|
| <asp:CheckBoxField DataField="active" HeaderText="Active"
| SortExpression="active" />
|
| <asp:BoundField DataField="title" HeaderText="Title" >
|
| <ControlStyle Width="225px" />
|
| </asp:BoundField>
|
| <asp:BoundField DataField="version" HeaderText="Version" />
|
| <asp:BoundField DataField="other_version_info" HeaderText="Version Info"
/>
|
| <asp:BoundField DataField="manufacturer" HeaderText="Manufacturer" />
|
| <asp:TemplateField HeaderText="Media">
|
| <EditItemTemplate>
|
| &nbsp;
|
| <asp:DropDownList ID="DropDownList1" runat="server"
| DataSourceID="SQLMediaTypes"
|
| DataTextField="media_type" DataValueField="media_type_id" Style="left:
-6px;
|
| position: relative; top: 0px" Width="161px" SelectedValue='<%#
| Bind("media_type_id") %>'>
|
| </asp:DropDownList>
|
| </EditItemTemplate>
|
| <InsertItemTemplate>
|
| <asp:DropDownList ID="DropDownList2" runat="server"
| DataSourceID="SQLMediaTypes"
|
| DataTextField="media_type" DataValueField="media_type_id" Style="left:
0px;
|
| position: relative; top: 0px" Width="161px" SelectedValue='<%#
| Bind("media_type_id") %>'>
|
| </asp:DropDownList>
|
| </InsertItemTemplate>
|
| <ItemTemplate>
|
| <asp:Label ID="Label1" runat="server" Text='<%# Bind("media_type")
| %>'></asp:Label>
|
| </ItemTemplate>
|
| </asp:TemplateField>
|
| <asp:BoundField DataField="license_info" HeaderText="License Info" />
|
| <asp:BoundField DataField="date_purchased" HeaderText="Purchase Date"
| SortExpression="date_purchased" />
|
|
| </Fields>
|
| <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
|
| <EditRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White"
| Font-Names="Arial" Font-Size="X-Small" />
|
| <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
|
| <PagerStyle BackColor="#999999" ForeColor="Black"
HorizontalAlign="Center"
| />
|
| <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
|
| <AlternatingRowStyle BackColor="Gainsboro" />
|
| </asp:DetailsView>
|
| </td>
|
| </tr></table>
|
| <asp:Label ID="Label2" runat="server" Font-Names="Courier New"
Height="28px"
| Style="z-index: 103;
|
| left: 28px; position: absolute; top: -298px" Width="379px">Application
| Management Database</asp:Label>
|
| <asp:SqlDataSource ID="AppsDBDataSource" runat="server"
|
| EnableCaching="false" CacheKeyDependency="AppsDBDataSource_Controller"
|
| ConnectionString='<%$ ConnectionStrings:LocalAppsDB %>'
|
| SelectCommand="SELECT * FROM vwSoftware">
|
| </asp:SqlDataSource>
|
| <asp:SqlDataSource ID="RowDataSource" runat="server"
|
| EnableCaching="false"
|
| ConnectionString='<%$ ConnectionStrings:LocalAppsDB %>'
|
| SelectCommand="SELECT * FROM vwSoftware WHERE ci_id=@ci_id"
|
| UpdateCommand="UPDATE software SET active=@active, title=@title,
| version=@version, other_version_info=@other_version_info,
| manufacturer=@manufacturer, media_type_id=@media_type_id,
| license_info=@license_info, date_purchased=@date_purchased WHERE
| ci_id=@ci_id"
|
| InsertCommand="INSERT INTO software(active, title, version,
| other_version_info, manufacturer, media_type_id, license_info,
| date_purchased) VALUES(@active, @title, @version, @other_version_info,
| @manufacturer, @media_type_id, @license_info, @date_purchased)"
|
| DeleteCommand="DELETE FROM software WHERE ci_id=@ci_id">
|
| <SelectParameters>
|
| <asp:ControlParameter Name="ci_id" ControlID="SummaryGrid"
| PropertyName="SelectedValue" />
|
| </SelectParameters>
|
| </asp:SqlDataSource>
|
| <asp:SqlDataSource ID="SQLMediaTypes" runat="server"
ConnectionString="<%$
| ConnectionStrings:LocalAppsDB %>"
|
| OnSelecting="SQLMediaTypes_Selecting" ProviderName="<%$
| ConnectionStrings:LocalAppsDB.ProviderName %>"
|
| SelectCommand="SELECT [media_type_id], [media_type] FROM
| [media_type]"></asp:SqlDataSource>
|
|
| </asp:Content>
|
|
|
 
T

Trevor Bezotte

I checked the profiler and it shows correct parameter, but it does not show
the correct parameter value.

I tried your ItemUpdating code but it does not get fired.




Steven Cheng said:
Hi Trevor,

Welcome to ASPNET newsgroup.
Regarding on the DetailsView TemplateField updating problem, based on my
experience, for template fields, we can just enable two -way databinding
as long as we use the <%# bind(....) %> expression in databinding
expression. Also, I've checked the code snippet you provide and compare to
my local test page, seem haven't found any particular difference...
Have you tried create a new page and regenerate such steps(maybe you can
just use a detailsView without GridView to make the things
simplified....)...

Also, one way for testing is register the DetailsView's ItemUpdating event
and printout all the new paramters' value there , e.g:

=============
protected void DetailsView1_ItemUpdating(object sender,
DetailsViewUpdateEventArgs e)
{
foreach(string key in e.NewValues.Keys)
{
Response.Write("<br>" + key + " " + e.NewValues[key]);
}

e.Cancel = true;
}
============

we can have a look whether all the parameters are provided correclty....
Also, on sqlserver side, we can using sqlprofiler to monitor whether the
final sqlstatement has contained the correctly paratmeters....

BTW, I've also pasted my test page's aspx template below for your
reference:

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

==================================
<div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:databaseConnectionString %>"
DeleteCommand="DELETE FROM [items] WHERE [id] = @id"
InsertCommand="INSERT INTO [items] ([name], [priority]) VALUES (@name,
@priority)"
SelectCommand="SELECT [id], [name], [priority] FROM [items]"
UpdateCommand="UPDATE [items] SET [name] = @name, [priority] = @priority
WHERE [id] = @id">
<DeleteParameters>
<asp:parameter Name="id" Type="Int64" />
</DeleteParameters>
<UpdateParameters>
<asp:parameter Name="name" Type="String" />
<asp:parameter Name="priority" Type="Int32" />
<asp:parameter Name="id" Type="Int64" />
</UpdateParameters>
<InsertParameters>
<asp:parameter Name="name" Type="String" />
<asp:parameter Name="priority" Type="Int32" />
</InsertParameters>
</asp:SqlDataSource>
<asp:DetailsView ID="DetailsView1" runat="server"
AllowPaging="True" AutoGenerateRows="False"
DataKeyNames="id" DataSourceID="SqlDataSource1" Height="50px"
Width="125px" OnItemUpdating="DetailsView1_ItemUpdating">
<Fields>
<asp:BoundField DataField="id" HeaderText="id"
InsertVisible="False" ReadOnly="True"
SortExpression="id" />
<asp:BoundField DataField="name" HeaderText="name"
SortExpression="name" />
<asp:TemplateField HeaderText="priority"
SortExpression="priority">
<EditItemTemplate>
<asp:DropDownList ID="lstPriority" runat="server"
SelectedValue='<%# Bind("priority") %>' DataSourceID="SqlDataSource3"
DataTextField="pname" DataValueField="pid">
<asp:ListItem Value="0">low</asp:ListItem>
<asp:ListItem Value="1">middle</asp:ListItem>
<asp:ListItem Value="2">high</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource3"
runat="server" CacheDuration="300" ConnectionString="<%$
ConnectionStrings:databaseConnectionString %>"
EnableCaching="True" SelectCommand="SELECT
DISTINCT [pid], [pname] FROM [priorities]">
</asp:SqlDataSource>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#
Bind("priority") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:DropDownList ID="lstPriority" runat="server"
Enabled="False" SelectedValue='<%# Bind("priority") %>'
DataSourceID="SqlDataSource2" DataTextField="pname" DataValueField="pid">
<asp:ListItem Value="0">low</asp:ListItem>
<asp:ListItem Value="1">middle</asp:ListItem>
<asp:ListItem Value="2">high</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2"
runat="server" CacheDuration="600" ConnectionString="<%$
ConnectionStrings:databaseConnectionString %>"
EnableCaching="True" SelectCommand="SELECT
DISTINCT [pid], [pname] FROM [priorities]">
</asp:SqlDataSource>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True"
ShowEditButton="True" ShowInsertButton="True" />
</Fields>
</asp:DetailsView>

</div>
=======================




--------------------
| From: "Trevor Bezotte" <[email protected]>
| Subject: DetailsView EditItemTemplate DropdownList Update Problem
| Date: Thu, 1 Dec 2005 14:53:40 -0600
| Lines: 234
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| X-RFC2646: Format=Flowed; Original
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| NNTP-Posting-Host: global.erdman.com 12.20.65.30
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet.datagridcontrol:14838
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
|
| Hi!
|
| I have a DetailsView with a DropDownList in an EditItemTemplate, I know,
| pretty cool right? But when I try to Update the table with a new value
from
| the DropDownList the table does not get updated with the new value. I'm
new
| at this and I'm sure I'm overlooking something simple here. I'll post
the
| ASP code, hopefully someone can help me with this one.
|
| Thank you!
|
|
| <%@ Page Language="C#" masterpagefile="~/software.master"
| AutoEventWireup="true" CodeFile="MasterDetail.aspx.cs" Debug="true"
| Inherits="MasterDetail" %>
|
| <asp:Content ID="SoftwareData" runat="server"
| ContentPlaceHolderID="PageBody">
|
|
|
| <table><tr>
|
| <td valign="top" style="width: 280px">
|
| <asp:GridView ID="SummaryGrid" runat="server"
| DataSourceID="AppsDBDataSource"
|
| EnableViewState="False"
|
| DataKeyNames="ci_id" AllowPaging="True"
|
| AutoGenerateSelectButton="True"
|
| AutoGenerateColumns="False" style="left: 73px; position: relative; top:
9px"
| BackColor="White" BorderColor="#999999" BorderStyle="None"
BorderWidth="1px"
| CellPadding="3" Font-Names="Arial" Font-Size="X-Small"
GridLines="Vertical"
| Width="492px" PageSize="5">
|
| <Columns>
|
| <asp:BoundField DataField="manufacturer" HeaderText="Manufacturer" />
|
| <asp:BoundField DataField="title" HeaderText="Title" />
|
| <asp:BoundField DataField="version" HeaderText="Version" />
|
| </Columns>
|
| <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
|
| <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
|
| <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White"
/>
|
| <PagerStyle BackColor="#999999" ForeColor="Black"
HorizontalAlign="Center"
| />
|
| <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
|
| <AlternatingRowStyle BackColor="Gainsboro" />
|
| </asp:GridView>
|
| </td>
|
| <td valign="top">
|
| <asp:DetailsView ID="DetailsView1" runat="server"
|
| DataKeyNames="ci_id, media_type_id"
|
| HeaderText="Software Package Details"
|
| EmptyDataText="No package currently selected"
|
| DataSourceID="RowDataSource"
|
| AutoGenerateInsertButton="True"
|
| AutoGenerateDeleteButton="True"
|
| AutoGenerateEditButton="True" OnItemUpdated="DetailsView1_ItemUpdated"
| style="left: 73px; position: relative; top: 9px" BackColor="White"
| BorderColor="#999999" BorderStyle="None" BorderWidth="1px"
CellPadding="3"
| Font-Names="Arial" Font-Size="X-Small" GridLines="Vertical"
Width="320px"
| AutoGenerateRows="False">
|
| <Fields>
|
| <asp:BoundField DataField="ci_id" HeaderText="ID" ReadOnly="True" />
|
| <asp:CheckBoxField DataField="active" HeaderText="Active"
| SortExpression="active" />
|
| <asp:BoundField DataField="title" HeaderText="Title" >
|
| <ControlStyle Width="225px" />
|
| </asp:BoundField>
|
| <asp:BoundField DataField="version" HeaderText="Version" />
|
| <asp:BoundField DataField="other_version_info" HeaderText="Version Info"
/>
|
| <asp:BoundField DataField="manufacturer" HeaderText="Manufacturer" />
|
| <asp:TemplateField HeaderText="Media">
|
| <EditItemTemplate>
|
| &nbsp;
|
| <asp:DropDownList ID="DropDownList1" runat="server"
| DataSourceID="SQLMediaTypes"
|
| DataTextField="media_type" DataValueField="media_type_id" Style="left:
-6px;
|
| position: relative; top: 0px" Width="161px" SelectedValue='<%#
| Bind("media_type_id") %>'>
|
| </asp:DropDownList>
|
| </EditItemTemplate>
|
| <InsertItemTemplate>
|
| <asp:DropDownList ID="DropDownList2" runat="server"
| DataSourceID="SQLMediaTypes"
|
| DataTextField="media_type" DataValueField="media_type_id" Style="left:
0px;
|
| position: relative; top: 0px" Width="161px" SelectedValue='<%#
| Bind("media_type_id") %>'>
|
| </asp:DropDownList>
|
| </InsertItemTemplate>
|
| <ItemTemplate>
|
| <asp:Label ID="Label1" runat="server" Text='<%# Bind("media_type")
| %>'></asp:Label>
|
| </ItemTemplate>
|
| </asp:TemplateField>
|
| <asp:BoundField DataField="license_info" HeaderText="License Info" />
|
| <asp:BoundField DataField="date_purchased" HeaderText="Purchase Date"
| SortExpression="date_purchased" />
|
|
| </Fields>
|
| <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
|
| <EditRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White"
| Font-Names="Arial" Font-Size="X-Small" />
|
| <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
|
| <PagerStyle BackColor="#999999" ForeColor="Black"
HorizontalAlign="Center"
| />
|
| <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
|
| <AlternatingRowStyle BackColor="Gainsboro" />
|
| </asp:DetailsView>
|
| </td>
|
| </tr></table>
|
| <asp:Label ID="Label2" runat="server" Font-Names="Courier New"
Height="28px"
| Style="z-index: 103;
|
| left: 28px; position: absolute; top: -298px" Width="379px">Application
| Management Database</asp:Label>
|
| <asp:SqlDataSource ID="AppsDBDataSource" runat="server"
|
| EnableCaching="false" CacheKeyDependency="AppsDBDataSource_Controller"
|
| ConnectionString='<%$ ConnectionStrings:LocalAppsDB %>'
|
| SelectCommand="SELECT * FROM vwSoftware">
|
| </asp:SqlDataSource>
|
| <asp:SqlDataSource ID="RowDataSource" runat="server"
|
| EnableCaching="false"
|
| ConnectionString='<%$ ConnectionStrings:LocalAppsDB %>'
|
| SelectCommand="SELECT * FROM vwSoftware WHERE ci_id=@ci_id"
|
| UpdateCommand="UPDATE software SET active=@active, title=@title,
| version=@version, other_version_info=@other_version_info,
| manufacturer=@manufacturer, media_type_id=@media_type_id,
| license_info=@license_info, date_purchased=@date_purchased WHERE
| ci_id=@ci_id"
|
| InsertCommand="INSERT INTO software(active, title, version,
| other_version_info, manufacturer, media_type_id, license_info,
| date_purchased) VALUES(@active, @title, @version, @other_version_info,
| @manufacturer, @media_type_id, @license_info, @date_purchased)"
|
| DeleteCommand="DELETE FROM software WHERE ci_id=@ci_id">
|
| <SelectParameters>
|
| <asp:ControlParameter Name="ci_id" ControlID="SummaryGrid"
| PropertyName="SelectedValue" />
|
| </SelectParameters>
|
| </asp:SqlDataSource>
|
| <asp:SqlDataSource ID="SQLMediaTypes" runat="server"
ConnectionString="<%$
| ConnectionStrings:LocalAppsDB %>"
|
| OnSelecting="SQLMediaTypes_Selecting" ProviderName="<%$
| ConnectionStrings:LocalAppsDB.ProviderName %>"
|
| SelectCommand="SELECT [media_type_id], [media_type] FROM
| [media_type]"></asp:SqlDataSource>
|
|
| </asp:Content>
|
|
|
 
T

Trevor Bezotte

OK, the OnItemUpdating IS firing (I forgot to add the
OnItemUpdating="DetailsView1_ItemUpdating" to my asp code) and I see the
correct parameter value for media_type_id being written to the page via
Response.Write, why doesn't that value make it to the SQL server for
updating?


Steven Cheng said:
Hi Trevor,

Welcome to ASPNET newsgroup.
Regarding on the DetailsView TemplateField updating problem, based on my
experience, for template fields, we can just enable two -way databinding
as long as we use the <%# bind(....) %> expression in databinding
expression. Also, I've checked the code snippet you provide and compare to
my local test page, seem haven't found any particular difference...
Have you tried create a new page and regenerate such steps(maybe you can
just use a detailsView without GridView to make the things
simplified....)...

Also, one way for testing is register the DetailsView's ItemUpdating event
and printout all the new paramters' value there , e.g:

=============
protected void DetailsView1_ItemUpdating(object sender,
DetailsViewUpdateEventArgs e)
{
foreach(string key in e.NewValues.Keys)
{
Response.Write("<br>" + key + " " + e.NewValues[key]);
}

e.Cancel = true;
}
============

we can have a look whether all the parameters are provided correclty....
Also, on sqlserver side, we can using sqlprofiler to monitor whether the
final sqlstatement has contained the correctly paratmeters....

BTW, I've also pasted my test page's aspx template below for your
reference:

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

==================================
<div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:databaseConnectionString %>"
DeleteCommand="DELETE FROM [items] WHERE [id] = @id"
InsertCommand="INSERT INTO [items] ([name], [priority]) VALUES (@name,
@priority)"
SelectCommand="SELECT [id], [name], [priority] FROM [items]"
UpdateCommand="UPDATE [items] SET [name] = @name, [priority] = @priority
WHERE [id] = @id">
<DeleteParameters>
<asp:parameter Name="id" Type="Int64" />
</DeleteParameters>
<UpdateParameters>
<asp:parameter Name="name" Type="String" />
<asp:parameter Name="priority" Type="Int32" />
<asp:parameter Name="id" Type="Int64" />
</UpdateParameters>
<InsertParameters>
<asp:parameter Name="name" Type="String" />
<asp:parameter Name="priority" Type="Int32" />
</InsertParameters>
</asp:SqlDataSource>
<asp:DetailsView ID="DetailsView1" runat="server"
AllowPaging="True" AutoGenerateRows="False"
DataKeyNames="id" DataSourceID="SqlDataSource1" Height="50px"
Width="125px" OnItemUpdating="DetailsView1_ItemUpdating">
<Fields>
<asp:BoundField DataField="id" HeaderText="id"
InsertVisible="False" ReadOnly="True"
SortExpression="id" />
<asp:BoundField DataField="name" HeaderText="name"
SortExpression="name" />
<asp:TemplateField HeaderText="priority"
SortExpression="priority">
<EditItemTemplate>
<asp:DropDownList ID="lstPriority" runat="server"
SelectedValue='<%# Bind("priority") %>' DataSourceID="SqlDataSource3"
DataTextField="pname" DataValueField="pid">
<asp:ListItem Value="0">low</asp:ListItem>
<asp:ListItem Value="1">middle</asp:ListItem>
<asp:ListItem Value="2">high</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource3"
runat="server" CacheDuration="300" ConnectionString="<%$
ConnectionStrings:databaseConnectionString %>"
EnableCaching="True" SelectCommand="SELECT
DISTINCT [pid], [pname] FROM [priorities]">
</asp:SqlDataSource>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#
Bind("priority") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:DropDownList ID="lstPriority" runat="server"
Enabled="False" SelectedValue='<%# Bind("priority") %>'
DataSourceID="SqlDataSource2" DataTextField="pname" DataValueField="pid">
<asp:ListItem Value="0">low</asp:ListItem>
<asp:ListItem Value="1">middle</asp:ListItem>
<asp:ListItem Value="2">high</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2"
runat="server" CacheDuration="600" ConnectionString="<%$
ConnectionStrings:databaseConnectionString %>"
EnableCaching="True" SelectCommand="SELECT
DISTINCT [pid], [pname] FROM [priorities]">
</asp:SqlDataSource>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True"
ShowEditButton="True" ShowInsertButton="True" />
</Fields>
</asp:DetailsView>

</div>
=======================




--------------------
| From: "Trevor Bezotte" <[email protected]>
| Subject: DetailsView EditItemTemplate DropdownList Update Problem
| Date: Thu, 1 Dec 2005 14:53:40 -0600
| Lines: 234
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| X-RFC2646: Format=Flowed; Original
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| NNTP-Posting-Host: global.erdman.com 12.20.65.30
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet.datagridcontrol:14838
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
|
| Hi!
|
| I have a DetailsView with a DropDownList in an EditItemTemplate, I know,
| pretty cool right? But when I try to Update the table with a new value
from
| the DropDownList the table does not get updated with the new value. I'm
new
| at this and I'm sure I'm overlooking something simple here. I'll post
the
| ASP code, hopefully someone can help me with this one.
|
| Thank you!
|
|
| <%@ Page Language="C#" masterpagefile="~/software.master"
| AutoEventWireup="true" CodeFile="MasterDetail.aspx.cs" Debug="true"
| Inherits="MasterDetail" %>
|
| <asp:Content ID="SoftwareData" runat="server"
| ContentPlaceHolderID="PageBody">
|
|
|
| <table><tr>
|
| <td valign="top" style="width: 280px">
|
| <asp:GridView ID="SummaryGrid" runat="server"
| DataSourceID="AppsDBDataSource"
|
| EnableViewState="False"
|
| DataKeyNames="ci_id" AllowPaging="True"
|
| AutoGenerateSelectButton="True"
|
| AutoGenerateColumns="False" style="left: 73px; position: relative; top:
9px"
| BackColor="White" BorderColor="#999999" BorderStyle="None"
BorderWidth="1px"
| CellPadding="3" Font-Names="Arial" Font-Size="X-Small"
GridLines="Vertical"
| Width="492px" PageSize="5">
|
| <Columns>
|
| <asp:BoundField DataField="manufacturer" HeaderText="Manufacturer" />
|
| <asp:BoundField DataField="title" HeaderText="Title" />
|
| <asp:BoundField DataField="version" HeaderText="Version" />
|
| </Columns>
|
| <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
|
| <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
|
| <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White"
/>
|
| <PagerStyle BackColor="#999999" ForeColor="Black"
HorizontalAlign="Center"
| />
|
| <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
|
| <AlternatingRowStyle BackColor="Gainsboro" />
|
| </asp:GridView>
|
| </td>
|
| <td valign="top">
|
| <asp:DetailsView ID="DetailsView1" runat="server"
|
| DataKeyNames="ci_id, media_type_id"
|
| HeaderText="Software Package Details"
|
| EmptyDataText="No package currently selected"
|
| DataSourceID="RowDataSource"
|
| AutoGenerateInsertButton="True"
|
| AutoGenerateDeleteButton="True"
|
| AutoGenerateEditButton="True" OnItemUpdated="DetailsView1_ItemUpdated"
| style="left: 73px; position: relative; top: 9px" BackColor="White"
| BorderColor="#999999" BorderStyle="None" BorderWidth="1px"
CellPadding="3"
| Font-Names="Arial" Font-Size="X-Small" GridLines="Vertical"
Width="320px"
| AutoGenerateRows="False">
|
| <Fields>
|
| <asp:BoundField DataField="ci_id" HeaderText="ID" ReadOnly="True" />
|
| <asp:CheckBoxField DataField="active" HeaderText="Active"
| SortExpression="active" />
|
| <asp:BoundField DataField="title" HeaderText="Title" >
|
| <ControlStyle Width="225px" />
|
| </asp:BoundField>
|
| <asp:BoundField DataField="version" HeaderText="Version" />
|
| <asp:BoundField DataField="other_version_info" HeaderText="Version Info"
/>
|
| <asp:BoundField DataField="manufacturer" HeaderText="Manufacturer" />
|
| <asp:TemplateField HeaderText="Media">
|
| <EditItemTemplate>
|
| &nbsp;
|
| <asp:DropDownList ID="DropDownList1" runat="server"
| DataSourceID="SQLMediaTypes"
|
| DataTextField="media_type" DataValueField="media_type_id" Style="left:
-6px;
|
| position: relative; top: 0px" Width="161px" SelectedValue='<%#
| Bind("media_type_id") %>'>
|
| </asp:DropDownList>
|
| </EditItemTemplate>
|
| <InsertItemTemplate>
|
| <asp:DropDownList ID="DropDownList2" runat="server"
| DataSourceID="SQLMediaTypes"
|
| DataTextField="media_type" DataValueField="media_type_id" Style="left:
0px;
|
| position: relative; top: 0px" Width="161px" SelectedValue='<%#
| Bind("media_type_id") %>'>
|
| </asp:DropDownList>
|
| </InsertItemTemplate>
|
| <ItemTemplate>
|
| <asp:Label ID="Label1" runat="server" Text='<%# Bind("media_type")
| %>'></asp:Label>
|
| </ItemTemplate>
|
| </asp:TemplateField>
|
| <asp:BoundField DataField="license_info" HeaderText="License Info" />
|
| <asp:BoundField DataField="date_purchased" HeaderText="Purchase Date"
| SortExpression="date_purchased" />
|
|
| </Fields>
|
| <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
|
| <EditRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White"
| Font-Names="Arial" Font-Size="X-Small" />
|
| <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
|
| <PagerStyle BackColor="#999999" ForeColor="Black"
HorizontalAlign="Center"
| />
|
| <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
|
| <AlternatingRowStyle BackColor="Gainsboro" />
|
| </asp:DetailsView>
|
| </td>
|
| </tr></table>
|
| <asp:Label ID="Label2" runat="server" Font-Names="Courier New"
Height="28px"
| Style="z-index: 103;
|
| left: 28px; position: absolute; top: -298px" Width="379px">Application
| Management Database</asp:Label>
|
| <asp:SqlDataSource ID="AppsDBDataSource" runat="server"
|
| EnableCaching="false" CacheKeyDependency="AppsDBDataSource_Controller"
|
| ConnectionString='<%$ ConnectionStrings:LocalAppsDB %>'
|
| SelectCommand="SELECT * FROM vwSoftware">
|
| </asp:SqlDataSource>
|
| <asp:SqlDataSource ID="RowDataSource" runat="server"
|
| EnableCaching="false"
|
| ConnectionString='<%$ ConnectionStrings:LocalAppsDB %>'
|
| SelectCommand="SELECT * FROM vwSoftware WHERE ci_id=@ci_id"
|
| UpdateCommand="UPDATE software SET active=@active, title=@title,
| version=@version, other_version_info=@other_version_info,
| manufacturer=@manufacturer, media_type_id=@media_type_id,
| license_info=@license_info, date_purchased=@date_purchased WHERE
| ci_id=@ci_id"
|
| InsertCommand="INSERT INTO software(active, title, version,
| other_version_info, manufacturer, media_type_id, license_info,
| date_purchased) VALUES(@active, @title, @version, @other_version_info,
| @manufacturer, @media_type_id, @license_info, @date_purchased)"
|
| DeleteCommand="DELETE FROM software WHERE ci_id=@ci_id">
|
| <SelectParameters>
|
| <asp:ControlParameter Name="ci_id" ControlID="SummaryGrid"
| PropertyName="SelectedValue" />
|
| </SelectParameters>
|
| </asp:SqlDataSource>
|
| <asp:SqlDataSource ID="SQLMediaTypes" runat="server"
ConnectionString="<%$
| ConnectionStrings:LocalAppsDB %>"
|
| OnSelecting="SQLMediaTypes_Selecting" ProviderName="<%$
| ConnectionStrings:LocalAppsDB.ProviderName %>"
|
| SelectCommand="SELECT [media_type_id], [media_type] FROM
| [media_type]"></asp:SqlDataSource>
|
|
| </asp:Content>
|
|
|
 
S

Steven Cheng[MSFT]

Thanks for your response Trevor,

So the problems seems occured between the DataBound control and the backend
database....., Just during the DataSource control's processing. Would you
try creating a complete new page and readd such databound, datasource
controls to see whether the behavior always remains? I think this is
likely a page specific issue....

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "Trevor Bezotte" <[email protected]>
| References: <#[email protected]>
<[email protected]>
| Subject: Re: DetailsView EditItemTemplate DropdownList Update Problem
| Date: Fri, 2 Dec 2005 08:36:00 -0600
| Lines: 407
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| X-RFC2646: Format=Flowed; Original
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| NNTP-Posting-Host: global.erdman.com 12.20.65.30
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet.datagridcontrol:14843
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
|
| I checked the profiler and it shows correct parameter, but it does not
show
| the correct parameter value.
|
| I tried your ItemUpdating code but it does not get fired.
|
|
|
|
| | > Hi Trevor,
| >
| > Welcome to ASPNET newsgroup.
| > Regarding on the DetailsView TemplateField updating problem, based on my
| > experience, for template fields, we can just enable two -way databinding
| > as long as we use the <%# bind(....) %> expression in databinding
| > expression. Also, I've checked the code snippet you provide and compare
to
| > my local test page, seem haven't found any particular difference...
| > Have you tried create a new page and regenerate such steps(maybe you can
| > just use a detailsView without GridView to make the things
| > simplified....)...
| >
| > Also, one way for testing is register the DetailsView's ItemUpdating
event
| > and printout all the new paramters' value there , e.g:
| >
| > =============
| > protected void DetailsView1_ItemUpdating(object sender,
| > DetailsViewUpdateEventArgs e)
| > {
| > foreach(string key in e.NewValues.Keys)
| > {
| > Response.Write("<br>" + key + " " + e.NewValues[key]);
| > }
| >
| > e.Cancel = true;
| > }
| > ============
| >
| > we can have a look whether all the parameters are provided correclty....
| > Also, on sqlserver side, we can using sqlprofiler to monitor whether the
| > final sqlstatement has contained the correctly paratmeters....
| >
| > BTW, I've also pasted my test page's aspx template below for your
| > reference:
| >
| > Hope helps. Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| > ==================================
| > <div>
| > <asp:SqlDataSource ID="SqlDataSource1" runat="server"
| > ConnectionString="<%$ ConnectionStrings:databaseConnectionString %>"
| > DeleteCommand="DELETE FROM [items] WHERE [id] = @id"
| > InsertCommand="INSERT INTO [items] ([name], [priority]) VALUES (@name,
| > @priority)"
| > SelectCommand="SELECT [id], [name], [priority] FROM [items]"
| > UpdateCommand="UPDATE [items] SET [name] = @name, [priority] = @priority
| > WHERE [id] = @id">
| > <DeleteParameters>
| > <asp:parameter Name="id" Type="Int64" />
| > </DeleteParameters>
| > <UpdateParameters>
| > <asp:parameter Name="name" Type="String" />
| > <asp:parameter Name="priority" Type="Int32" />
| > <asp:parameter Name="id" Type="Int64" />
| > </UpdateParameters>
| > <InsertParameters>
| > <asp:parameter Name="name" Type="String" />
| > <asp:parameter Name="priority" Type="Int32" />
| > </InsertParameters>
| > </asp:SqlDataSource>
| > <asp:DetailsView ID="DetailsView1" runat="server"
| > AllowPaging="True" AutoGenerateRows="False"
| > DataKeyNames="id" DataSourceID="SqlDataSource1" Height="50px"
| > Width="125px" OnItemUpdating="DetailsView1_ItemUpdating">
| > <Fields>
| > <asp:BoundField DataField="id" HeaderText="id"
| > InsertVisible="False" ReadOnly="True"
| > SortExpression="id" />
| > <asp:BoundField DataField="name" HeaderText="name"
| > SortExpression="name" />
| > <asp:TemplateField HeaderText="priority"
| > SortExpression="priority">
| > <EditItemTemplate>
| > <asp:DropDownList ID="lstPriority" runat="server"
| > SelectedValue='<%# Bind("priority") %>' DataSourceID="SqlDataSource3"
| > DataTextField="pname" DataValueField="pid">
| > <asp:ListItem Value="0">low</asp:ListItem>
| > <asp:ListItem Value="1">middle</asp:ListItem>
| > <asp:ListItem Value="2">high</asp:ListItem>
| > </asp:DropDownList>
| > <asp:SqlDataSource ID="SqlDataSource3"
| > runat="server" CacheDuration="300" ConnectionString="<%$
| > ConnectionStrings:databaseConnectionString %>"
| > EnableCaching="True" SelectCommand="SELECT
| > DISTINCT [pid], [pname] FROM [priorities]">
| > </asp:SqlDataSource>
| > </EditItemTemplate>
| > <InsertItemTemplate>
| > <asp:TextBox ID="TextBox1" runat="server"
Text='<%#
| > Bind("priority") %>'></asp:TextBox>
| > </InsertItemTemplate>
| > <ItemTemplate>
| > <asp:DropDownList ID="lstPriority" runat="server"
| > Enabled="False" SelectedValue='<%# Bind("priority") %>'
| > DataSourceID="SqlDataSource2" DataTextField="pname"
DataValueField="pid">
| > <asp:ListItem Value="0">low</asp:ListItem>
| > <asp:ListItem Value="1">middle</asp:ListItem>
| > <asp:ListItem Value="2">high</asp:ListItem>
| > </asp:DropDownList>
| > <asp:SqlDataSource ID="SqlDataSource2"
| > runat="server" CacheDuration="600" ConnectionString="<%$
| > ConnectionStrings:databaseConnectionString %>"
| > EnableCaching="True" SelectCommand="SELECT
| > DISTINCT [pid], [pname] FROM [priorities]">
| > </asp:SqlDataSource>
| > </ItemTemplate>
| > </asp:TemplateField>
| > <asp:CommandField ShowDeleteButton="True"
| > ShowEditButton="True" ShowInsertButton="True" />
| > </Fields>
| > </asp:DetailsView>
| >
| > </div>
| > =======================
| >
| >
| >
| >
| > --------------------
| > | From: "Trevor Bezotte" <[email protected]>
| > | Subject: DetailsView EditItemTemplate DropdownList Update Problem
| > | Date: Thu, 1 Dec 2005 14:53:40 -0600
| > | Lines: 234
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| > | X-RFC2646: Format=Flowed; Original
| > | Message-ID: <#[email protected]>
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > | NNTP-Posting-Host: global.erdman.com 12.20.65.30
| > | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| > | Xref: TK2MSFTNGXA02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet.datagridcontrol:14838
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > |
| > | Hi!
| > |
| > | I have a DetailsView with a DropDownList in an EditItemTemplate, I
know,
| > | pretty cool right? But when I try to Update the table with a new value
| > from
| > | the DropDownList the table does not get updated with the new value.
I'm
| > new
| > | at this and I'm sure I'm overlooking something simple here. I'll post
| > the
| > | ASP code, hopefully someone can help me with this one.
| > |
| > | Thank you!
| > |
| > |
| > | <%@ Page Language="C#" masterpagefile="~/software.master"
| > | AutoEventWireup="true" CodeFile="MasterDetail.aspx.cs" Debug="true"
| > | Inherits="MasterDetail" %>
| > |
| > | <asp:Content ID="SoftwareData" runat="server"
| > | ContentPlaceHolderID="PageBody">
| > |
| > |
| > |
| > | <table><tr>
| > |
| > | <td valign="top" style="width: 280px">
| > |
| > | <asp:GridView ID="SummaryGrid" runat="server"
| > | DataSourceID="AppsDBDataSource"
| > |
| > | EnableViewState="False"
| > |
| > | DataKeyNames="ci_id" AllowPaging="True"
| > |
| > | AutoGenerateSelectButton="True"
| > |
| > | AutoGenerateColumns="False" style="left: 73px; position: relative;
top:
| > 9px"
| > | BackColor="White" BorderColor="#999999" BorderStyle="None"
| > BorderWidth="1px"
| > | CellPadding="3" Font-Names="Arial" Font-Size="X-Small"
| > GridLines="Vertical"
| > | Width="492px" PageSize="5">
| > |
| > | <Columns>
| > |
| > | <asp:BoundField DataField="manufacturer" HeaderText="Manufacturer" />
| > |
| > | <asp:BoundField DataField="title" HeaderText="Title" />
| > |
| > | <asp:BoundField DataField="version" HeaderText="Version" />
| > |
| > | </Columns>
| > |
| > | <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
| > |
| > | <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
| > |
| > | <SelectedRowStyle BackColor="#008A8C" Font-Bold="True"
ForeColor="White"
| > />
| > |
| > | <PagerStyle BackColor="#999999" ForeColor="Black"
| > HorizontalAlign="Center"
| > | />
| > |
| > | <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
| > |
| > | <AlternatingRowStyle BackColor="Gainsboro" />
| > |
| > | </asp:GridView>
| > |
| > | </td>
| > |
| > | <td valign="top">
| > |
| > | <asp:DetailsView ID="DetailsView1" runat="server"
| > |
| > | DataKeyNames="ci_id, media_type_id"
| > |
| > | HeaderText="Software Package Details"
| > |
| > | EmptyDataText="No package currently selected"
| > |
| > | DataSourceID="RowDataSource"
| > |
| > | AutoGenerateInsertButton="True"
| > |
| > | AutoGenerateDeleteButton="True"
| > |
| > | AutoGenerateEditButton="True" OnItemUpdated="DetailsView1_ItemUpdated"
| > | style="left: 73px; position: relative; top: 9px" BackColor="White"
| > | BorderColor="#999999" BorderStyle="None" BorderWidth="1px"
| > CellPadding="3"
| > | Font-Names="Arial" Font-Size="X-Small" GridLines="Vertical"
| > Width="320px"
| > | AutoGenerateRows="False">
| > |
| > | <Fields>
| > |
| > | <asp:BoundField DataField="ci_id" HeaderText="ID" ReadOnly="True" />
| > |
| > | <asp:CheckBoxField DataField="active" HeaderText="Active"
| > | SortExpression="active" />
| > |
| > | <asp:BoundField DataField="title" HeaderText="Title" >
| > |
| > | <ControlStyle Width="225px" />
| > |
| > | </asp:BoundField>
| > |
| > | <asp:BoundField DataField="version" HeaderText="Version" />
| > |
| > | <asp:BoundField DataField="other_version_info" HeaderText="Version
Info"
| > />
| > |
| > | <asp:BoundField DataField="manufacturer" HeaderText="Manufacturer" />
| > |
| > | <asp:TemplateField HeaderText="Media">
| > |
| > | <EditItemTemplate>
| > |
| > | &nbsp;
| > |
| > | <asp:DropDownList ID="DropDownList1" runat="server"
| > | DataSourceID="SQLMediaTypes"
| > |
| > | DataTextField="media_type" DataValueField="media_type_id" Style="left:
| > -6px;
| > |
| > | position: relative; top: 0px" Width="161px" SelectedValue='<%#
| > | Bind("media_type_id") %>'>
| > |
| > | </asp:DropDownList>
| > |
| > | </EditItemTemplate>
| > |
| > | <InsertItemTemplate>
| > |
| > | <asp:DropDownList ID="DropDownList2" runat="server"
| > | DataSourceID="SQLMediaTypes"
| > |
| > | DataTextField="media_type" DataValueField="media_type_id" Style="left:
| > 0px;
| > |
| > | position: relative; top: 0px" Width="161px" SelectedValue='<%#
| > | Bind("media_type_id") %>'>
| > |
| > | </asp:DropDownList>
| > |
| > | </InsertItemTemplate>
| > |
| > | <ItemTemplate>
| > |
| > | <asp:Label ID="Label1" runat="server" Text='<%# Bind("media_type")
| > | %>'></asp:Label>
| > |
| > | </ItemTemplate>
| > |
| > | </asp:TemplateField>
| > |
| > | <asp:BoundField DataField="license_info" HeaderText="License Info" />
| > |
| > | <asp:BoundField DataField="date_purchased" HeaderText="Purchase Date"
| > | SortExpression="date_purchased" />
| > |
| > |
| > | </Fields>
| > |
| > | <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
| > |
| > | <EditRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White"
| > | Font-Names="Arial" Font-Size="X-Small" />
| > |
| > | <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
| > |
| > | <PagerStyle BackColor="#999999" ForeColor="Black"
| > HorizontalAlign="Center"
| > | />
| > |
| > | <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
| > |
| > | <AlternatingRowStyle BackColor="Gainsboro" />
| > |
| > | </asp:DetailsView>
| > |
| > | </td>
| > |
| > | </tr></table>
| > |
| > | <asp:Label ID="Label2" runat="server" Font-Names="Courier New"
| > Height="28px"
| > | Style="z-index: 103;
| > |
| > | left: 28px; position: absolute; top: -298px" Width="379px">Application
| > | Management Database</asp:Label>
| > |
| > | <asp:SqlDataSource ID="AppsDBDataSource" runat="server"
| > |
| > | EnableCaching="false" CacheKeyDependency="AppsDBDataSource_Controller"
| > |
| > | ConnectionString='<%$ ConnectionStrings:LocalAppsDB %>'
| > |
| > | SelectCommand="SELECT * FROM vwSoftware">
| > |
| > | </asp:SqlDataSource>
| > |
| > | <asp:SqlDataSource ID="RowDataSource" runat="server"
| > |
| > | EnableCaching="false"
| > |
| > | ConnectionString='<%$ ConnectionStrings:LocalAppsDB %>'
| > |
| > | SelectCommand="SELECT * FROM vwSoftware WHERE ci_id=@ci_id"
| > |
| > | UpdateCommand="UPDATE software SET active=@active, title=@title,
| > | version=@version, other_version_info=@other_version_info,
| > | manufacturer=@manufacturer, media_type_id=@media_type_id,
| > | license_info=@license_info, date_purchased=@date_purchased WHERE
| > | ci_id=@ci_id"
| > |
| > | InsertCommand="INSERT INTO software(active, title, version,
| > | other_version_info, manufacturer, media_type_id, license_info,
| > | date_purchased) VALUES(@active, @title, @version, @other_version_info,
| > | @manufacturer, @media_type_id, @license_info, @date_purchased)"
| > |
| > | DeleteCommand="DELETE FROM software WHERE ci_id=@ci_id">
| > |
| > | <SelectParameters>
| > |
| > | <asp:ControlParameter Name="ci_id" ControlID="SummaryGrid"
| > | PropertyName="SelectedValue" />
| > |
| > | </SelectParameters>
| > |
| > | </asp:SqlDataSource>
| > |
| > | <asp:SqlDataSource ID="SQLMediaTypes" runat="server"
| > ConnectionString="<%$
| > | ConnectionStrings:LocalAppsDB %>"
| > |
| > | OnSelecting="SQLMediaTypes_Selecting" ProviderName="<%$
| > | ConnectionStrings:LocalAppsDB.ProviderName %>"
| > |
| > | SelectCommand="SELECT [media_type_id], [media_type] FROM
| > | [media_type]"></asp:SqlDataSource>
| > |
| > |
| > | </asp:Content>
| > |
| > |
| > |
| >
|
|
|
 
T

Trevor Bezotte

The database gets updated no problem when I use default controls (textboxes)
on the EditItemTemplate, its just when I switch to a dropdownlist for one of
the fields.

The dropdownlist uses values from a related table.


Steven Cheng said:
Thanks for your response Trevor,

So the problems seems occured between the DataBound control and the
backend
database....., Just during the DataSource control's processing. Would
you
try creating a complete new page and readd such databound, datasource
controls to see whether the behavior always remains? I think this is
likely a page specific issue....

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "Trevor Bezotte" <[email protected]>
| References: <#[email protected]>
<[email protected]>
| Subject: Re: DetailsView EditItemTemplate DropdownList Update Problem
| Date: Fri, 2 Dec 2005 08:36:00 -0600
| Lines: 407
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| X-RFC2646: Format=Flowed; Original
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| NNTP-Posting-Host: global.erdman.com 12.20.65.30
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet.datagridcontrol:14843
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
|
| I checked the profiler and it shows correct parameter, but it does not
show
| the correct parameter value.
|
| I tried your ItemUpdating code but it does not get fired.
|
|
|
|
| | > Hi Trevor,
| >
| > Welcome to ASPNET newsgroup.
| > Regarding on the DetailsView TemplateField updating problem, based on
my
| > experience, for template fields, we can just enable two -way
databinding
| > as long as we use the <%# bind(....) %> expression in databinding
| > expression. Also, I've checked the code snippet you provide and
compare
to
| > my local test page, seem haven't found any particular difference...
| > Have you tried create a new page and regenerate such steps(maybe you
can
| > just use a detailsView without GridView to make the things
| > simplified....)...
| >
| > Also, one way for testing is register the DetailsView's ItemUpdating
event
| > and printout all the new paramters' value there , e.g:
| >
| > =============
| > protected void DetailsView1_ItemUpdating(object sender,
| > DetailsViewUpdateEventArgs e)
| > {
| > foreach(string key in e.NewValues.Keys)
| > {
| > Response.Write("<br>" + key + " " + e.NewValues[key]);
| > }
| >
| > e.Cancel = true;
| > }
| > ============
| >
| > we can have a look whether all the parameters are provided
correclty....
| > Also, on sqlserver side, we can using sqlprofiler to monitor whether
the
| > final sqlstatement has contained the correctly paratmeters....
| >
| > BTW, I've also pasted my test page's aspx template below for your
| > reference:
| >
| > Hope helps. Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| > ==================================
| > <div>
| > <asp:SqlDataSource ID="SqlDataSource1" runat="server"
| > ConnectionString="<%$ ConnectionStrings:databaseConnectionString %>"
| > DeleteCommand="DELETE FROM [items] WHERE [id] = @id"
| > InsertCommand="INSERT INTO [items] ([name], [priority]) VALUES (@name,
| > @priority)"
| > SelectCommand="SELECT [id], [name], [priority] FROM
[items]"
| > UpdateCommand="UPDATE [items] SET [name] = @name, [priority] =
@priority
| > WHERE [id] = @id">
| > <DeleteParameters>
| > <asp:parameter Name="id" Type="Int64" />
| > </DeleteParameters>
| > <UpdateParameters>
| > <asp:parameter Name="name" Type="String" />
| > <asp:parameter Name="priority" Type="Int32" />
| > <asp:parameter Name="id" Type="Int64" />
| > </UpdateParameters>
| > <InsertParameters>
| > <asp:parameter Name="name" Type="String" />
| > <asp:parameter Name="priority" Type="Int32" />
| > </InsertParameters>
| > </asp:SqlDataSource>
| > <asp:DetailsView ID="DetailsView1" runat="server"
| > AllowPaging="True" AutoGenerateRows="False"
| > DataKeyNames="id" DataSourceID="SqlDataSource1"
Height="50px"
| > Width="125px" OnItemUpdating="DetailsView1_ItemUpdating">
| > <Fields>
| > <asp:BoundField DataField="id" HeaderText="id"
| > InsertVisible="False" ReadOnly="True"
| > SortExpression="id" />
| > <asp:BoundField DataField="name" HeaderText="name"
| > SortExpression="name" />
| > <asp:TemplateField HeaderText="priority"
| > SortExpression="priority">
| > <EditItemTemplate>
| > <asp:DropDownList ID="lstPriority"
runat="server"
| > SelectedValue='<%# Bind("priority") %>' DataSourceID="SqlDataSource3"
| > DataTextField="pname" DataValueField="pid">
| > <asp:ListItem Value="0">low</asp:ListItem>
| > <asp:ListItem
Value="1">middle</asp:ListItem>
| > <asp:ListItem Value="2">high</asp:ListItem>
| > </asp:DropDownList>
| > <asp:SqlDataSource ID="SqlDataSource3"
| > runat="server" CacheDuration="300" ConnectionString="<%$
| > ConnectionStrings:databaseConnectionString %>"
| > EnableCaching="True" SelectCommand="SELECT
| > DISTINCT [pid], [pname] FROM [priorities]">
| > </asp:SqlDataSource>
| > </EditItemTemplate>
| > <InsertItemTemplate>
| > <asp:TextBox ID="TextBox1" runat="server"
Text='<%#
| > Bind("priority") %>'></asp:TextBox>
| > </InsertItemTemplate>
| > <ItemTemplate>
| > <asp:DropDownList ID="lstPriority"
runat="server"
| > Enabled="False" SelectedValue='<%# Bind("priority") %>'
| > DataSourceID="SqlDataSource2" DataTextField="pname"
DataValueField="pid">
| > <asp:ListItem Value="0">low</asp:ListItem>
| > <asp:ListItem
Value="1">middle</asp:ListItem>
| > <asp:ListItem Value="2">high</asp:ListItem>
| > </asp:DropDownList>
| > <asp:SqlDataSource ID="SqlDataSource2"
| > runat="server" CacheDuration="600" ConnectionString="<%$
| > ConnectionStrings:databaseConnectionString %>"
| > EnableCaching="True" SelectCommand="SELECT
| > DISTINCT [pid], [pname] FROM [priorities]">
| > </asp:SqlDataSource>
| > </ItemTemplate>
| > </asp:TemplateField>
| > <asp:CommandField ShowDeleteButton="True"
| > ShowEditButton="True" ShowInsertButton="True" />
| > </Fields>
| > </asp:DetailsView>
| >
| > </div>
| > =======================
| >
| >
| >
| >
| > --------------------
| > | From: "Trevor Bezotte" <[email protected]>
| > | Subject: DetailsView EditItemTemplate DropdownList Update Problem
| > | Date: Thu, 1 Dec 2005 14:53:40 -0600
| > | Lines: 234
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| > | X-RFC2646: Format=Flowed; Original
| > | Message-ID: <#[email protected]>
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > | NNTP-Posting-Host: global.erdman.com 12.20.65.30
| > | Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| > | Xref: TK2MSFTNGXA02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet.datagridcontrol:14838
| > | X-Tomcat-NG:
microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > |
| > | Hi!
| > |
| > | I have a DetailsView with a DropDownList in an EditItemTemplate, I
know,
| > | pretty cool right? But when I try to Update the table with a new
value
| > from
| > | the DropDownList the table does not get updated with the new value.
I'm
| > new
| > | at this and I'm sure I'm overlooking something simple here. I'll
post
| > the
| > | ASP code, hopefully someone can help me with this one.
| > |
| > | Thank you!
| > |
| > |
| > | <%@ Page Language="C#" masterpagefile="~/software.master"
| > | AutoEventWireup="true" CodeFile="MasterDetail.aspx.cs" Debug="true"
| > | Inherits="MasterDetail" %>
| > |
| > | <asp:Content ID="SoftwareData" runat="server"
| > | ContentPlaceHolderID="PageBody">
| > |
| > |
| > |
| > | <table><tr>
| > |
| > | <td valign="top" style="width: 280px">
| > |
| > | <asp:GridView ID="SummaryGrid" runat="server"
| > | DataSourceID="AppsDBDataSource"
| > |
| > | EnableViewState="False"
| > |
| > | DataKeyNames="ci_id" AllowPaging="True"
| > |
| > | AutoGenerateSelectButton="True"
| > |
| > | AutoGenerateColumns="False" style="left: 73px; position: relative;
top:
| > 9px"
| > | BackColor="White" BorderColor="#999999" BorderStyle="None"
| > BorderWidth="1px"
| > | CellPadding="3" Font-Names="Arial" Font-Size="X-Small"
| > GridLines="Vertical"
| > | Width="492px" PageSize="5">
| > |
| > | <Columns>
| > |
| > | <asp:BoundField DataField="manufacturer" HeaderText="Manufacturer"
/>
| > |
| > | <asp:BoundField DataField="title" HeaderText="Title" />
| > |
| > | <asp:BoundField DataField="version" HeaderText="Version" />
| > |
| > | </Columns>
| > |
| > | <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
| > |
| > | <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
| > |
| > | <SelectedRowStyle BackColor="#008A8C" Font-Bold="True"
ForeColor="White"
| > />
| > |
| > | <PagerStyle BackColor="#999999" ForeColor="Black"
| > HorizontalAlign="Center"
| > | />
| > |
| > | <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White"
/>
| > |
| > | <AlternatingRowStyle BackColor="Gainsboro" />
| > |
| > | </asp:GridView>
| > |
| > | </td>
| > |
| > | <td valign="top">
| > |
| > | <asp:DetailsView ID="DetailsView1" runat="server"
| > |
| > | DataKeyNames="ci_id, media_type_id"
| > |
| > | HeaderText="Software Package Details"
| > |
| > | EmptyDataText="No package currently selected"
| > |
| > | DataSourceID="RowDataSource"
| > |
| > | AutoGenerateInsertButton="True"
| > |
| > | AutoGenerateDeleteButton="True"
| > |
| > | AutoGenerateEditButton="True"
OnItemUpdated="DetailsView1_ItemUpdated"
| > | style="left: 73px; position: relative; top: 9px" BackColor="White"
| > | BorderColor="#999999" BorderStyle="None" BorderWidth="1px"
| > CellPadding="3"
| > | Font-Names="Arial" Font-Size="X-Small" GridLines="Vertical"
| > Width="320px"
| > | AutoGenerateRows="False">
| > |
| > | <Fields>
| > |
| > | <asp:BoundField DataField="ci_id" HeaderText="ID" ReadOnly="True" />
| > |
| > | <asp:CheckBoxField DataField="active" HeaderText="Active"
| > | SortExpression="active" />
| > |
| > | <asp:BoundField DataField="title" HeaderText="Title" >
| > |
| > | <ControlStyle Width="225px" />
| > |
| > | </asp:BoundField>
| > |
| > | <asp:BoundField DataField="version" HeaderText="Version" />
| > |
| > | <asp:BoundField DataField="other_version_info" HeaderText="Version
Info"
| > />
| > |
| > | <asp:BoundField DataField="manufacturer" HeaderText="Manufacturer"
/>
| > |
| > | <asp:TemplateField HeaderText="Media">
| > |
| > | <EditItemTemplate>
| > |
| > | &nbsp;
| > |
| > | <asp:DropDownList ID="DropDownList1" runat="server"
| > | DataSourceID="SQLMediaTypes"
| > |
| > | DataTextField="media_type" DataValueField="media_type_id"
Style="left:
| > -6px;
| > |
| > | position: relative; top: 0px" Width="161px" SelectedValue='<%#
| > | Bind("media_type_id") %>'>
| > |
| > | </asp:DropDownList>
| > |
| > | </EditItemTemplate>
| > |
| > | <InsertItemTemplate>
| > |
| > | <asp:DropDownList ID="DropDownList2" runat="server"
| > | DataSourceID="SQLMediaTypes"
| > |
| > | DataTextField="media_type" DataValueField="media_type_id"
Style="left:
| > 0px;
| > |
| > | position: relative; top: 0px" Width="161px" SelectedValue='<%#
| > | Bind("media_type_id") %>'>
| > |
| > | </asp:DropDownList>
| > |
| > | </InsertItemTemplate>
| > |
| > | <ItemTemplate>
| > |
| > | <asp:Label ID="Label1" runat="server" Text='<%# Bind("media_type")
| > | %>'></asp:Label>
| > |
| > | </ItemTemplate>
| > |
| > | </asp:TemplateField>
| > |
| > | <asp:BoundField DataField="license_info" HeaderText="License Info"
/>
| > |
| > | <asp:BoundField DataField="date_purchased" HeaderText="Purchase
Date"
| > | SortExpression="date_purchased" />
| > |
| > |
| > | </Fields>
| > |
| > | <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
| > |
| > | <EditRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White"
| > | Font-Names="Arial" Font-Size="X-Small" />
| > |
| > | <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
| > |
| > | <PagerStyle BackColor="#999999" ForeColor="Black"
| > HorizontalAlign="Center"
| > | />
| > |
| > | <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White"
/>
| > |
| > | <AlternatingRowStyle BackColor="Gainsboro" />
| > |
| > | </asp:DetailsView>
| > |
| > | </td>
| > |
| > | </tr></table>
| > |
| > | <asp:Label ID="Label2" runat="server" Font-Names="Courier New"
| > Height="28px"
| > | Style="z-index: 103;
| > |
| > | left: 28px; position: absolute; top: -298px"
Width="379px">Application
| > | Management Database</asp:Label>
| > |
| > | <asp:SqlDataSource ID="AppsDBDataSource" runat="server"
| > |
| > | EnableCaching="false"
CacheKeyDependency="AppsDBDataSource_Controller"
| > |
| > | ConnectionString='<%$ ConnectionStrings:LocalAppsDB %>'
| > |
| > | SelectCommand="SELECT * FROM vwSoftware">
| > |
| > | </asp:SqlDataSource>
| > |
| > | <asp:SqlDataSource ID="RowDataSource" runat="server"
| > |
| > | EnableCaching="false"
| > |
| > | ConnectionString='<%$ ConnectionStrings:LocalAppsDB %>'
| > |
| > | SelectCommand="SELECT * FROM vwSoftware WHERE ci_id=@ci_id"
| > |
| > | UpdateCommand="UPDATE software SET active=@active, title=@title,
| > | version=@version, other_version_info=@other_version_info,
| > | manufacturer=@manufacturer, media_type_id=@media_type_id,
| > | license_info=@license_info, date_purchased=@date_purchased WHERE
| > | ci_id=@ci_id"
| > |
| > | InsertCommand="INSERT INTO software(active, title, version,
| > | other_version_info, manufacturer, media_type_id, license_info,
| > | date_purchased) VALUES(@active, @title, @version,
@other_version_info,
| > | @manufacturer, @media_type_id, @license_info, @date_purchased)"
| > |
| > | DeleteCommand="DELETE FROM software WHERE ci_id=@ci_id">
| > |
| > | <SelectParameters>
| > |
| > | <asp:ControlParameter Name="ci_id" ControlID="SummaryGrid"
| > | PropertyName="SelectedValue" />
| > |
| > | </SelectParameters>
| > |
| > | </asp:SqlDataSource>
| > |
| > | <asp:SqlDataSource ID="SQLMediaTypes" runat="server"
| > ConnectionString="<%$
| > | ConnectionStrings:LocalAppsDB %>"
| > |
| > | OnSelecting="SQLMediaTypes_Selecting" ProviderName="<%$
| > | ConnectionStrings:LocalAppsDB.ProviderName %>"
| > |
| > | SelectCommand="SELECT [media_type_id], [media_type] FROM
| > | [media_type]"></asp:SqlDataSource>
| > |
| > |
| > | </asp:Content>
| > |
| > |
| > |
| >
|
|
|
 
S

Steven Cheng[MSFT]

Thanks for your followup.

Seems strange. Would you try making a simplified page with the controls
that can reproduce the problem so that I can test it on my side? Also, you
can post the test database's table structure to me...

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "Trevor Bezotte" <[email protected]>
| References: <#[email protected]>
<[email protected]>
<#[email protected]>
<vscaaXZ#[email protected]>
| Subject: Re: DetailsView EditItemTemplate DropdownList Update Problem
| Date: Mon, 5 Dec 2005 08:56:22 -0600
| Lines: 498
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| X-RFC2646: Format=Flowed; Original
| Message-ID: <#Rh6Pwa#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| NNTP-Posting-Host: global.erdman.com 12.20.65.30
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP15.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet.datagridcontrol:14858
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
|
| The database gets updated no problem when I use default controls
(textboxes)
| on the EditItemTemplate, its just when I switch to a dropdownlist for one
of
| the fields.
|
| The dropdownlist uses values from a related table.
|
|
| | > Thanks for your response Trevor,
| >
| > So the problems seems occured between the DataBound control and the
| > backend
| > database....., Just during the DataSource control's processing. Would
| > you
| > try creating a complete new page and readd such databound, datasource
| > controls to see whether the behavior always remains? I think this is
| > likely a page specific issue....
| >
| > Regards,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| > --------------------
| > | From: "Trevor Bezotte" <[email protected]>
| > | References: <#[email protected]>
| > <[email protected]>
| > | Subject: Re: DetailsView EditItemTemplate DropdownList Update Problem
| > | Date: Fri, 2 Dec 2005 08:36:00 -0600
| > | Lines: 407
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| > | X-RFC2646: Format=Flowed; Original
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| > | Message-ID: <#[email protected]>
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > | NNTP-Posting-Host: global.erdman.com 12.20.65.30
| > | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| > | Xref: TK2MSFTNGXA02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet.datagridcontrol:14843
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > |
| > | I checked the profiler and it shows correct parameter, but it does not
| > show
| > | the correct parameter value.
| > |
| > | I tried your ItemUpdating code but it does not get fired.
| > |
| > |
| > |
| > |
| > | | > | > Hi Trevor,
| > | >
| > | > Welcome to ASPNET newsgroup.
| > | > Regarding on the DetailsView TemplateField updating problem, based
on
| > my
| > | > experience, for template fields, we can just enable two -way
| > databinding
| > | > as long as we use the <%# bind(....) %> expression in databinding
| > | > expression. Also, I've checked the code snippet you provide and
| > compare
| > to
| > | > my local test page, seem haven't found any particular difference...
| > | > Have you tried create a new page and regenerate such steps(maybe
you
| > can
| > | > just use a detailsView without GridView to make the things
| > | > simplified....)...
| > | >
| > | > Also, one way for testing is register the DetailsView's ItemUpdating
| > event
| > | > and printout all the new paramters' value there , e.g:
| > | >
| > | > =============
| > | > protected void DetailsView1_ItemUpdating(object sender,
| > | > DetailsViewUpdateEventArgs e)
| > | > {
| > | > foreach(string key in e.NewValues.Keys)
| > | > {
| > | > Response.Write("<br>" + key + " " + e.NewValues[key]);
| > | > }
| > | >
| > | > e.Cancel = true;
| > | > }
| > | > ============
| > | >
| > | > we can have a look whether all the parameters are provided
| > correclty....
| > | > Also, on sqlserver side, we can using sqlprofiler to monitor
whether
| > the
| > | > final sqlstatement has contained the correctly paratmeters....
| > | >
| > | > BTW, I've also pasted my test page's aspx template below for your
| > | > reference:
| > | >
| > | > Hope helps. Thanks,
| > | >
| > | > Steven Cheng
| > | > Microsoft Online Support
| > | >
| > | > Get Secure! www.microsoft.com/security
| > | > (This posting is provided "AS IS", with no warranties, and confers
no
| > | > rights.)
| > | >
| > | > ==================================
| > | > <div>
| > | > <asp:SqlDataSource ID="SqlDataSource1" runat="server"
| > | > ConnectionString="<%$ ConnectionStrings:databaseConnectionString %>"
| > | > DeleteCommand="DELETE FROM [items] WHERE [id] = @id"
| > | > InsertCommand="INSERT INTO [items] ([name], [priority]) VALUES
(@name,
| > | > @priority)"
| > | > SelectCommand="SELECT [id], [name], [priority] FROM
| > [items]"
| > | > UpdateCommand="UPDATE [items] SET [name] = @name, [priority] =
| > @priority
| > | > WHERE [id] = @id">
| > | > <DeleteParameters>
| > | > <asp:parameter Name="id" Type="Int64" />
| > | > </DeleteParameters>
| > | > <UpdateParameters>
| > | > <asp:parameter Name="name" Type="String" />
| > | > <asp:parameter Name="priority" Type="Int32" />
| > | > <asp:parameter Name="id" Type="Int64" />
| > | > </UpdateParameters>
| > | > <InsertParameters>
| > | > <asp:parameter Name="name" Type="String" />
| > | > <asp:parameter Name="priority" Type="Int32" />
| > | > </InsertParameters>
| > | > </asp:SqlDataSource>
| > | > <asp:DetailsView ID="DetailsView1" runat="server"
| > | > AllowPaging="True" AutoGenerateRows="False"
| > | > DataKeyNames="id" DataSourceID="SqlDataSource1"
| > Height="50px"
| > | > Width="125px" OnItemUpdating="DetailsView1_ItemUpdating">
| > | > <Fields>
| > | > <asp:BoundField DataField="id" HeaderText="id"
| > | > InsertVisible="False" ReadOnly="True"
| > | > SortExpression="id" />
| > | > <asp:BoundField DataField="name" HeaderText="name"
| > | > SortExpression="name" />
| > | > <asp:TemplateField HeaderText="priority"
| > | > SortExpression="priority">
| > | > <EditItemTemplate>
| > | > <asp:DropDownList ID="lstPriority"
| > runat="server"
| > | > SelectedValue='<%# Bind("priority") %>'
DataSourceID="SqlDataSource3"
| > | > DataTextField="pname" DataValueField="pid">
| > | > <asp:ListItem
Value="0">low</asp:ListItem>
| > | > <asp:ListItem
| > Value="1">middle</asp:ListItem>
| > | > <asp:ListItem
Value="2">high</asp:ListItem>
| > | > </asp:DropDownList>
| > | > <asp:SqlDataSource ID="SqlDataSource3"
| > | > runat="server" CacheDuration="300" ConnectionString="<%$
| > | > ConnectionStrings:databaseConnectionString %>"
| > | > EnableCaching="True"
SelectCommand="SELECT
| > | > DISTINCT [pid], [pname] FROM [priorities]">
| > | > </asp:SqlDataSource>
| > | > </EditItemTemplate>
| > | > <InsertItemTemplate>
| > | > <asp:TextBox ID="TextBox1" runat="server"
| > Text='<%#
| > | > Bind("priority") %>'></asp:TextBox>
| > | > </InsertItemTemplate>
| > | > <ItemTemplate>
| > | > <asp:DropDownList ID="lstPriority"
| > runat="server"
| > | > Enabled="False" SelectedValue='<%# Bind("priority") %>'
| > | > DataSourceID="SqlDataSource2" DataTextField="pname"
| > DataValueField="pid">
| > | > <asp:ListItem
Value="0">low</asp:ListItem>
| > | > <asp:ListItem
| > Value="1">middle</asp:ListItem>
| > | > <asp:ListItem
Value="2">high</asp:ListItem>
| > | > </asp:DropDownList>
| > | > <asp:SqlDataSource ID="SqlDataSource2"
| > | > runat="server" CacheDuration="600" ConnectionString="<%$
| > | > ConnectionStrings:databaseConnectionString %>"
| > | > EnableCaching="True"
SelectCommand="SELECT
| > | > DISTINCT [pid], [pname] FROM [priorities]">
| > | > </asp:SqlDataSource>
| > | > </ItemTemplate>
| > | > </asp:TemplateField>
| > | > <asp:CommandField ShowDeleteButton="True"
| > | > ShowEditButton="True" ShowInsertButton="True" />
| > | > </Fields>
| > | > </asp:DetailsView>
| > | >
| > | > </div>
| > | > =======================
| > | >
| > | >
| > | >
| > | >
| > | > --------------------
| > | > | From: "Trevor Bezotte" <[email protected]>
| > | > | Subject: DetailsView EditItemTemplate DropdownList Update Problem
| > | > | Date: Thu, 1 Dec 2005 14:53:40 -0600
| > | > | Lines: 234
| > | > | X-Priority: 3
| > | > | X-MSMail-Priority: Normal
| > | > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| > | > | X-RFC2646: Format=Flowed; Original
| > | > | Message-ID: <#[email protected]>
| > | > | Newsgroups:
microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > | > | NNTP-Posting-Host: global.erdman.com 12.20.65.30
| > | > | Path:
| > TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| > | > | Xref: TK2MSFTNGXA02.phx.gbl
| > | > microsoft.public.dotnet.framework.aspnet.datagridcontrol:14838
| > | > | X-Tomcat-NG:
| > microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > | > |
| > | > | Hi!
| > | > |
| > | > | I have a DetailsView with a DropDownList in an EditItemTemplate, I
| > know,
| > | > | pretty cool right? But when I try to Update the table with a new
| > value
| > | > from
| > | > | the DropDownList the table does not get updated with the new
value.
| > I'm
| > | > new
| > | > | at this and I'm sure I'm overlooking something simple here. I'll
| > post
| > | > the
| > | > | ASP code, hopefully someone can help me with this one.
| > | > |
| > | > | Thank you!
| > | > |
| > | > |
| > | > | <%@ Page Language="C#" masterpagefile="~/software.master"
| > | > | AutoEventWireup="true" CodeFile="MasterDetail.aspx.cs"
Debug="true"
| > | > | Inherits="MasterDetail" %>
| > | > |
| > | > | <asp:Content ID="SoftwareData" runat="server"
| > | > | ContentPlaceHolderID="PageBody">
| > | > |
| > | > |
| > | > |
| > | > | <table><tr>
| > | > |
| > | > | <td valign="top" style="width: 280px">
| > | > |
| > | > | <asp:GridView ID="SummaryGrid" runat="server"
| > | > | DataSourceID="AppsDBDataSource"
| > | > |
| > | > | EnableViewState="False"
| > | > |
| > | > | DataKeyNames="ci_id" AllowPaging="True"
| > | > |
| > | > | AutoGenerateSelectButton="True"
| > | > |
| > | > | AutoGenerateColumns="False" style="left: 73px; position: relative;
| > top:
| > | > 9px"
| > | > | BackColor="White" BorderColor="#999999" BorderStyle="None"
| > | > BorderWidth="1px"
| > | > | CellPadding="3" Font-Names="Arial" Font-Size="X-Small"
| > | > GridLines="Vertical"
| > | > | Width="492px" PageSize="5">
| > | > |
| > | > | <Columns>
| > | > |
| > | > | <asp:BoundField DataField="manufacturer"
HeaderText="Manufacturer"
| > />
| > | > |
| > | > | <asp:BoundField DataField="title" HeaderText="Title" />
| > | > |
| > | > | <asp:BoundField DataField="version" HeaderText="Version" />
| > | > |
| > | > | </Columns>
| > | > |
| > | > | <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
| > | > |
| > | > | <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
| > | > |
| > | > | <SelectedRowStyle BackColor="#008A8C" Font-Bold="True"
| > ForeColor="White"
| > | > />
| > | > |
| > | > | <PagerStyle BackColor="#999999" ForeColor="Black"
| > | > HorizontalAlign="Center"
| > | > | />
| > | > |
| > | > | <HeaderStyle BackColor="#000084" Font-Bold="True"
ForeColor="White"
| > />
| > | > |
| > | > | <AlternatingRowStyle BackColor="Gainsboro" />
| > | > |
| > | > | </asp:GridView>
| > | > |
| > | > | </td>
| > | > |
| > | > | <td valign="top">
| > | > |
| > | > | <asp:DetailsView ID="DetailsView1" runat="server"
| > | > |
| > | > | DataKeyNames="ci_id, media_type_id"
| > | > |
| > | > | HeaderText="Software Package Details"
| > | > |
| > | > | EmptyDataText="No package currently selected"
| > | > |
| > | > | DataSourceID="RowDataSource"
| > | > |
| > | > | AutoGenerateInsertButton="True"
| > | > |
| > | > | AutoGenerateDeleteButton="True"
| > | > |
| > | > | AutoGenerateEditButton="True"
| > OnItemUpdated="DetailsView1_ItemUpdated"
| > | > | style="left: 73px; position: relative; top: 9px" BackColor="White"
| > | > | BorderColor="#999999" BorderStyle="None" BorderWidth="1px"
| > | > CellPadding="3"
| > | > | Font-Names="Arial" Font-Size="X-Small" GridLines="Vertical"
| > | > Width="320px"
| > | > | AutoGenerateRows="False">
| > | > |
| > | > | <Fields>
| > | > |
| > | > | <asp:BoundField DataField="ci_id" HeaderText="ID" ReadOnly="True"
/>
| > | > |
| > | > | <asp:CheckBoxField DataField="active" HeaderText="Active"
| > | > | SortExpression="active" />
| > | > |
| > | > | <asp:BoundField DataField="title" HeaderText="Title" >
| > | > |
| > | > | <ControlStyle Width="225px" />
| > | > |
| > | > | </asp:BoundField>
| > | > |
| > | > | <asp:BoundField DataField="version" HeaderText="Version" />
| > | > |
| > | > | <asp:BoundField DataField="other_version_info" HeaderText="Version
| > Info"
| > | > />
| > | > |
| > | > | <asp:BoundField DataField="manufacturer"
HeaderText="Manufacturer"
| > />
| > | > |
| > | > | <asp:TemplateField HeaderText="Media">
| > | > |
| > | > | <EditItemTemplate>
| > | > |
| > | > | &nbsp;
| > | > |
| > | > | <asp:DropDownList ID="DropDownList1" runat="server"
| > | > | DataSourceID="SQLMediaTypes"
| > | > |
| > | > | DataTextField="media_type" DataValueField="media_type_id"
| > Style="left:
| > | > -6px;
| > | > |
| > | > | position: relative; top: 0px" Width="161px" SelectedValue='<%#
| > | > | Bind("media_type_id") %>'>
| > | > |
| > | > | </asp:DropDownList>
| > | > |
| > | > | </EditItemTemplate>
| > | > |
| > | > | <InsertItemTemplate>
| > | > |
| > | > | <asp:DropDownList ID="DropDownList2" runat="server"
| > | > | DataSourceID="SQLMediaTypes"
| > | > |
| > | > | DataTextField="media_type" DataValueField="media_type_id"
| > Style="left:
| > | > 0px;
| > | > |
| > | > | position: relative; top: 0px" Width="161px" SelectedValue='<%#
| > | > | Bind("media_type_id") %>'>
| > | > |
| > | > | </asp:DropDownList>
| > | > |
| > | > | </InsertItemTemplate>
| > | > |
| > | > | <ItemTemplate>
| > | > |
| > | > | <asp:Label ID="Label1" runat="server" Text='<%# Bind("media_type")
| > | > | %>'></asp:Label>
| > | > |
| > | > | </ItemTemplate>
| > | > |
| > | > | </asp:TemplateField>
| > | > |
| > | > | <asp:BoundField DataField="license_info" HeaderText="License
Info"
| > />
| > | > |
| > | > | <asp:BoundField DataField="date_purchased" HeaderText="Purchase
| > Date"
| > | > | SortExpression="date_purchased" />
| > | > |
| > | > |
| > | > | </Fields>
| > | > |
| > | > | <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
| > | > |
| > | > | <EditRowStyle BackColor="#008A8C" Font-Bold="True"
ForeColor="White"
| > | > | Font-Names="Arial" Font-Size="X-Small" />
| > | > |
| > | > | <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
| > | > |
| > | > | <PagerStyle BackColor="#999999" ForeColor="Black"
| > | > HorizontalAlign="Center"
| > | > | />
| > | > |
| > | > | <HeaderStyle BackColor="#000084" Font-Bold="True"
ForeColor="White"
| > />
| > | > |
| > | > | <AlternatingRowStyle BackColor="Gainsboro" />
| > | > |
| > | > | </asp:DetailsView>
| > | > |
| > | > | </td>
| > | > |
| > | > | </tr></table>
| > | > |
| > | > | <asp:Label ID="Label2" runat="server" Font-Names="Courier New"
| > | > Height="28px"
| > | > | Style="z-index: 103;
| > | > |
| > | > | left: 28px; position: absolute; top: -298px"
| > Width="379px">Application
| > | > | Management Database</asp:Label>
| > | > |
| > | > | <asp:SqlDataSource ID="AppsDBDataSource" runat="server"
| > | > |
| > | > | EnableCaching="false"
| > CacheKeyDependency="AppsDBDataSource_Controller"
| > | > |
| > | > | ConnectionString='<%$ ConnectionStrings:LocalAppsDB %>'
| > | > |
| > | > | SelectCommand="SELECT * FROM vwSoftware">
| > | > |
| > | > | </asp:SqlDataSource>
| > | > |
| > | > | <asp:SqlDataSource ID="RowDataSource" runat="server"
| > | > |
| > | > | EnableCaching="false"
| > | > |
| > | > | ConnectionString='<%$ ConnectionStrings:LocalAppsDB %>'
| > | > |
| > | > | SelectCommand="SELECT * FROM vwSoftware WHERE ci_id=@ci_id"
| > | > |
| > | > | UpdateCommand="UPDATE software SET active=@active, title=@title,
| > | > | version=@version, other_version_info=@other_version_info,
| > | > | manufacturer=@manufacturer, media_type_id=@media_type_id,
| > | > | license_info=@license_info, date_purchased=@date_purchased WHERE
| > | > | ci_id=@ci_id"
| > | > |
| > | > | InsertCommand="INSERT INTO software(active, title, version,
| > | > | other_version_info, manufacturer, media_type_id, license_info,
| > | > | date_purchased) VALUES(@active, @title, @version,
| > @other_version_info,
| > | > | @manufacturer, @media_type_id, @license_info, @date_purchased)"
| > | > |
| > | > | DeleteCommand="DELETE FROM software WHERE ci_id=@ci_id">
| > | > |
| > | > | <SelectParameters>
| > | > |
| > | > | <asp:ControlParameter Name="ci_id" ControlID="SummaryGrid"
| > | > | PropertyName="SelectedValue" />
| > | > |
| > | > | </SelectParameters>
| > | > |
| > | > | </asp:SqlDataSource>
| > | > |
| > | > | <asp:SqlDataSource ID="SQLMediaTypes" runat="server"
| > | > ConnectionString="<%$
| > | > | ConnectionStrings:LocalAppsDB %>"
| > | > |
| > | > | OnSelecting="SQLMediaTypes_Selecting" ProviderName="<%$
| > | > | ConnectionStrings:LocalAppsDB.ProviderName %>"
| > | > |
| > | > | SelectCommand="SELECT [media_type_id], [media_type] FROM
| > | > | [media_type]"></asp:SqlDataSource>
| > | > |
| > | > |
| > | > | </asp:Content>
| > | > |
| > | > |
| > | > |
| > | >
| > |
| > |
| > |
| >
|
|
|
 
T

Trevor Bezotte

funny, it works fine when the page is simplified to just the detailsview,
here's the code...

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="testForm.aspx.vb"
Inherits="testForm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Test Page</title>

</head>

<body>

<form id="form1" runat="server">

<div>

<asp:SqlDataSource ID="SqlDataSource1" runat="server"

ConnectionString="<%$ ConnectionStrings:databaseConnectionString %>"

DeleteCommand="DELETE FROM [software] WHERE [ci_id] = @ci_id"

InsertCommand="INSERT INTO software(active, title, version,
other_version_info, manufacturer, media_type_id, license_info,
date_purchased) VALUES(@active, @title, @version, @other_version_info,
@manufacturer, @media_type_id, @license_info, @date_purchased)"

SelectCommand="SELECT ci_id, active, title, version, other_version_info,
manufacturer, media_type_id, license_info, date_purchased FROM software"

UpdateCommand="UPDATE software SET active=@active, title=@title,
version=@version, other_version_info=@other_version_info,
manufacturer=@manufacturer, media_type_id=@media_type_id,
license_info=@license_info, date_purchased=@date_purchased WHERE
ci_id=@ci_id">

<DeleteParameters>

<asp:parameter Name="ci_id" Type="Int64" />

</DeleteParameters>

<UpdateParameters>

<asp:parameter Name="active" Type="Boolean" />

<asp:parameter Name="title" Type="String" />

<asp:parameter Name="version" Type="String" />

<asp:parameter Name="other_version_info" Type="String" />

<asp:parameter Name="manufacturer" Type="String" />

<asp:parameter Name="media_type_id" Type="Int32" />

<asp:parameter Name="license_info" Type="String" />

<asp:parameter Name="date_purchased" Type="DateTime" />

<asp:parameter Name="ci_id" />

</UpdateParameters>

<InsertParameters>

<asp:parameter Name="active" Type="Boolean" />

<asp:parameter Name="title" Type="String" />

<asp:parameter Name="version" Type="String" />

<asp:parameter Name="other_version_info" Type="String" />

<asp:parameter Name="manufacturer" Type="String" />

<asp:parameter Name="media_type_id" Type="Int32" />

<asp:parameter Name="license_info" Type="String" />

<asp:parameter Name="date_purchased" Type="DateTime" />

</InsertParameters>

</asp:SqlDataSource> &nbsp;

<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
DataKeyNames="ci_id"

DataSourceID="SqlDataSource1" Height="50px" Style="position: relative"
Width="143px">

<Fields>

<asp:BoundField DataField="ci_id" HeaderText="ci_id" InsertVisible="False"
ReadOnly="True"

SortExpression="ci_id" />

<asp:CheckBoxField DataField="active" HeaderText="active"
SortExpression="active" />

<asp:BoundField DataField="title" HeaderText="title" SortExpression="title"
/>

<asp:BoundField DataField="version" HeaderText="version"
SortExpression="version" />

<asp:BoundField DataField="other_version_info"
HeaderText="other_version_info" SortExpression="other_version_info" />

<asp:BoundField DataField="manufacturer" HeaderText="manufacturer"
SortExpression="manufacturer" />

<asp:BoundField DataField="media_type_id" HeaderText="media_type_id"
SortExpression="media_type_id" />

<asp:TemplateField HeaderText="Media">

<EditItemTemplate>

&nbsp;

<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource2"

DataTextField="media_type" DataValueField="media_type_id" Style="left: -6px;

position: relative; top: 0px" Width="161px" SelectedValue='<%#
Bind("media_type_id") %>'>

</asp:DropDownList>

</EditItemTemplate>

</asp:TemplateField>

<asp:BoundField DataField="license_info" HeaderText="license_info"
SortExpression="license_info" />

<asp:BoundField DataField="date_purchased" HeaderText="date_purchased"
SortExpression="date_purchased" />

<asp:CommandField ShowDeleteButton="True" ShowEditButton="True"
ShowInsertButton="True" />

</Fields>

</asp:DetailsView>

<br />



</div>

<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$
ConnectionStrings:AppsDBConnectionString %>"

SelectCommand="SELECT [media_type_id], [media_type] FROM
[media_type]"></asp:SqlDataSource>

</form>

</body>

</html>



Steven Cheng said:
Thanks for your followup.

Seems strange. Would you try making a simplified page with the controls
that can reproduce the problem so that I can test it on my side? Also, you
can post the test database's table structure to me...

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "Trevor Bezotte" <[email protected]>
| References: <#[email protected]>
<[email protected]>
<#[email protected]>
<vscaaXZ#[email protected]>
| Subject: Re: DetailsView EditItemTemplate DropdownList Update Problem
| Date: Mon, 5 Dec 2005 08:56:22 -0600
| Lines: 498
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| X-RFC2646: Format=Flowed; Original
| Message-ID: <#Rh6Pwa#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| NNTP-Posting-Host: global.erdman.com 12.20.65.30
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP15.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet.datagridcontrol:14858
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
|
| The database gets updated no problem when I use default controls
(textboxes)
| on the EditItemTemplate, its just when I switch to a dropdownlist for
one
of
| the fields.
|
| The dropdownlist uses values from a related table.
|
|
| | > Thanks for your response Trevor,
| >
| > So the problems seems occured between the DataBound control and the
| > backend
| > database....., Just during the DataSource control's processing.
Would
| > you
| > try creating a complete new page and readd such databound, datasource
| > controls to see whether the behavior always remains? I think this is
| > likely a page specific issue....
| >
| > Regards,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| > --------------------
| > | From: "Trevor Bezotte" <[email protected]>
| > | References: <#[email protected]>
| > <[email protected]>
| > | Subject: Re: DetailsView EditItemTemplate DropdownList Update
Problem
| > | Date: Fri, 2 Dec 2005 08:36:00 -0600
| > | Lines: 407
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| > | X-RFC2646: Format=Flowed; Original
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| > | Message-ID: <#[email protected]>
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > | NNTP-Posting-Host: global.erdman.com 12.20.65.30
| > | Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| > | Xref: TK2MSFTNGXA02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet.datagridcontrol:14843
| > | X-Tomcat-NG:
microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > |
| > | I checked the profiler and it shows correct parameter, but it does
not
| > show
| > | the correct parameter value.
| > |
| > | I tried your ItemUpdating code but it does not get fired.
| > |
| > |
| > |
| > |
| > | | > | > Hi Trevor,
| > | >
| > | > Welcome to ASPNET newsgroup.
| > | > Regarding on the DetailsView TemplateField updating problem, based
on
| > my
| > | > experience, for template fields, we can just enable two -way
| > databinding
| > | > as long as we use the <%# bind(....) %> expression in databinding
| > | > expression. Also, I've checked the code snippet you provide and
| > compare
| > to
| > | > my local test page, seem haven't found any particular
difference...
| > | > Have you tried create a new page and regenerate such steps(maybe
you
| > can
| > | > just use a detailsView without GridView to make the things
| > | > simplified....)...
| > | >
| > | > Also, one way for testing is register the DetailsView's
ItemUpdating
| > event
| > | > and printout all the new paramters' value there , e.g:
| > | >
| > | > =============
| > | > protected void DetailsView1_ItemUpdating(object sender,
| > | > DetailsViewUpdateEventArgs e)
| > | > {
| > | > foreach(string key in e.NewValues.Keys)
| > | > {
| > | > Response.Write("<br>" + key + " " + e.NewValues[key]);
| > | > }
| > | >
| > | > e.Cancel = true;
| > | > }
| > | > ============
| > | >
| > | > we can have a look whether all the parameters are provided
| > correclty....
| > | > Also, on sqlserver side, we can using sqlprofiler to monitor
whether
| > the
| > | > final sqlstatement has contained the correctly paratmeters....
| > | >
| > | > BTW, I've also pasted my test page's aspx template below for your
| > | > reference:
| > | >
| > | > Hope helps. Thanks,
| > | >
| > | > Steven Cheng
| > | > Microsoft Online Support
| > | >
| > | > Get Secure! www.microsoft.com/security
| > | > (This posting is provided "AS IS", with no warranties, and confers
no
| > | > rights.)
| > | >
| > | > ==================================
| > | > <div>
| > | > <asp:SqlDataSource ID="SqlDataSource1" runat="server"
| > | > ConnectionString="<%$ ConnectionStrings:databaseConnectionString
%>"
| > | > DeleteCommand="DELETE FROM [items] WHERE [id] = @id"
| > | > InsertCommand="INSERT INTO [items] ([name], [priority]) VALUES
(@name,
| > | > @priority)"
| > | > SelectCommand="SELECT [id], [name], [priority] FROM
| > [items]"
| > | > UpdateCommand="UPDATE [items] SET [name] = @name, [priority] =
| > @priority
| > | > WHERE [id] = @id">
| > | > <DeleteParameters>
| > | > <asp:parameter Name="id" Type="Int64" />
| > | > </DeleteParameters>
| > | > <UpdateParameters>
| > | > <asp:parameter Name="name" Type="String" />
| > | > <asp:parameter Name="priority" Type="Int32" />
| > | > <asp:parameter Name="id" Type="Int64" />
| > | > </UpdateParameters>
| > | > <InsertParameters>
| > | > <asp:parameter Name="name" Type="String" />
| > | > <asp:parameter Name="priority" Type="Int32" />
| > | > </InsertParameters>
| > | > </asp:SqlDataSource>
| > | > <asp:DetailsView ID="DetailsView1" runat="server"
| > | > AllowPaging="True" AutoGenerateRows="False"
| > | > DataKeyNames="id" DataSourceID="SqlDataSource1"
| > Height="50px"
| > | > Width="125px" OnItemUpdating="DetailsView1_ItemUpdating">
| > | > <Fields>
| > | > <asp:BoundField DataField="id" HeaderText="id"
| > | > InsertVisible="False" ReadOnly="True"
| > | > SortExpression="id" />
| > | > <asp:BoundField DataField="name" HeaderText="name"
| > | > SortExpression="name" />
| > | > <asp:TemplateField HeaderText="priority"
| > | > SortExpression="priority">
| > | > <EditItemTemplate>
| > | > <asp:DropDownList ID="lstPriority"
| > runat="server"
| > | > SelectedValue='<%# Bind("priority") %>'
DataSourceID="SqlDataSource3"
| > | > DataTextField="pname" DataValueField="pid">
| > | > <asp:ListItem
Value="0">low</asp:ListItem>
| > | > <asp:ListItem
| > Value="1">middle</asp:ListItem>
| > | > <asp:ListItem
Value="2">high</asp:ListItem>
| > | > </asp:DropDownList>
| > | > <asp:SqlDataSource ID="SqlDataSource3"
| > | > runat="server" CacheDuration="300" ConnectionString="<%$
| > | > ConnectionStrings:databaseConnectionString %>"
| > | > EnableCaching="True"
SelectCommand="SELECT
| > | > DISTINCT [pid], [pname] FROM [priorities]">
| > | > </asp:SqlDataSource>
| > | > </EditItemTemplate>
| > | > <InsertItemTemplate>
| > | > <asp:TextBox ID="TextBox1" runat="server"
| > Text='<%#
| > | > Bind("priority") %>'></asp:TextBox>
| > | > </InsertItemTemplate>
| > | > <ItemTemplate>
| > | > <asp:DropDownList ID="lstPriority"
| > runat="server"
| > | > Enabled="False" SelectedValue='<%# Bind("priority") %>'
| > | > DataSourceID="SqlDataSource2" DataTextField="pname"
| > DataValueField="pid">
| > | > <asp:ListItem
Value="0">low</asp:ListItem>
| > | > <asp:ListItem
| > Value="1">middle</asp:ListItem>
| > | > <asp:ListItem
Value="2">high</asp:ListItem>
| > | > </asp:DropDownList>
| > | > <asp:SqlDataSource ID="SqlDataSource2"
| > | > runat="server" CacheDuration="600" ConnectionString="<%$
| > | > ConnectionStrings:databaseConnectionString %>"
| > | > EnableCaching="True"
SelectCommand="SELECT
| > | > DISTINCT [pid], [pname] FROM [priorities]">
| > | > </asp:SqlDataSource>
| > | > </ItemTemplate>
| > | > </asp:TemplateField>
| > | > <asp:CommandField ShowDeleteButton="True"
| > | > ShowEditButton="True" ShowInsertButton="True" />
| > | > </Fields>
| > | > </asp:DetailsView>
| > | >
| > | > </div>
| > | > =======================
| > | >
| > | >
| > | >
| > | >
| > | > --------------------
| > | > | From: "Trevor Bezotte" <[email protected]>
| > | > | Subject: DetailsView EditItemTemplate DropdownList Update
Problem
| > | > | Date: Thu, 1 Dec 2005 14:53:40 -0600
| > | > | Lines: 234
| > | > | X-Priority: 3
| > | > | X-MSMail-Priority: Normal
| > | > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| > | > | X-RFC2646: Format=Flowed; Original
| > | > | Message-ID: <#[email protected]>
| > | > | Newsgroups:
microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > | > | NNTP-Posting-Host: global.erdman.com 12.20.65.30
| > | > | Path:
| > TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| > | > | Xref: TK2MSFTNGXA02.phx.gbl
| > | > microsoft.public.dotnet.framework.aspnet.datagridcontrol:14838
| > | > | X-Tomcat-NG:
| > microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > | > |
| > | > | Hi!
| > | > |
| > | > | I have a DetailsView with a DropDownList in an EditItemTemplate,
I
| > know,
| > | > | pretty cool right? But when I try to Update the table with a new
| > value
| > | > from
| > | > | the DropDownList the table does not get updated with the new
value.
| > I'm
| > | > new
| > | > | at this and I'm sure I'm overlooking something simple here. I'll
| > post
| > | > the
| > | > | ASP code, hopefully someone can help me with this one.
| > | > |
| > | > | Thank you!
| > | > |
| > | > |
| > | > | <%@ Page Language="C#" masterpagefile="~/software.master"
| > | > | AutoEventWireup="true" CodeFile="MasterDetail.aspx.cs"
Debug="true"
| > | > | Inherits="MasterDetail" %>
| > | > |
| > | > | <asp:Content ID="SoftwareData" runat="server"
| > | > | ContentPlaceHolderID="PageBody">
| > | > |
| > | > |
| > | > |
| > | > | <table><tr>
| > | > |
| > | > | <td valign="top" style="width: 280px">
| > | > |
| > | > | <asp:GridView ID="SummaryGrid" runat="server"
| > | > | DataSourceID="AppsDBDataSource"
| > | > |
| > | > | EnableViewState="False"
| > | > |
| > | > | DataKeyNames="ci_id" AllowPaging="True"
| > | > |
| > | > | AutoGenerateSelectButton="True"
| > | > |
| > | > | AutoGenerateColumns="False" style="left: 73px; position:
relative;
| > top:
| > | > 9px"
| > | > | BackColor="White" BorderColor="#999999" BorderStyle="None"
| > | > BorderWidth="1px"
| > | > | CellPadding="3" Font-Names="Arial" Font-Size="X-Small"
| > | > GridLines="Vertical"
| > | > | Width="492px" PageSize="5">
| > | > |
| > | > | <Columns>
| > | > |
| > | > | <asp:BoundField DataField="manufacturer"
HeaderText="Manufacturer"
| > />
| > | > |
| > | > | <asp:BoundField DataField="title" HeaderText="Title" />
| > | > |
| > | > | <asp:BoundField DataField="version" HeaderText="Version" />
| > | > |
| > | > | </Columns>
| > | > |
| > | > | <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
| > | > |
| > | > | <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
| > | > |
| > | > | <SelectedRowStyle BackColor="#008A8C" Font-Bold="True"
| > ForeColor="White"
| > | > />
| > | > |
| > | > | <PagerStyle BackColor="#999999" ForeColor="Black"
| > | > HorizontalAlign="Center"
| > | > | />
| > | > |
| > | > | <HeaderStyle BackColor="#000084" Font-Bold="True"
ForeColor="White"
| > />
| > | > |
| > | > | <AlternatingRowStyle BackColor="Gainsboro" />
| > | > |
| > | > | </asp:GridView>
| > | > |
| > | > | </td>
| > | > |
| > | > | <td valign="top">
| > | > |
| > | > | <asp:DetailsView ID="DetailsView1" runat="server"
| > | > |
| > | > | DataKeyNames="ci_id, media_type_id"
| > | > |
| > | > | HeaderText="Software Package Details"
| > | > |
| > | > | EmptyDataText="No package currently selected"
| > | > |
| > | > | DataSourceID="RowDataSource"
| > | > |
| > | > | AutoGenerateInsertButton="True"
| > | > |
| > | > | AutoGenerateDeleteButton="True"
| > | > |
| > | > | AutoGenerateEditButton="True"
| > OnItemUpdated="DetailsView1_ItemUpdated"
| > | > | style="left: 73px; position: relative; top: 9px"
BackColor="White"
| > | > | BorderColor="#999999" BorderStyle="None" BorderWidth="1px"
| > | > CellPadding="3"
| > | > | Font-Names="Arial" Font-Size="X-Small" GridLines="Vertical"
| > | > Width="320px"
| > | > | AutoGenerateRows="False">
| > | > |
| > | > | <Fields>
| > | > |
| > | > | <asp:BoundField DataField="ci_id" HeaderText="ID"
ReadOnly="True"
/>
| > | > |
| > | > | <asp:CheckBoxField DataField="active" HeaderText="Active"
| > | > | SortExpression="active" />
| > | > |
| > | > | <asp:BoundField DataField="title" HeaderText="Title" >
| > | > |
| > | > | <ControlStyle Width="225px" />
| > | > |
| > | > | </asp:BoundField>
| > | > |
| > | > | <asp:BoundField DataField="version" HeaderText="Version" />
| > | > |
| > | > | <asp:BoundField DataField="other_version_info"
HeaderText="Version
| > Info"
| > | > />
| > | > |
| > | > | <asp:BoundField DataField="manufacturer"
HeaderText="Manufacturer"
| > />
| > | > |
| > | > | <asp:TemplateField HeaderText="Media">
| > | > |
| > | > | <EditItemTemplate>
| > | > |
| > | > | &nbsp;
| > | > |
| > | > | <asp:DropDownList ID="DropDownList1" runat="server"
| > | > | DataSourceID="SQLMediaTypes"
| > | > |
| > | > | DataTextField="media_type" DataValueField="media_type_id"
| > Style="left:
| > | > -6px;
| > | > |
| > | > | position: relative; top: 0px" Width="161px" SelectedValue='<%#
| > | > | Bind("media_type_id") %>'>
| > | > |
| > | > | </asp:DropDownList>
| > | > |
| > | > | </EditItemTemplate>
| > | > |
| > | > | <InsertItemTemplate>
| > | > |
| > | > | <asp:DropDownList ID="DropDownList2" runat="server"
| > | > | DataSourceID="SQLMediaTypes"
| > | > |
| > | > | DataTextField="media_type" DataValueField="media_type_id"
| > Style="left:
| > | > 0px;
| > | > |
| > | > | position: relative; top: 0px" Width="161px" SelectedValue='<%#
| > | > | Bind("media_type_id") %>'>
| > | > |
| > | > | </asp:DropDownList>
| > | > |
| > | > | </InsertItemTemplate>
| > | > |
| > | > | <ItemTemplate>
| > | > |
| > | > | <asp:Label ID="Label1" runat="server" Text='<%#
Bind("media_type")
| > | > | %>'></asp:Label>
| > | > |
| > | > | </ItemTemplate>
| > | > |
| > | > | </asp:TemplateField>
| > | > |
| > | > | <asp:BoundField DataField="license_info" HeaderText="License
Info"
| > />
| > | > |
| > | > | <asp:BoundField DataField="date_purchased" HeaderText="Purchase
| > Date"
| > | > | SortExpression="date_purchased" />
| > | > |
| > | > |
| > | > | </Fields>
| > | > |
| > | > | <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
| > | > |
| > | > | <EditRowStyle BackColor="#008A8C" Font-Bold="True"
ForeColor="White"
| > | > | Font-Names="Arial" Font-Size="X-Small" />
| > | > |
| > | > | <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
| > | > |
| > | > | <PagerStyle BackColor="#999999" ForeColor="Black"
| > | > HorizontalAlign="Center"
| > | > | />
| > | > |
| > | > | <HeaderStyle BackColor="#000084" Font-Bold="True"
ForeColor="White"
| > />
| > | > |
| > | > | <AlternatingRowStyle BackColor="Gainsboro" />
| > | > |
| > | > | </asp:DetailsView>
| > | > |
| > | > | </td>
| > | > |
| > | > | </tr></table>
| > | > |
| > | > | <asp:Label ID="Label2" runat="server" Font-Names="Courier New"
| > | > Height="28px"
| > | > | Style="z-index: 103;
| > | > |
| > | > | left: 28px; position: absolute; top: -298px"
| > Width="379px">Application
| > | > | Management Database</asp:Label>
| > | > |
| > | > | <asp:SqlDataSource ID="AppsDBDataSource" runat="server"
| > | > |
| > | > | EnableCaching="false"
| > CacheKeyDependency="AppsDBDataSource_Controller"
| > | > |
| > | > | ConnectionString='<%$ ConnectionStrings:LocalAppsDB %>'
| > | > |
| > | > | SelectCommand="SELECT * FROM vwSoftware">
| > | > |
| > | > | </asp:SqlDataSource>
| > | > |
| > | > | <asp:SqlDataSource ID="RowDataSource" runat="server"
| > | > |
| > | > | EnableCaching="false"
| > | > |
| > | > | ConnectionString='<%$ ConnectionStrings:LocalAppsDB %>'
| > | > |
| > | > | SelectCommand="SELECT * FROM vwSoftware WHERE ci_id=@ci_id"
| > | > |
| > | > | UpdateCommand="UPDATE software SET active=@active, title=@title,
| > | > | version=@version, other_version_info=@other_version_info,
| > | > | manufacturer=@manufacturer, media_type_id=@media_type_id,
| > | > | license_info=@license_info, date_purchased=@date_purchased WHERE
| > | > | ci_id=@ci_id"
| > | > |
| > | > | InsertCommand="INSERT INTO software(active, title, version,
| > | > | other_version_info, manufacturer, media_type_id, license_info,
| > | > | date_purchased) VALUES(@active, @title, @version,
| > @other_version_info,
| > | > | @manufacturer, @media_type_id, @license_info, @date_purchased)"
| > | > |
| > | > | DeleteCommand="DELETE FROM software WHERE ci_id=@ci_id">
| > | > |
| > | > | <SelectParameters>
| > | > |
| > | > | <asp:ControlParameter Name="ci_id" ControlID="SummaryGrid"
| > | > | PropertyName="SelectedValue" />
| > | > |
| > | > | </SelectParameters>
| > | > |
| > | > | </asp:SqlDataSource>
| > | > |
| > | > | <asp:SqlDataSource ID="SQLMediaTypes" runat="server"
| > | > ConnectionString="<%$
| > | > | ConnectionStrings:LocalAppsDB %>"
| > | > |
| > | > | OnSelecting="SQLMediaTypes_Selecting" ProviderName="<%$
| > | > | ConnectionStrings:LocalAppsDB.ProviderName %>"
| > | > |
| > | > | SelectCommand="SELECT [media_type_id], [media_type] FROM
| > | > | [media_type]"></asp:SqlDataSource>
| > | > |
| > | > |
| > | > | </asp:Content>
| > | > |
| > | > |
| > | > |
| > | >
| > |
| > |
| > |
| >
|
|
|
 
T

Trevor Bezotte

OK, I have my original code working, I just pasted the code from my test
form into my original and got it working that way.

Thank you very much for your help Steven.

Trevor



Trevor Bezotte said:
funny, it works fine when the page is simplified to just the detailsview,
here's the code...

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="testForm.aspx.vb"
Inherits="testForm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Test Page</title>

</head>

<body>

<form id="form1" runat="server">

<div>

<asp:SqlDataSource ID="SqlDataSource1" runat="server"

ConnectionString="<%$ ConnectionStrings:databaseConnectionString %>"

DeleteCommand="DELETE FROM [software] WHERE [ci_id] = @ci_id"

InsertCommand="INSERT INTO software(active, title, version,
other_version_info, manufacturer, media_type_id, license_info,
date_purchased) VALUES(@active, @title, @version, @other_version_info,
@manufacturer, @media_type_id, @license_info, @date_purchased)"

SelectCommand="SELECT ci_id, active, title, version, other_version_info,
manufacturer, media_type_id, license_info, date_purchased FROM software"

UpdateCommand="UPDATE software SET active=@active, title=@title,
version=@version, other_version_info=@other_version_info,
manufacturer=@manufacturer, media_type_id=@media_type_id,
license_info=@license_info, date_purchased=@date_purchased WHERE
ci_id=@ci_id">

<DeleteParameters>

<asp:parameter Name="ci_id" Type="Int64" />

</DeleteParameters>

<UpdateParameters>

<asp:parameter Name="active" Type="Boolean" />

<asp:parameter Name="title" Type="String" />

<asp:parameter Name="version" Type="String" />

<asp:parameter Name="other_version_info" Type="String" />

<asp:parameter Name="manufacturer" Type="String" />

<asp:parameter Name="media_type_id" Type="Int32" />

<asp:parameter Name="license_info" Type="String" />

<asp:parameter Name="date_purchased" Type="DateTime" />

<asp:parameter Name="ci_id" />

</UpdateParameters>

<InsertParameters>

<asp:parameter Name="active" Type="Boolean" />

<asp:parameter Name="title" Type="String" />

<asp:parameter Name="version" Type="String" />

<asp:parameter Name="other_version_info" Type="String" />

<asp:parameter Name="manufacturer" Type="String" />

<asp:parameter Name="media_type_id" Type="Int32" />

<asp:parameter Name="license_info" Type="String" />

<asp:parameter Name="date_purchased" Type="DateTime" />

</InsertParameters>

</asp:SqlDataSource> &nbsp;

<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
DataKeyNames="ci_id"

DataSourceID="SqlDataSource1" Height="50px" Style="position: relative"
Width="143px">

<Fields>

<asp:BoundField DataField="ci_id" HeaderText="ci_id" InsertVisible="False"
ReadOnly="True"

SortExpression="ci_id" />

<asp:CheckBoxField DataField="active" HeaderText="active"
SortExpression="active" />

<asp:BoundField DataField="title" HeaderText="title"
SortExpression="title" />

<asp:BoundField DataField="version" HeaderText="version"
SortExpression="version" />

<asp:BoundField DataField="other_version_info"
HeaderText="other_version_info" SortExpression="other_version_info" />

<asp:BoundField DataField="manufacturer" HeaderText="manufacturer"
SortExpression="manufacturer" />

<asp:BoundField DataField="media_type_id" HeaderText="media_type_id"
SortExpression="media_type_id" />

<asp:TemplateField HeaderText="Media">

<EditItemTemplate>

&nbsp;

<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource2"

DataTextField="media_type" DataValueField="media_type_id"
Style="left: -6px;

position: relative; top: 0px" Width="161px" SelectedValue='<%#
Bind("media_type_id") %>'>

</asp:DropDownList>

</EditItemTemplate>

</asp:TemplateField>

<asp:BoundField DataField="license_info" HeaderText="license_info"
SortExpression="license_info" />

<asp:BoundField DataField="date_purchased" HeaderText="date_purchased"
SortExpression="date_purchased" />

<asp:CommandField ShowDeleteButton="True" ShowEditButton="True"
ShowInsertButton="True" />

</Fields>

</asp:DetailsView>

<br />



</div>

<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:AppsDBConnectionString %>"

SelectCommand="SELECT [media_type_id], [media_type] FROM
[media_type]"></asp:SqlDataSource>

</form>

</body>

</html>



Steven Cheng said:
Thanks for your followup.

Seems strange. Would you try making a simplified page with the controls
that can reproduce the problem so that I can test it on my side? Also,
you
can post the test database's table structure to me...

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "Trevor Bezotte" <[email protected]>
| References: <#[email protected]>
<[email protected]>
<#[email protected]>
<vscaaXZ#[email protected]>
| Subject: Re: DetailsView EditItemTemplate DropdownList Update Problem
| Date: Mon, 5 Dec 2005 08:56:22 -0600
| Lines: 498
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| X-RFC2646: Format=Flowed; Original
| Message-ID: <#Rh6Pwa#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| NNTP-Posting-Host: global.erdman.com 12.20.65.30
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP15.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet.datagridcontrol:14858
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
|
| The database gets updated no problem when I use default controls
(textboxes)
| on the EditItemTemplate, its just when I switch to a dropdownlist for
one
of
| the fields.
|
| The dropdownlist uses values from a related table.
|
|
| | > Thanks for your response Trevor,
| >
| > So the problems seems occured between the DataBound control and the
| > backend
| > database....., Just during the DataSource control's processing.
Would
| > you
| > try creating a complete new page and readd such databound, datasource
| > controls to see whether the behavior always remains? I think this is
| > likely a page specific issue....
| >
| > Regards,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| > --------------------
| > | From: "Trevor Bezotte" <[email protected]>
| > | References: <#[email protected]>
| > <[email protected]>
| > | Subject: Re: DetailsView EditItemTemplate DropdownList Update
Problem
| > | Date: Fri, 2 Dec 2005 08:36:00 -0600
| > | Lines: 407
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| > | X-RFC2646: Format=Flowed; Original
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| > | Message-ID: <#[email protected]>
| > | Newsgroups:
microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > | NNTP-Posting-Host: global.erdman.com 12.20.65.30
| > | Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| > | Xref: TK2MSFTNGXA02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet.datagridcontrol:14843
| > | X-Tomcat-NG:
microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > |
| > | I checked the profiler and it shows correct parameter, but it does
not
| > show
| > | the correct parameter value.
| > |
| > | I tried your ItemUpdating code but it does not get fired.
| > |
| > |
| > |
| > |
message
| > | | > | > Hi Trevor,
| > | >
| > | > Welcome to ASPNET newsgroup.
| > | > Regarding on the DetailsView TemplateField updating problem,
based
on
| > my
| > | > experience, for template fields, we can just enable two -way
| > databinding
| > | > as long as we use the <%# bind(....) %> expression in databinding
| > | > expression. Also, I've checked the code snippet you provide and
| > compare
| > to
| > | > my local test page, seem haven't found any particular
difference...
| > | > Have you tried create a new page and regenerate such steps(maybe
you
| > can
| > | > just use a detailsView without GridView to make the things
| > | > simplified....)...
| > | >
| > | > Also, one way for testing is register the DetailsView's
ItemUpdating
| > event
| > | > and printout all the new paramters' value there , e.g:
| > | >
| > | > =============
| > | > protected void DetailsView1_ItemUpdating(object sender,
| > | > DetailsViewUpdateEventArgs e)
| > | > {
| > | > foreach(string key in e.NewValues.Keys)
| > | > {
| > | > Response.Write("<br>" + key + " " + e.NewValues[key]);
| > | > }
| > | >
| > | > e.Cancel = true;
| > | > }
| > | > ============
| > | >
| > | > we can have a look whether all the parameters are provided
| > correclty....
| > | > Also, on sqlserver side, we can using sqlprofiler to monitor
whether
| > the
| > | > final sqlstatement has contained the correctly paratmeters....
| > | >
| > | > BTW, I've also pasted my test page's aspx template below for your
| > | > reference:
| > | >
| > | > Hope helps. Thanks,
| > | >
| > | > Steven Cheng
| > | > Microsoft Online Support
| > | >
| > | > Get Secure! www.microsoft.com/security
| > | > (This posting is provided "AS IS", with no warranties, and
confers
no
| > | > rights.)
| > | >
| > | > ==================================
| > | > <div>
| > | > <asp:SqlDataSource ID="SqlDataSource1" runat="server"
| > | > ConnectionString="<%$ ConnectionStrings:databaseConnectionString
%>"
| > | > DeleteCommand="DELETE FROM [items] WHERE [id] = @id"
| > | > InsertCommand="INSERT INTO [items] ([name], [priority]) VALUES
(@name,
| > | > @priority)"
| > | > SelectCommand="SELECT [id], [name], [priority] FROM
| > [items]"
| > | > UpdateCommand="UPDATE [items] SET [name] = @name, [priority] =
| > @priority
| > | > WHERE [id] = @id">
| > | > <DeleteParameters>
| > | > <asp:parameter Name="id" Type="Int64" />
| > | > </DeleteParameters>
| > | > <UpdateParameters>
| > | > <asp:parameter Name="name" Type="String" />
| > | > <asp:parameter Name="priority" Type="Int32" />
| > | > <asp:parameter Name="id" Type="Int64" />
| > | > </UpdateParameters>
| > | > <InsertParameters>
| > | > <asp:parameter Name="name" Type="String" />
| > | > <asp:parameter Name="priority" Type="Int32" />
| > | > </InsertParameters>
| > | > </asp:SqlDataSource>
| > | > <asp:DetailsView ID="DetailsView1" runat="server"
| > | > AllowPaging="True" AutoGenerateRows="False"
| > | > DataKeyNames="id" DataSourceID="SqlDataSource1"
| > Height="50px"
| > | > Width="125px" OnItemUpdating="DetailsView1_ItemUpdating">
| > | > <Fields>
| > | > <asp:BoundField DataField="id" HeaderText="id"
| > | > InsertVisible="False" ReadOnly="True"
| > | > SortExpression="id" />
| > | > <asp:BoundField DataField="name" HeaderText="name"
| > | > SortExpression="name" />
| > | > <asp:TemplateField HeaderText="priority"
| > | > SortExpression="priority">
| > | > <EditItemTemplate>
| > | > <asp:DropDownList ID="lstPriority"
| > runat="server"
| > | > SelectedValue='<%# Bind("priority") %>'
DataSourceID="SqlDataSource3"
| > | > DataTextField="pname" DataValueField="pid">
| > | > <asp:ListItem
Value="0">low</asp:ListItem>
| > | > <asp:ListItem
| > Value="1">middle</asp:ListItem>
| > | > <asp:ListItem
Value="2">high</asp:ListItem>
| > | > </asp:DropDownList>
| > | > <asp:SqlDataSource ID="SqlDataSource3"
| > | > runat="server" CacheDuration="300" ConnectionString="<%$
| > | > ConnectionStrings:databaseConnectionString %>"
| > | > EnableCaching="True"
SelectCommand="SELECT
| > | > DISTINCT [pid], [pname] FROM [priorities]">
| > | > </asp:SqlDataSource>
| > | > </EditItemTemplate>
| > | > <InsertItemTemplate>
| > | > <asp:TextBox ID="TextBox1" runat="server"
| > Text='<%#
| > | > Bind("priority") %>'></asp:TextBox>
| > | > </InsertItemTemplate>
| > | > <ItemTemplate>
| > | > <asp:DropDownList ID="lstPriority"
| > runat="server"
| > | > Enabled="False" SelectedValue='<%# Bind("priority") %>'
| > | > DataSourceID="SqlDataSource2" DataTextField="pname"
| > DataValueField="pid">
| > | > <asp:ListItem
Value="0">low</asp:ListItem>
| > | > <asp:ListItem
| > Value="1">middle</asp:ListItem>
| > | > <asp:ListItem
Value="2">high</asp:ListItem>
| > | > </asp:DropDownList>
| > | > <asp:SqlDataSource ID="SqlDataSource2"
| > | > runat="server" CacheDuration="600" ConnectionString="<%$
| > | > ConnectionStrings:databaseConnectionString %>"
| > | > EnableCaching="True"
SelectCommand="SELECT
| > | > DISTINCT [pid], [pname] FROM [priorities]">
| > | > </asp:SqlDataSource>
| > | > </ItemTemplate>
| > | > </asp:TemplateField>
| > | > <asp:CommandField ShowDeleteButton="True"
| > | > ShowEditButton="True" ShowInsertButton="True" />
| > | > </Fields>
| > | > </asp:DetailsView>
| > | >
| > | > </div>
| > | > =======================
| > | >
| > | >
| > | >
| > | >
| > | > --------------------
| > | > | From: "Trevor Bezotte" <[email protected]>
| > | > | Subject: DetailsView EditItemTemplate DropdownList Update
Problem
| > | > | Date: Thu, 1 Dec 2005 14:53:40 -0600
| > | > | Lines: 234
| > | > | X-Priority: 3
| > | > | X-MSMail-Priority: Normal
| > | > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| > | > | X-RFC2646: Format=Flowed; Original
| > | > | Message-ID: <#[email protected]>
| > | > | Newsgroups:
microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > | > | NNTP-Posting-Host: global.erdman.com 12.20.65.30
| > | > | Path:
| > TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| > | > | Xref: TK2MSFTNGXA02.phx.gbl
| > | > microsoft.public.dotnet.framework.aspnet.datagridcontrol:14838
| > | > | X-Tomcat-NG:
| > microsoft.public.dotnet.framework.aspnet.datagridcontrol
| > | > |
| > | > | Hi!
| > | > |
| > | > | I have a DetailsView with a DropDownList in an
EditItemTemplate, I
| > know,
| > | > | pretty cool right? But when I try to Update the table with a
new
| > value
| > | > from
| > | > | the DropDownList the table does not get updated with the new
value.
| > I'm
| > | > new
| > | > | at this and I'm sure I'm overlooking something simple here.
I'll
| > post
| > | > the
| > | > | ASP code, hopefully someone can help me with this one.
| > | > |
| > | > | Thank you!
| > | > |
| > | > |
| > | > | <%@ Page Language="C#" masterpagefile="~/software.master"
| > | > | AutoEventWireup="true" CodeFile="MasterDetail.aspx.cs"
Debug="true"
| > | > | Inherits="MasterDetail" %>
| > | > |
| > | > | <asp:Content ID="SoftwareData" runat="server"
| > | > | ContentPlaceHolderID="PageBody">
| > | > |
| > | > |
| > | > |
| > | > | <table><tr>
| > | > |
| > | > | <td valign="top" style="width: 280px">
| > | > |
| > | > | <asp:GridView ID="SummaryGrid" runat="server"
| > | > | DataSourceID="AppsDBDataSource"
| > | > |
| > | > | EnableViewState="False"
| > | > |
| > | > | DataKeyNames="ci_id" AllowPaging="True"
| > | > |
| > | > | AutoGenerateSelectButton="True"
| > | > |
| > | > | AutoGenerateColumns="False" style="left: 73px; position:
relative;
| > top:
| > | > 9px"
| > | > | BackColor="White" BorderColor="#999999" BorderStyle="None"
| > | > BorderWidth="1px"
| > | > | CellPadding="3" Font-Names="Arial" Font-Size="X-Small"
| > | > GridLines="Vertical"
| > | > | Width="492px" PageSize="5">
| > | > |
| > | > | <Columns>
| > | > |
| > | > | <asp:BoundField DataField="manufacturer"
HeaderText="Manufacturer"
| > />
| > | > |
| > | > | <asp:BoundField DataField="title" HeaderText="Title" />
| > | > |
| > | > | <asp:BoundField DataField="version" HeaderText="Version" />
| > | > |
| > | > | </Columns>
| > | > |
| > | > | <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
| > | > |
| > | > | <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
| > | > |
| > | > | <SelectedRowStyle BackColor="#008A8C" Font-Bold="True"
| > ForeColor="White"
| > | > />
| > | > |
| > | > | <PagerStyle BackColor="#999999" ForeColor="Black"
| > | > HorizontalAlign="Center"
| > | > | />
| > | > |
| > | > | <HeaderStyle BackColor="#000084" Font-Bold="True"
ForeColor="White"
| > />
| > | > |
| > | > | <AlternatingRowStyle BackColor="Gainsboro" />
| > | > |
| > | > | </asp:GridView>
| > | > |
| > | > | </td>
| > | > |
| > | > | <td valign="top">
| > | > |
| > | > | <asp:DetailsView ID="DetailsView1" runat="server"
| > | > |
| > | > | DataKeyNames="ci_id, media_type_id"
| > | > |
| > | > | HeaderText="Software Package Details"
| > | > |
| > | > | EmptyDataText="No package currently selected"
| > | > |
| > | > | DataSourceID="RowDataSource"
| > | > |
| > | > | AutoGenerateInsertButton="True"
| > | > |
| > | > | AutoGenerateDeleteButton="True"
| > | > |
| > | > | AutoGenerateEditButton="True"
| > OnItemUpdated="DetailsView1_ItemUpdated"
| > | > | style="left: 73px; position: relative; top: 9px"
BackColor="White"
| > | > | BorderColor="#999999" BorderStyle="None" BorderWidth="1px"
| > | > CellPadding="3"
| > | > | Font-Names="Arial" Font-Size="X-Small" GridLines="Vertical"
| > | > Width="320px"
| > | > | AutoGenerateRows="False">
| > | > |
| > | > | <Fields>
| > | > |
| > | > | <asp:BoundField DataField="ci_id" HeaderText="ID"
ReadOnly="True"
/>
| > | > |
| > | > | <asp:CheckBoxField DataField="active" HeaderText="Active"
| > | > | SortExpression="active" />
| > | > |
| > | > | <asp:BoundField DataField="title" HeaderText="Title" >
| > | > |
| > | > | <ControlStyle Width="225px" />
| > | > |
| > | > | </asp:BoundField>
| > | > |
| > | > | <asp:BoundField DataField="version" HeaderText="Version" />
| > | > |
| > | > | <asp:BoundField DataField="other_version_info"
HeaderText="Version
| > Info"
| > | > />
| > | > |
| > | > | <asp:BoundField DataField="manufacturer"
HeaderText="Manufacturer"
| > />
| > | > |
| > | > | <asp:TemplateField HeaderText="Media">
| > | > |
| > | > | <EditItemTemplate>
| > | > |
| > | > | &nbsp;
| > | > |
| > | > | <asp:DropDownList ID="DropDownList1" runat="server"
| > | > | DataSourceID="SQLMediaTypes"
| > | > |
| > | > | DataTextField="media_type" DataValueField="media_type_id"
| > Style="left:
| > | > -6px;
| > | > |
| > | > | position: relative; top: 0px" Width="161px" SelectedValue='<%#
| > | > | Bind("media_type_id") %>'>
| > | > |
| > | > | </asp:DropDownList>
| > | > |
| > | > | </EditItemTemplate>
| > | > |
| > | > | <InsertItemTemplate>
| > | > |
| > | > | <asp:DropDownList ID="DropDownList2" runat="server"
| > | > | DataSourceID="SQLMediaTypes"
| > | > |
| > | > | DataTextField="media_type" DataValueField="media_type_id"
| > Style="left:
| > | > 0px;
| > | > |
| > | > | position: relative; top: 0px" Width="161px" SelectedValue='<%#
| > | > | Bind("media_type_id") %>'>
| > | > |
| > | > | </asp:DropDownList>
| > | > |
| > | > | </InsertItemTemplate>
| > | > |
| > | > | <ItemTemplate>
| > | > |
| > | > | <asp:Label ID="Label1" runat="server" Text='<%#
Bind("media_type")
| > | > | %>'></asp:Label>
| > | > |
| > | > | </ItemTemplate>
| > | > |
| > | > | </asp:TemplateField>
| > | > |
| > | > | <asp:BoundField DataField="license_info" HeaderText="License
Info"
| > />
| > | > |
| > | > | <asp:BoundField DataField="date_purchased" HeaderText="Purchase
| > Date"
| > | > | SortExpression="date_purchased" />
| > | > |
| > | > |
| > | > | </Fields>
| > | > |
| > | > | <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
| > | > |
| > | > | <EditRowStyle BackColor="#008A8C" Font-Bold="True"
ForeColor="White"
| > | > | Font-Names="Arial" Font-Size="X-Small" />
| > | > |
| > | > | <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
| > | > |
| > | > | <PagerStyle BackColor="#999999" ForeColor="Black"
| > | > HorizontalAlign="Center"
| > | > | />
| > | > |
| > | > | <HeaderStyle BackColor="#000084" Font-Bold="True"
ForeColor="White"
| > />
| > | > |
| > | > | <AlternatingRowStyle BackColor="Gainsboro" />
| > | > |
| > | > | </asp:DetailsView>
| > | > |
| > | > | </td>
| > | > |
| > | > | </tr></table>
| > | > |
| > | > | <asp:Label ID="Label2" runat="server" Font-Names="Courier New"
| > | > Height="28px"
| > | > | Style="z-index: 103;
| > | > |
| > | > | left: 28px; position: absolute; top: -298px"
| > Width="379px">Application
| > | > | Management Database</asp:Label>
| > | > |
| > | > | <asp:SqlDataSource ID="AppsDBDataSource" runat="server"
| > | > |
| > | > | EnableCaching="false"
| > CacheKeyDependency="AppsDBDataSource_Controller"
| > | > |
| > | > | ConnectionString='<%$ ConnectionStrings:LocalAppsDB %>'
| > | > |
| > | > | SelectCommand="SELECT * FROM vwSoftware">
| > | > |
| > | > | </asp:SqlDataSource>
| > | > |
| > | > | <asp:SqlDataSource ID="RowDataSource" runat="server"
| > | > |
| > | > | EnableCaching="false"
| > | > |
| > | > | ConnectionString='<%$ ConnectionStrings:LocalAppsDB %>'
| > | > |
| > | > | SelectCommand="SELECT * FROM vwSoftware WHERE ci_id=@ci_id"
| > | > |
| > | > | UpdateCommand="UPDATE software SET active=@active,
title=@title,
| > | > | version=@version, other_version_info=@other_version_info,
| > | > | manufacturer=@manufacturer, media_type_id=@media_type_id,
| > | > | license_info=@license_info, date_purchased=@date_purchased
WHERE
| > | > | ci_id=@ci_id"
| > | > |
| > | > | InsertCommand="INSERT INTO software(active, title, version,
| > | > | other_version_info, manufacturer, media_type_id, license_info,
| > | > | date_purchased) VALUES(@active, @title, @version,
| > @other_version_info,
| > | > | @manufacturer, @media_type_id, @license_info, @date_purchased)"
| > | > |
| > | > | DeleteCommand="DELETE FROM software WHERE ci_id=@ci_id">
| > | > |
| > | > | <SelectParameters>
| > | > |
| > | > | <asp:ControlParameter Name="ci_id" ControlID="SummaryGrid"
| > | > | PropertyName="SelectedValue" />
| > | > |
| > | > | </SelectParameters>
| > | > |
| > | > | </asp:SqlDataSource>
| > | > |
| > | > | <asp:SqlDataSource ID="SQLMediaTypes" runat="server"
| > | > ConnectionString="<%$
| > | > | ConnectionStrings:LocalAppsDB %>"
| > | > |
| > | > | OnSelecting="SQLMediaTypes_Selecting" ProviderName="<%$
| > | > | ConnectionStrings:LocalAppsDB.ProviderName %>"
| > | > |
| > | > | SelectCommand="SELECT [media_type_id], [media_type] FROM
| > | > | [media_type]"></asp:SqlDataSource>
| > | > |
| > | > |
| > | > | </asp:Content>
| > | > |
| > | > |
| > | > |
| > | >
| > |
| > |
| > |
| >
|
|
|
 
S

Steven Cheng[MSFT]

Thanks for your followup Trevor,

Sounds strange. Anyway, glad that everything get working now.
Have a good day!

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "Trevor Bezotte" <[email protected]>
| References: <#[email protected]>
<[email protected]>
<#[email protected]>
<vscaaXZ#[email protected]>
<#Rh6Pwa#[email protected]>
<HvrkTet#[email protected]>
<#qevAe3#[email protected]>
| Subject: Re: DetailsView EditItemTemplate DropdownList Update Problem
| Date: Wed, 7 Dec 2005 17:52:11 -0600
| Lines: 781
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| X-RFC2646: Format=Flowed; Response
| Message-ID: <OpwJ9k4#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| NNTP-Posting-Host: global.erdman.com 12.20.65.30
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet.datagridcontrol:14866
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
|
| OK, I have my original code working, I just pasted the code from my test
| form into my original and got it working that way.
|
| Thank you very much for your help Steven.
|
| Trevor
|
|
|
| | > funny, it works fine when the page is simplified to just the
detailsview,
| > here's the code...
| >
| > <%@ Page Language="VB" AutoEventWireup="false"
CodeFile="testForm.aspx.vb"
| > Inherits="testForm" %>
| >
| > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
| > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
| >
| > <html xmlns="http://www.w3.org/1999/xhtml" >
| >
| > <head runat="server">
| >
| > <title>Test Page</title>
| >
| > </head>
| >
| > <body>
| >
| > <form id="form1" runat="server">
| >
| > <div>
| >
| > <asp:SqlDataSource ID="SqlDataSource1" runat="server"
| >
| > ConnectionString="<%$ ConnectionStrings:databaseConnectionString %>"
| >
| > DeleteCommand="DELETE FROM [software] WHERE [ci_id] = @ci_id"
| >
| > InsertCommand="INSERT INTO software(active, title, version,
| > other_version_info, manufacturer, media_type_id, license_info,
| > date_purchased) VALUES(@active, @title, @version, @other_version_info,
| > @manufacturer, @media_type_id, @license_info, @date_purchased)"
| >
| > SelectCommand="SELECT ci_id, active, title, version,
other_version_info,
| > manufacturer, media_type_id, license_info, date_purchased FROM software"
| >
| > UpdateCommand="UPDATE software SET active=@active, title=@title,
| > version=@version, other_version_info=@other_version_info,
| > manufacturer=@manufacturer, media_type_id=@media_type_id,
| > license_info=@license_info, date_purchased=@date_purchased WHERE
| > ci_id=@ci_id">
| >
| > <DeleteParameters>
| >
| > <asp:parameter Name="ci_id" Type="Int64" />
| >
| > </DeleteParameters>
| >
| > <UpdateParameters>
| >
| > <asp:parameter Name="active" Type="Boolean" />
| >
| > <asp:parameter Name="title" Type="String" />
| >
| > <asp:parameter Name="version" Type="String" />
| >
| > <asp:parameter Name="other_version_info" Type="String" />
| >
| > <asp:parameter Name="manufacturer" Type="String" />
| >
| > <asp:parameter Name="media_type_id" Type="Int32" />
| >
| > <asp:parameter Name="license_info" Type="String" />
| >
| > <asp:parameter Name="date_purchased" Type="DateTime" />
| >
| > <asp:parameter Name="ci_id" />
| >
| > </UpdateParameters>
| >
| > <InsertParameters>
| >
| > <asp:parameter Name="active" Type="Boolean" />
| >
| > <asp:parameter Name="title" Type="String" />
| >
| > <asp:parameter Name="version" Type="String" />
| >
| > <asp:parameter Name="other_version_info" Type="String" />
| >
| > <asp:parameter Name="manufacturer" Type="String" />
| >
| > <asp:parameter Name="media_type_id" Type="Int32" />
| >
| > <asp:parameter Name="license_info" Type="String" />
| >
| > <asp:parameter Name="date_purchased" Type="DateTime" />
| >
| > </InsertParameters>
| >
| > </asp:SqlDataSource> &nbsp;
| >
| > <asp:DetailsView ID="DetailsView1" runat="server"
AutoGenerateRows="False"
| > DataKeyNames="ci_id"
| >
| > DataSourceID="SqlDataSource1" Height="50px" Style="position: relative"
| > Width="143px">
| >
| > <Fields>
| >
| > <asp:BoundField DataField="ci_id" HeaderText="ci_id"
InsertVisible="False"
| > ReadOnly="True"
| >
| > SortExpression="ci_id" />
| >
| > <asp:CheckBoxField DataField="active" HeaderText="active"
| > SortExpression="active" />
| >
| > <asp:BoundField DataField="title" HeaderText="title"
| > SortExpression="title" />
| >
| > <asp:BoundField DataField="version" HeaderText="version"
| > SortExpression="version" />
| >
| > <asp:BoundField DataField="other_version_info"
| > HeaderText="other_version_info" SortExpression="other_version_info" />
| >
| > <asp:BoundField DataField="manufacturer" HeaderText="manufacturer"
| > SortExpression="manufacturer" />
| >
| > <asp:BoundField DataField="media_type_id" HeaderText="media_type_id"
| > SortExpression="media_type_id" />
| >
| > <asp:TemplateField HeaderText="Media">
| >
| > <EditItemTemplate>
| >
| > &nbsp;
| >
| > <asp:DropDownList ID="DropDownList1" runat="server"
| > DataSourceID="SqlDataSource2"
| >
| > DataTextField="media_type" DataValueField="media_type_id"
| > Style="left: -6px;
| >
| > position: relative; top: 0px" Width="161px" SelectedValue='<%#
| > Bind("media_type_id") %>'>
| >
| > </asp:DropDownList>
| >
| > </EditItemTemplate>
| >
| > </asp:TemplateField>
| >
| > <asp:BoundField DataField="license_info" HeaderText="license_info"
| > SortExpression="license_info" />
| >
| > <asp:BoundField DataField="date_purchased" HeaderText="date_purchased"
| > SortExpression="date_purchased" />
| >
| > <asp:CommandField ShowDeleteButton="True" ShowEditButton="True"
| > ShowInsertButton="True" />
| >
| > </Fields>
| >
| > </asp:DetailsView>
| >
| > <br />
| >
| >
| >
| > </div>
| >
| > <asp:SqlDataSource ID="SqlDataSource2" runat="server"
| > ConnectionString="<%$ ConnectionStrings:AppsDBConnectionString %>"
| >
| > SelectCommand="SELECT [media_type_id], [media_type] FROM
| > [media_type]"></asp:SqlDataSource>
| >
| > </form>
| >
| > </body>
| >
| > </html>
| >
| >
| >
| > | >> Thanks for your followup.
| >>
| >> Seems strange. Would you try making a simplified page with the controls
| >> that can reproduce the problem so that I can test it on my side? Also,
| >> you
| >> can post the test database's table structure to me...
| >>
| >> Thanks,
| >>
| >> Steven Cheng
| >> Microsoft Online Support
| >>
| >> Get Secure! www.microsoft.com/security
| >> (This posting is provided "AS IS", with no warranties, and confers no
| >> rights.)
| >>
| >> --------------------
| >> | From: "Trevor Bezotte" <[email protected]>
| >> | References: <#[email protected]>
| >> <[email protected]>
| >> <#[email protected]>
| >> <vscaaXZ#[email protected]>
| >> | Subject: Re: DetailsView EditItemTemplate DropdownList Update Problem
| >> | Date: Mon, 5 Dec 2005 08:56:22 -0600
| >> | Lines: 498
| >> | X-Priority: 3
| >> | X-MSMail-Priority: Normal
| >> | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| >> | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| >> | X-RFC2646: Format=Flowed; Original
| >> | Message-ID: <#Rh6Pwa#[email protected]>
| >> | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| >> | NNTP-Posting-Host: global.erdman.com 12.20.65.30
| >> | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP15.phx.gbl
| >> | Xref: TK2MSFTNGXA02.phx.gbl
| >> microsoft.public.dotnet.framework.aspnet.datagridcontrol:14858
| >> | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| >> |
| >> | The database gets updated no problem when I use default controls
| >> (textboxes)
| >> | on the EditItemTemplate, its just when I switch to a dropdownlist
for
| >> one
| >> of
| >> | the fields.
| >> |
| >> | The dropdownlist uses values from a related table.
| >> |
| >> |
| >> | | >> | > Thanks for your response Trevor,
| >> | >
| >> | > So the problems seems occured between the DataBound control and the
| >> | > backend
| >> | > database....., Just during the DataSource control's processing.
| >> Would
| >> | > you
| >> | > try creating a complete new page and readd such databound,
datasource
| >> | > controls to see whether the behavior always remains? I think this
is
| >> | > likely a page specific issue....
| >> | >
| >> | > Regards,
| >> | >
| >> | > Steven Cheng
| >> | > Microsoft Online Support
| >> | >
| >> | > Get Secure! www.microsoft.com/security
| >> | > (This posting is provided "AS IS", with no warranties, and confers
no
| >> | > rights.)
| >> | >
| >> | > --------------------
| >> | > | From: "Trevor Bezotte" <[email protected]>
| >> | > | References: <#[email protected]>
| >> | > <[email protected]>
| >> | > | Subject: Re: DetailsView EditItemTemplate DropdownList Update
| >> Problem
| >> | > | Date: Fri, 2 Dec 2005 08:36:00 -0600
| >> | > | Lines: 407
| >> | > | X-Priority: 3
| >> | > | X-MSMail-Priority: Normal
| >> | > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| >> | > | X-RFC2646: Format=Flowed; Original
| >> | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| >> | > | Message-ID: <#[email protected]>
| >> | > | Newsgroups:
| >> microsoft.public.dotnet.framework.aspnet.datagridcontrol
| >> | > | NNTP-Posting-Host: global.erdman.com 12.20.65.30
| >> | > | Path:
| >> TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| >> | > | Xref: TK2MSFTNGXA02.phx.gbl
| >> | > microsoft.public.dotnet.framework.aspnet.datagridcontrol:14843
| >> | > | X-Tomcat-NG:
| >> microsoft.public.dotnet.framework.aspnet.datagridcontrol
| >> | > |
| >> | > | I checked the profiler and it shows correct parameter, but it
does
| >> not
| >> | > show
| >> | > | the correct parameter value.
| >> | > |
| >> | > | I tried your ItemUpdating code but it does not get fired.
| >> | > |
| >> | > |
| >> | > |
| >> | > |
| >> message
| >> | > | | >> | > | > Hi Trevor,
| >> | > | >
| >> | > | > Welcome to ASPNET newsgroup.
| >> | > | > Regarding on the DetailsView TemplateField updating problem,
| >> based
| >> on
| >> | > my
| >> | > | > experience, for template fields, we can just enable two -way
| >> | > databinding
| >> | > | > as long as we use the <%# bind(....) %> expression in
databinding
| >> | > | > expression. Also, I've checked the code snippet you provide and
| >> | > compare
| >> | > to
| >> | > | > my local test page, seem haven't found any particular
| >> difference...
| >> | > | > Have you tried create a new page and regenerate such
steps(maybe
| >> you
| >> | > can
| >> | > | > just use a detailsView without GridView to make the things
| >> | > | > simplified....)...
| >> | > | >
| >> | > | > Also, one way for testing is register the DetailsView's
| >> ItemUpdating
| >> | > event
| >> | > | > and printout all the new paramters' value there , e.g:
| >> | > | >
| >> | > | > =============
| >> | > | > protected void DetailsView1_ItemUpdating(object sender,
| >> | > | > DetailsViewUpdateEventArgs e)
| >> | > | > {
| >> | > | > foreach(string key in e.NewValues.Keys)
| >> | > | > {
| >> | > | > Response.Write("<br>" + key + " " +
e.NewValues[key]);
| >> | > | > }
| >> | > | >
| >> | > | > e.Cancel = true;
| >> | > | > }
| >> | > | > ============
| >> | > | >
| >> | > | > we can have a look whether all the parameters are provided
| >> | > correclty....
| >> | > | > Also, on sqlserver side, we can using sqlprofiler to monitor
| >> whether
| >> | > the
| >> | > | > final sqlstatement has contained the correctly paratmeters....
| >> | > | >
| >> | > | > BTW, I've also pasted my test page's aspx template below for
your
| >> | > | > reference:
| >> | > | >
| >> | > | > Hope helps. Thanks,
| >> | > | >
| >> | > | > Steven Cheng
| >> | > | > Microsoft Online Support
| >> | > | >
| >> | > | > Get Secure! www.microsoft.com/security
| >> | > | > (This posting is provided "AS IS", with no warranties, and
| >> confers
| >> no
| >> | > | > rights.)
| >> | > | >
| >> | > | > ==================================
| >> | > | > <div>
| >> | > | > <asp:SqlDataSource ID="SqlDataSource1" runat="server"
| >> | > | > ConnectionString="<%$
ConnectionStrings:databaseConnectionString
| >> %>"
| >> | > | > DeleteCommand="DELETE FROM [items] WHERE [id] = @id"
| >> | > | > InsertCommand="INSERT INTO [items] ([name], [priority]) VALUES
| >> (@name,
| >> | > | > @priority)"
| >> | > | > SelectCommand="SELECT [id], [name], [priority] FROM
| >> | > [items]"
| >> | > | > UpdateCommand="UPDATE [items] SET [name] = @name, [priority] =
| >> | > @priority
| >> | > | > WHERE [id] = @id">
| >> | > | > <DeleteParameters>
| >> | > | > <asp:parameter Name="id" Type="Int64" />
| >> | > | > </DeleteParameters>
| >> | > | > <UpdateParameters>
| >> | > | > <asp:parameter Name="name" Type="String" />
| >> | > | > <asp:parameter Name="priority" Type="Int32" />
| >> | > | > <asp:parameter Name="id" Type="Int64" />
| >> | > | > </UpdateParameters>
| >> | > | > <InsertParameters>
| >> | > | > <asp:parameter Name="name" Type="String" />
| >> | > | > <asp:parameter Name="priority" Type="Int32" />
| >> | > | > </InsertParameters>
| >> | > | > </asp:SqlDataSource>
| >> | > | > <asp:DetailsView ID="DetailsView1" runat="server"
| >> | > | > AllowPaging="True" AutoGenerateRows="False"
| >> | > | > DataKeyNames="id" DataSourceID="SqlDataSource1"
| >> | > Height="50px"
| >> | > | > Width="125px" OnItemUpdating="DetailsView1_ItemUpdating">
| >> | > | > <Fields>
| >> | > | > <asp:BoundField DataField="id" HeaderText="id"
| >> | > | > InsertVisible="False" ReadOnly="True"
| >> | > | > SortExpression="id" />
| >> | > | > <asp:BoundField DataField="name"
HeaderText="name"
| >> | > | > SortExpression="name" />
| >> | > | > <asp:TemplateField HeaderText="priority"
| >> | > | > SortExpression="priority">
| >> | > | > <EditItemTemplate>
| >> | > | > <asp:DropDownList ID="lstPriority"
| >> | > runat="server"
| >> | > | > SelectedValue='<%# Bind("priority") %>'
| >> DataSourceID="SqlDataSource3"
| >> | > | > DataTextField="pname" DataValueField="pid">
| >> | > | > <asp:ListItem
| >> Value="0">low</asp:ListItem>
| >> | > | > <asp:ListItem
| >> | > Value="1">middle</asp:ListItem>
| >> | > | > <asp:ListItem
| >> Value="2">high</asp:ListItem>
| >> | > | > </asp:DropDownList>
| >> | > | > <asp:SqlDataSource ID="SqlDataSource3"
| >> | > | > runat="server" CacheDuration="300" ConnectionString="<%$
| >> | > | > ConnectionStrings:databaseConnectionString %>"
| >> | > | > EnableCaching="True"
| >> SelectCommand="SELECT
| >> | > | > DISTINCT [pid], [pname] FROM [priorities]">
| >> | > | > </asp:SqlDataSource>
| >> | > | > </EditItemTemplate>
| >> | > | > <InsertItemTemplate>
| >> | > | > <asp:TextBox ID="TextBox1"
runat="server"
| >> | > Text='<%#
| >> | > | > Bind("priority") %>'></asp:TextBox>
| >> | > | > </InsertItemTemplate>
| >> | > | > <ItemTemplate>
| >> | > | > <asp:DropDownList ID="lstPriority"
| >> | > runat="server"
| >> | > | > Enabled="False" SelectedValue='<%# Bind("priority") %>'
| >> | > | > DataSourceID="SqlDataSource2" DataTextField="pname"
| >> | > DataValueField="pid">
| >> | > | > <asp:ListItem
| >> Value="0">low</asp:ListItem>
| >> | > | > <asp:ListItem
| >> | > Value="1">middle</asp:ListItem>
| >> | > | > <asp:ListItem
| >> Value="2">high</asp:ListItem>
| >> | > | > </asp:DropDownList>
| >> | > | > <asp:SqlDataSource ID="SqlDataSource2"
| >> | > | > runat="server" CacheDuration="600" ConnectionString="<%$
| >> | > | > ConnectionStrings:databaseConnectionString %>"
| >> | > | > EnableCaching="True"
| >> SelectCommand="SELECT
| >> | > | > DISTINCT [pid], [pname] FROM [priorities]">
| >> | > | > </asp:SqlDataSource>
| >> | > | > </ItemTemplate>
| >> | > | > </asp:TemplateField>
| >> | > | > <asp:CommandField ShowDeleteButton="True"
| >> | > | > ShowEditButton="True" ShowInsertButton="True" />
| >> | > | > </Fields>
| >> | > | > </asp:DetailsView>
| >> | > | >
| >> | > | > </div>
| >> | > | > =======================
| >> | > | >
| >> | > | >
| >> | > | >
| >> | > | >
| >> | > | > --------------------
| >> | > | > | From: "Trevor Bezotte" <[email protected]>
| >> | > | > | Subject: DetailsView EditItemTemplate DropdownList Update
| >> Problem
| >> | > | > | Date: Thu, 1 Dec 2005 14:53:40 -0600
| >> | > | > | Lines: 234
| >> | > | > | X-Priority: 3
| >> | > | > | X-MSMail-Priority: Normal
| >> | > | > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| >> | > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| >> | > | > | X-RFC2646: Format=Flowed; Original
| >> | > | > | Message-ID: <#[email protected]>
| >> | > | > | Newsgroups:
| >> microsoft.public.dotnet.framework.aspnet.datagridcontrol
| >> | > | > | NNTP-Posting-Host: global.erdman.com 12.20.65.30
| >> | > | > | Path:
| >> | > TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| >> | > | > | Xref: TK2MSFTNGXA02.phx.gbl
| >> | > | > microsoft.public.dotnet.framework.aspnet.datagridcontrol:14838
| >> | > | > | X-Tomcat-NG:
| >> | > microsoft.public.dotnet.framework.aspnet.datagridcontrol
| >> | > | > |
| >> | > | > | Hi!
| >> | > | > |
| >> | > | > | I have a DetailsView with a DropDownList in an
| >> EditItemTemplate, I
| >> | > know,
| >> | > | > | pretty cool right? But when I try to Update the table with a
| >> new
| >> | > value
| >> | > | > from
| >> | > | > | the DropDownList the table does not get updated with the new
| >> value.
| >> | > I'm
| >> | > | > new
| >> | > | > | at this and I'm sure I'm overlooking something simple here.
| >> I'll
| >> | > post
| >> | > | > the
| >> | > | > | ASP code, hopefully someone can help me with this one.
| >> | > | > |
| >> | > | > | Thank you!
| >> | > | > |
| >> | > | > |
| >> | > | > | <%@ Page Language="C#" masterpagefile="~/software.master"
| >> | > | > | AutoEventWireup="true" CodeFile="MasterDetail.aspx.cs"
| >> Debug="true"
| >> | > | > | Inherits="MasterDetail" %>
| >> | > | > |
| >> | > | > | <asp:Content ID="SoftwareData" runat="server"
| >> | > | > | ContentPlaceHolderID="PageBody">
| >> | > | > |
| >> | > | > |
| >> | > | > |
| >> | > | > | <table><tr>
| >> | > | > |
| >> | > | > | <td valign="top" style="width: 280px">
| >> | > | > |
| >> | > | > | <asp:GridView ID="SummaryGrid" runat="server"
| >> | > | > | DataSourceID="AppsDBDataSource"
| >> | > | > |
| >> | > | > | EnableViewState="False"
| >> | > | > |
| >> | > | > | DataKeyNames="ci_id" AllowPaging="True"
| >> | > | > |
| >> | > | > | AutoGenerateSelectButton="True"
| >> | > | > |
| >> | > | > | AutoGenerateColumns="False" style="left: 73px; position:
| >> relative;
| >> | > top:
| >> | > | > 9px"
| >> | > | > | BackColor="White" BorderColor="#999999" BorderStyle="None"
| >> | > | > BorderWidth="1px"
| >> | > | > | CellPadding="3" Font-Names="Arial" Font-Size="X-Small"
| >> | > | > GridLines="Vertical"
| >> | > | > | Width="492px" PageSize="5">
| >> | > | > |
| >> | > | > | <Columns>
| >> | > | > |
| >> | > | > | <asp:BoundField DataField="manufacturer"
| >> HeaderText="Manufacturer"
| >> | > />
| >> | > | > |
| >> | > | > | <asp:BoundField DataField="title" HeaderText="Title" />
| >> | > | > |
| >> | > | > | <asp:BoundField DataField="version" HeaderText="Version" />
| >> | > | > |
| >> | > | > | </Columns>
| >> | > | > |
| >> | > | > | <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
| >> | > | > |
| >> | > | > | <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
| >> | > | > |
| >> | > | > | <SelectedRowStyle BackColor="#008A8C" Font-Bold="True"
| >> | > ForeColor="White"
| >> | > | > />
| >> | > | > |
| >> | > | > | <PagerStyle BackColor="#999999" ForeColor="Black"
| >> | > | > HorizontalAlign="Center"
| >> | > | > | />
| >> | > | > |
| >> | > | > | <HeaderStyle BackColor="#000084" Font-Bold="True"
| >> ForeColor="White"
| >> | > />
| >> | > | > |
| >> | > | > | <AlternatingRowStyle BackColor="Gainsboro" />
| >> | > | > |
| >> | > | > | </asp:GridView>
| >> | > | > |
| >> | > | > | </td>
| >> | > | > |
| >> | > | > | <td valign="top">
| >> | > | > |
| >> | > | > | <asp:DetailsView ID="DetailsView1" runat="server"
| >> | > | > |
| >> | > | > | DataKeyNames="ci_id, media_type_id"
| >> | > | > |
| >> | > | > | HeaderText="Software Package Details"
| >> | > | > |
| >> | > | > | EmptyDataText="No package currently selected"
| >> | > | > |
| >> | > | > | DataSourceID="RowDataSource"
| >> | > | > |
| >> | > | > | AutoGenerateInsertButton="True"
| >> | > | > |
| >> | > | > | AutoGenerateDeleteButton="True"
| >> | > | > |
| >> | > | > | AutoGenerateEditButton="True"
| >> | > OnItemUpdated="DetailsView1_ItemUpdated"
| >> | > | > | style="left: 73px; position: relative; top: 9px"
| >> BackColor="White"
| >> | > | > | BorderColor="#999999" BorderStyle="None" BorderWidth="1px"
| >> | > | > CellPadding="3"
| >> | > | > | Font-Names="Arial" Font-Size="X-Small" GridLines="Vertical"
| >> | > | > Width="320px"
| >> | > | > | AutoGenerateRows="False">
| >> | > | > |
| >> | > | > | <Fields>
| >> | > | > |
| >> | > | > | <asp:BoundField DataField="ci_id" HeaderText="ID"
| >> ReadOnly="True"
| >> />
| >> | > | > |
| >> | > | > | <asp:CheckBoxField DataField="active" HeaderText="Active"
| >> | > | > | SortExpression="active" />
| >> | > | > |
| >> | > | > | <asp:BoundField DataField="title" HeaderText="Title" >
| >> | > | > |
| >> | > | > | <ControlStyle Width="225px" />
| >> | > | > |
| >> | > | > | </asp:BoundField>
| >> | > | > |
| >> | > | > | <asp:BoundField DataField="version" HeaderText="Version" />
| >> | > | > |
| >> | > | > | <asp:BoundField DataField="other_version_info"
| >> HeaderText="Version
| >> | > Info"
| >> | > | > />
| >> | > | > |
| >> | > | > | <asp:BoundField DataField="manufacturer"
| >> HeaderText="Manufacturer"
| >> | > />
| >> | > | > |
| >> | > | > | <asp:TemplateField HeaderText="Media">
| >> | > | > |
| >> | > | > | <EditItemTemplate>
| >> | > | > |
| >> | > | > | &nbsp;
| >> | > | > |
| >> | > | > | <asp:DropDownList ID="DropDownList1" runat="server"
| >> | > | > | DataSourceID="SQLMediaTypes"
| >> | > | > |
| >> | > | > | DataTextField="media_type" DataValueField="media_type_id"
| >> | > Style="left:
| >> | > | > -6px;
| >> | > | > |
| >> | > | > | position: relative; top: 0px" Width="161px"
SelectedValue='<%#
| >> | > | > | Bind("media_type_id") %>'>
| >> | > | > |
| >> | > | > | </asp:DropDownList>
| >> | > | > |
| >> | > | > | </EditItemTemplate>
| >> | > | > |
| >> | > | > | <InsertItemTemplate>
| >> | > | > |
| >> | > | > | <asp:DropDownList ID="DropDownList2" runat="server"
| >> | > | > | DataSourceID="SQLMediaTypes"
| >> | > | > |
| >> | > | > | DataTextField="media_type" DataValueField="media_type_id"
| >> | > Style="left:
| >> | > | > 0px;
| >> | > | > |
| >> | > | > | position: relative; top: 0px" Width="161px"
SelectedValue='<%#
| >> | > | > | Bind("media_type_id") %>'>
| >> | > | > |
| >> | > | > | </asp:DropDownList>
| >> | > | > |
| >> | > | > | </InsertItemTemplate>
| >> | > | > |
| >> | > | > | <ItemTemplate>
| >> | > | > |
| >> | > | > | <asp:Label ID="Label1" runat="server" Text='<%#
| >> Bind("media_type")
| >> | > | > | %>'></asp:Label>
| >> | > | > |
| >> | > | > | </ItemTemplate>
| >> | > | > |
| >> | > | > | </asp:TemplateField>
| >> | > | > |
| >> | > | > | <asp:BoundField DataField="license_info" HeaderText="License
| >> Info"
| >> | > />
| >> | > | > |
| >> | > | > | <asp:BoundField DataField="date_purchased"
HeaderText="Purchase
| >> | > Date"
| >> | > | > | SortExpression="date_purchased" />
| >> | > | > |
| >> | > | > |
| >> | > | > | </Fields>
| >> | > | > |
| >> | > | > | <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
| >> | > | > |
| >> | > | > | <EditRowStyle BackColor="#008A8C" Font-Bold="True"
| >> ForeColor="White"
| >> | > | > | Font-Names="Arial" Font-Size="X-Small" />
| >> | > | > |
| >> | > | > | <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
| >> | > | > |
| >> | > | > | <PagerStyle BackColor="#999999" ForeColor="Black"
| >> | > | > HorizontalAlign="Center"
| >> | > | > | />
| >> | > | > |
| >> | > | > | <HeaderStyle BackColor="#000084" Font-Bold="True"
| >> ForeColor="White"
| >> | > />
| >> | > | > |
| >> | > | > | <AlternatingRowStyle BackColor="Gainsboro" />
| >> | > | > |
| >> | > | > | </asp:DetailsView>
| >> | > | > |
| >> | > | > | </td>
| >> | > | > |
| >> | > | > | </tr></table>
| >> | > | > |
| >> | > | > | <asp:Label ID="Label2" runat="server" Font-Names="Courier
New"
| >> | > | > Height="28px"
| >> | > | > | Style="z-index: 103;
| >> | > | > |
| >> | > | > | left: 28px; position: absolute; top: -298px"
| >> | > Width="379px">Application
| >> | > | > | Management Database</asp:Label>
| >> | > | > |
| >> | > | > | <asp:SqlDataSource ID="AppsDBDataSource" runat="server"
| >> | > | > |
| >> | > | > | EnableCaching="false"
| >> | > CacheKeyDependency="AppsDBDataSource_Controller"
| >> | > | > |
| >> | > | > | ConnectionString='<%$ ConnectionStrings:LocalAppsDB %>'
| >> | > | > |
| >> | > | > | SelectCommand="SELECT * FROM vwSoftware">
| >> | > | > |
| >> | > | > | </asp:SqlDataSource>
| >> | > | > |
| >> | > | > | <asp:SqlDataSource ID="RowDataSource" runat="server"
| >> | > | > |
| >> | > | > | EnableCaching="false"
| >> | > | > |
| >> | > | > | ConnectionString='<%$ ConnectionStrings:LocalAppsDB %>'
| >> | > | > |
| >> | > | > | SelectCommand="SELECT * FROM vwSoftware WHERE ci_id=@ci_id"
| >> | > | > |
| >> | > | > | UpdateCommand="UPDATE software SET active=@active,
| >> title=@title,
| >> | > | > | version=@version, other_version_info=@other_version_info,
| >> | > | > | manufacturer=@manufacturer, media_type_id=@media_type_id,
| >> | > | > | license_info=@license_info, date_purchased=@date_purchased
| >> WHERE
| >> | > | > | ci_id=@ci_id"
| >> | > | > |
| >> | > | > | InsertCommand="INSERT INTO software(active, title, version,
| >> | > | > | other_version_info, manufacturer, media_type_id,
license_info,
| >> | > | > | date_purchased) VALUES(@active, @title, @version,
| >> | > @other_version_info,
| >> | > | > | @manufacturer, @media_type_id, @license_info,
@date_purchased)"
| >> | > | > |
| >> | > | > | DeleteCommand="DELETE FROM software WHERE ci_id=@ci_id">
| >> | > | > |
| >> | > | > | <SelectParameters>
| >> | > | > |
| >> | > | > | <asp:ControlParameter Name="ci_id" ControlID="SummaryGrid"
| >> | > | > | PropertyName="SelectedValue" />
| >> | > | > |
| >> | > | > | </SelectParameters>
| >> | > | > |
| >> | > | > | </asp:SqlDataSource>
| >> | > | > |
| >> | > | > | <asp:SqlDataSource ID="SQLMediaTypes" runat="server"
| >> | > | > ConnectionString="<%$
| >> | > | > | ConnectionStrings:LocalAppsDB %>"
| >> | > | > |
| >> | > | > | OnSelecting="SQLMediaTypes_Selecting" ProviderName="<%$
| >> | > | > | ConnectionStrings:LocalAppsDB.ProviderName %>"
| >> | > | > |
| >> | > | > | SelectCommand="SELECT [media_type_id], [media_type] FROM
| >> | > | > | [media_type]"></asp:SqlDataSource>
| >> | > | > |
| >> | > | > |
| >> | > | > | </asp:Content>
| >> | > | > |
| >> | > | > |
| >> | > | > |
| >> | > | >
| >> | > |
| >> | > |
| >> | > |
| >> | >
| >> |
| >> |
| >> |
| >>
| >
| >
|
|
|
 

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

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top