Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

DetailsViews Update sql with a template dropdownlist and multi line text box

I am using a details view to drill down to single records from a gridview on a previous page. Inside the details view I have converted 2 fields to template fields and changed the controls from the default textboxes to one being a dropdownlist and the other a text box set to multi-line to replicate a <textarea> box. I am having a difficult of a time getting any update statement to work when configuring the data source on the detailview.

How do I reference the selected value in the dropdown list control and the entered text in the multiline text vox to be able to update the appropriate fields in the associated table?

<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" CellPadding="4"
DataSourceID="DetailComplianceWI" ForeColor="#333333" GridLines="None" Height="50px"
Width="100%" DataKeyNames="ID">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<CommandRowStyle BackColor="#D1DDF1" Font-Bold="True" />
<EditRowStyle BackColor="#8080FF" />
<RowStyle BackColor="#EFF3FB" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<Fields>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
SortExpression="ID" />
<asp:BoundField DataField="RepName" HeaderText="RepName" SortExpression="RepName" ReadOnly="True" />
<asp:BoundField DataField="Extension" HeaderText="Extension" SortExpression="Extension" ReadOnly="True" />
<asp:BoundField DataField="Submitted" HeaderText="Submitted" SortExpression="Submitted" ReadOnly="True" />
<asp:TemplateField HeaderText="Status">
<EditItemTemplate>
<asp:DropDownList ID="DDStatus" runat="server"
Width="180px" DataTextField="Status" DataValueField="Status" SelectedValue='<%# Bind("Status") %>'>
<asp:ListItem>New</asp:ListItem>
<asp:ListItem>Pending</asp:ListItem>
<asp:ListItem>Closed</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Status") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="TMInboundStart" HeaderText="TMInboundStart" SortExpression="TMInboundStart" ReadOnly="True" />
<asp:BoundField DataField="TMInboundStop" HeaderText="TMInboundStop" SortExpression="TMInboundStop" ReadOnly="True" />
<asp:BoundField DataField="InboundBilingualStartStop" HeaderText="InboundBilingualStartStop"
SortExpression="InboundBilingualStartStop" ReadOnly="True" />
<asp:BoundField DataField="DateTimeCompleted" HeaderText="DateTimeCompleted" SortExpression="DateTimeCompleted" ReadOnly="True" />
<asp:BoundField DataField="ClosedBy" HeaderText="ClosedBy" SortExpression="ClosedBy" ReadOnly="True" />
<asp:TemplateField HeaderText="WFM_Notes" SortExpression="WFM_Notes">
<EditItemTemplate>
<asp:TextBox ID="txtWFM_Notes" runat="server" Height="81px" Text='<%# Bind("WFM_Notes") %>'
TextMode="MultiLine" Width="95%"></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("WFM_Notes") %>'></asp:TextBox>
</InsertItemTemplate>
<ControlStyle Width="95%" />
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("WFM_Notes") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
</Fields>
<FieldHeaderStyle BackColor="#DEE8F5" Font-Bold="True" Width="15%" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:DetailsView>
<asp:SqlDataSource ID="DetailComplianceWI" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionStringCompliance %>"
ProviderName="<%$ ConnectionStrings:ConnectionStringCompliance.ProviderName %>"
SelectCommand="SELECT * FROM [tblCompliance] WHERE ([ID] = ?)">
<SelectParameters>
<asp:QueryStringParameter Name="ID" QueryStringField="ID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
[5805 byte] By [dagdamor67] at [2007-11-11 8:10:46]
# 1 Re: DetailsViews Update sql with a template dropdownlist and multi line text box
I enable two way data binding and then made sure to delcare the update parameters to be the controlID and Selected value and now it works.
dagdamor67 at 2007-11-11 23:13:27 >
# 2 Re: DetailsViews Update sql with a template dropdownlist and multi line text box
Is it possible to see an example of the final code you are referring to? Many thanks!
phixate at 2007-11-11 23:14:23 >