Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 11th, 2006, 08:44 AM
Registered User
 
Join Date: Jul 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default DDL error

I have an issue with one of my dropdown lists. Let me explain the application so you can understand the issue better. I have an ASP.NET 2.0 application written in VB that tracks vacation requests one of the fields it tracks is the manager. The data for the manager is pulled from a table that is populated by a script that pulls data from Active Directory.This way the managers are kept up to date. I setup an edit page that uses a dropdown list so that we can change the manager if a user changes position or the manager leaves. The problem I have is if a manager leaves my edit page errors because the manager ddl no longer has the old manager in the list and the request references the old manager. How do I set it so that when it encounters the error it changes to a default value? To complicate this a little more the DDL is in a templatefield of a details view.

Here is the Details view code:

 <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
            CellPadding="4" DataSourceID="SqlDataSource4" ForeColor="#333333" GridLines="None"
            Height="50px" Width="329px" DataKeyNames="RecNum" HeaderText="Request Details">
            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
            <EditRowStyle BackColor="#999999" />
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <Fields>
                <asp:BoundField DataField="RecNum" HeaderText="RecNum" InsertVisible="False" ReadOnly="True"
                    SortExpression="RecNum" Visible="False" />
                <asp:BoundField DataField="Requester" HeaderText="Requester" SortExpression="Requester" ReadOnly="True" >
                    <ItemStyle Font-Size="Small" />
                    <HeaderStyle Font-Size="Small" />
                </asp:BoundField>
                <asp:TemplateField HeaderText="From" SortExpression="From1">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("From1", "{0:MM/dd/yyyy}") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("From1", "{0:MM/dd/yyyy}") %>'></asp:TextBox>
                    </InsertItemTemplate>
                    <ItemStyle Font-Size="Small" />
                    <HeaderStyle Font-Size="Small" />
                    <ItemTemplate>
                        <asp:Label ID="Label2" runat="server" Text='<%# Bind("From1", "{0:MM/dd/yyyy}") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="To" SortExpression="To1">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("To1", "{0:MM/dd/yyyy}") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("To1", "{0:MM/dd/yyyy}") %>'></asp:TextBox>
                    </InsertItemTemplate>
                    <ItemStyle Font-Size="Small" />
                    <HeaderStyle Font-Size="Small" />
                    <ItemTemplate>
                        <asp:Label ID="Label6" runat="server" Text='<%# Bind("To1", "{0:MM/dd/yyyy}") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="NoDays1" HeaderText="# of Days" SortExpression="NoDays1" >
                    <ItemStyle Font-Size="Small" />
                    <HeaderStyle Font-Size="Small" />
                </asp:BoundField>
                <asp:BoundField DataField="RequestDate" DataFormatString="{0:MM/dd/yyyy}" HeaderText="Request Date"
                    HtmlEncode="False" ReadOnly="True" SortExpression="RequestDate">
                    <ItemStyle Font-Size="Small" />
                    <HeaderStyle Font-Size="Small" />
                </asp:BoundField>
                <asp:TemplateField HeaderText="Request Type" SortExpression="ReqType">
                    <EditItemTemplate>
                        &nbsp;<asp:DropDownList ID="DropDownList4" runat="server" DataSourceID="SqlDataSource8"
                            DataTextField="ReqType" DataValueField="ReqType" SelectedValue='<%# Bind("ReqType") %>'>
                        </asp:DropDownList>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("ReqType") %>'></asp:TextBox>
                    </InsertItemTemplate>
                    <ItemStyle Font-Size="Small" />
                    <HeaderStyle Font-Size="Small" />
                    <ItemTemplate>
                        <asp:Label ID="Label4" runat="server" Text='<%# Bind("ReqType") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Manager" SortExpression="Manager">
                    <EditItemTemplate>
                        <asp:DropDownList ID="DropDownList5" runat="server" DataSourceID="SqlDataSource7" AppendDataBoundItems="True"
                            DataTextField="Manager_Name" DataValueField="Manager_Name" SelectedValue='<%# Bind("Manager") %>'>
                        </asp:DropDownList>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("Manager") %>'></asp:TextBox>
                    </InsertItemTemplate>
                    <ItemStyle Font-Size="Small" />
                    <HeaderStyle Font-Size="Small" />
                    <ItemTemplate>
                        <asp:Label ID="Label5" runat="server" Text='<%# Bind("Manager") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Approved" SortExpression="Approved">
                    <EditItemTemplate>
                        <asp:DropDownList ID="DropDownList3" runat="server" DataSourceID="SqlDataSource6"
                            DataTextField="ApprovalStatus" DataValueField="ApprovalStatus" SelectedValue='<%# Bind("Approved") %>'>
                        </asp:DropDownList>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Approved") %>'></asp:TextBox>
                    </InsertItemTemplate>
                    <ItemStyle Font-Size="Small" />
                    <HeaderStyle Font-Size="Small" />
                    <ItemTemplate>
                        <asp:Label ID="Label3" runat="server" Text='<%# Bind("Approved") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="Approver" HeaderText="Approver" SortExpression="Approver" ReadOnly="True" >
                    <ItemStyle Font-Size="Small" />
                    <HeaderStyle Font-Size="Small" />
                </asp:BoundField>
                <asp:BoundField DataField="ApprovedDate" HeaderText="Approved Date" SortExpression="ApprovedDate" ReadOnly="True" >
                    <ItemStyle Font-Size="Small" />
                    <HeaderStyle Font-Size="Small" />
                </asp:BoundField>
                <asp:TemplateField HeaderText="Department" SortExpression="Department">
                    <EditItemTemplate>
                        <asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="SqlDataSource5"
                            DataTextField="Department" DataValueField="Department" SelectedValue='<%# Bind("Department") %>'>
                        </asp:DropDownList>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Department") %>'></asp:TextBox>
                    </InsertItemTemplate>
                    <ItemStyle Font-Size="Small" />
                    <HeaderStyle Font-Size="Small" />
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("Department") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:CommandField ShowEditButton="True" ShowDeleteButton="True" >
                    <ItemStyle Font-Size="Small" />
                </asp:CommandField>
            </Fields>
            <FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
        </asp:DetailsView>

My guess is that I have to do something when the details view is binding to the data but can't figure out exactly what or how to reference the ddl inside the template field.

Any help would be greatly apprecated.


 
Old July 16th, 2006, 11:03 PM
Friend of Wrox
 
Join Date: Apr 2005
Posts: 190
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try-Catch block in the code behind.
VV


 
Old July 17th, 2006, 08:07 AM
Registered User
 
Join Date: Jul 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am not sure how to access the drop down element in the code behind since it is with in a template field. If I could access it I would then be able to try the catch error option. Any information on this would be helpful.






Similar Threads
Thread Thread Starter Forum Replies Last Post
DDL Custom Validator AspNetGuy BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 June 6th, 2008 05:17 PM
how can selectedvalue of DDL make other DDL visibl hertendreef ASP.NET 2.0 Professional 4 May 20th, 2008 04:38 PM
DropDownList into DataGrid-Every Row has a DDL su ASP.NET 1.0 and 1.1 Basics 0 November 29th, 2006 05:39 PM
DDL in DG (binding problem) RPG SEARCH ASP.NET 1.0 and 1.1 Basics 2 March 8th, 2005 12:50 PM
ddl response.redirect and passing value dorothee ASP.NET 1.0 and 1.1 Basics 0 June 11th, 2004 03:14 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.