Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Records won't display in DetailsView

Status
Not open for further replies.

yaknowss

Programmer
Apr 19, 2012
69
US
I currently have a table in DetailsView that has insert / edit capabilities, and is also filtered based on customer (constituent) ID. Currently, the table only appears in a browser if the constituent has a previous entry to filter by. I need this table to be viewable for all constituents, even if they do not have a previous entry so we can insert new entries for that constituent. Please find my code below.

Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" %>

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

<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="697px" 
            AllowPaging="True" AutoGenerateRows="False" DataKeyNames="NamedSeatId" 
            DataSourceID="SqlDataSource1">
            <Fields>
                <asp:BoundField DataField="ConstituentId" HeaderText="ConstituentId" 
                    SortExpression="ConstituentId" />
                <asp:BoundField DataField="NamedSeatId" HeaderText="NamedSeatId" 
                    InsertVisible="False" ReadOnly="True" SortExpression="NamedSeatId" />
                <asp:BoundField DataField="HallId" HeaderText="HallId" 
                    SortExpression="HallId" />
                <asp:BoundField DataField="SectionId" HeaderText="SectionId" 
                    SortExpression="SectionId" />
                <asp:BoundField DataField="Seat" HeaderText="Seat" SortExpression="Seat" />
                <asp:BoundField DataField="GiftOf" HeaderText="GiftOf" 
                    SortExpression="GiftOf" />
                <asp:BoundField DataField="Honoree" HeaderText="Honoree" 
                    SortExpression="Honoree" />
                <asp:CommandField ButtonType="Button" ShowEditButton="True" 
                    ShowInsertButton="True" />
            </Fields>

        </asp:DetailsView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConflictDetection="CompareAllValues" 
            ConnectionString="<%$ ConnectionStrings:ImpresarioConnectionString-LIVE %>" 
            DeleteCommand="DELETE FROM [sl_NamedSeat] WHERE [NamedSeatId] = @original_NamedSeatId AND [HallId] = @original_HallId AND [SectionId] = @original_SectionId AND [Seat] = @original_Seat AND (([GiftOf] = @original_GiftOf) OR ([GiftOf] IS NULL AND @original_GiftOf IS NULL)) AND (([Honoree] = @original_Honoree) OR ([Honoree] IS NULL AND @original_Honoree IS NULL)) AND (([ConstituentId] = @original_ConstituentId) OR ([ConstituentId] IS NULL AND @original_ConstituentId IS NULL))" 
            InsertCommand="INSERT INTO [sl_NamedSeat] ([HallId], [SectionId], [Seat], [GiftOf], [Honoree], [ConstituentId]) VALUES (@HallId, @SectionId, @Seat, @GiftOf, @Honoree, @ConstituentId)" 
            OldValuesParameterFormatString="original_{0}" 
            SelectCommand="SELECT * FROM [sl_NamedSeat] Where ConstituentId = @ConstituentId" 
            UpdateCommand="UPDATE [sl_NamedSeat] SET [HallId] = @HallId, [SectionId] = @SectionId, [Seat] = @Seat, [GiftOf] = @GiftOf, [Honoree] = @Honoree, [ConstituentId] = @ConstituentId WHERE [NamedSeatId] = @original_NamedSeatId AND [HallId] = @original_HallId AND [SectionId] = @original_SectionId AND [Seat] = @original_Seat AND (([GiftOf] = @original_GiftOf) OR ([GiftOf] IS NULL AND @original_GiftOf IS NULL)) AND (([Honoree] = @original_Honoree) OR ([Honoree] IS NULL AND @original_Honoree IS NULL)) AND (([ConstituentId] = @original_ConstituentId) OR ([ConstituentId] IS NULL AND @original_ConstituentId IS NULL))">
            <SelectParameters>
                <asp:QueryStringParameter Name="ConstituentId" QueryStringField="ConstituentId" />
            </SelectParameters>
            <DeleteParameters>
                <asp:Parameter Name="original_NamedSeatId" Type="Int32" />
                <asp:Parameter Name="original_HallId" Type="Int32" />
                <asp:Parameter Name="original_SectionId" Type="Int32" />
                <asp:Parameter Name="original_Seat" Type="String" />
                <asp:Parameter Name="original_GiftOf" Type="String" />
                <asp:Parameter Name="original_Honoree" Type="String" />
                <asp:Parameter Name="original_ConstituentId" Type="Int32" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="HallId" Type="Int32" />
                <asp:Parameter Name="SectionId" Type="Int32" />
                <asp:Parameter Name="Seat" Type="String" />
                <asp:Parameter Name="GiftOf" Type="String" />
                <asp:Parameter Name="Honoree" Type="String" />
                <asp:Parameter Name="ConstituentId" Type="Int32" />
            </InsertParameters>
            <UpdateParameters>
                <asp:Parameter Name="HallId" Type="Int32" />
                <asp:Parameter Name="SectionId" Type="Int32" />
                <asp:Parameter Name="Seat" Type="String" />
                <asp:Parameter Name="GiftOf" Type="String" />
                <asp:Parameter Name="Honoree" Type="String" />
                <asp:Parameter Name="ConstituentId" Type="Int32" />
                <asp:Parameter Name="original_NamedSeatId" Type="Int32" />
                <asp:Parameter Name="original_HallId" Type="Int32" />
                <asp:Parameter Name="original_SectionId" Type="Int32" />
                <asp:Parameter Name="original_Seat" Type="String" />
                <asp:Parameter Name="original_GiftOf" Type="String" />
                <asp:Parameter Name="original_Honoree" Type="String" />
                <asp:Parameter Name="original_ConstituentId" Type="Int32" />
            </UpdateParameters>
        </asp:SqlDataSource>
    </div>
    </form>
</body>
</html>

Any ideas? Thank you in advance.
 
Can you return a 'default' instantiation of a constituent when there isn't an existing on in your data source?

You would probably need to customise the view to template fields so you can hide/show an edit button as appropriate tho' as you probably wouldn't want to allow editing of such.

Rhys

"Technological progress is like an axe in the hands of a pathological criminal"
"Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe"
Albert Einstein
 
Thank you for your response.

As of now, the screen appears blank and the details view is not visible if a constituent isnt existing in my data source.

I've never customized a view to template fields before...
 
Adding an EmptyTemplate did the trick.

Code:
<EmptyDataTemplate>
<div class="noMatch">
<h1>No Matching Results!</h1>
Please select a different record.
<asp:Button ID="InsertButton" runat="server" Text="Insert New record" CommandName="New" />
</div>
</EmptyDataTemplate>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top