DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

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

  1. #1
    Join Date
    Feb 2006
    Posts
    10

    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>
    &nbsp;<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>

  2. #2
    Join Date
    Feb 2006
    Posts
    10
    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.

  3. #3
    Join Date
    Apr 2006
    Posts
    1

    Example?

    Is it possible to see an example of the final code you are referring to? Many thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center