Click here to Skip to main content
15,902,635 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a detailsview that I am populating with a datatable. I also have templated fields for custom code. The detailsview shows both sets of data which are duplicates, one set from the datatable and the other set from the templated fields. I only want to display one set of the data, that being the templated fields. Can someone explain to me my falacies and suggest a better way to handle this please?

Also, I cannot use SqlDataSources due to the way this program was originally designed. The code I have is below and shortened in the detailsview to make it easier to read.

XML
<asp:DetailsView ID="DetailsView1" runat="server" onmodechanging="DetailsView1_ModeChanging" OnItemUpdating="DetailsView1_ItemUpdating"
          DefaultMode="Edit" CssClass="panelStyle" OnDataBound="DetailsView1_DataBound" CausesValidation="false" GridLines="None"><%----%>
        <Fields>
            <asp:TemplateField HeaderText="Function Name">
                <EditItemTemplate>
                    <asp:DropDownList ID="ddlfunctions" runat="server"
                        DataSource='<%# _functionCollection %>' DataTextField="Display" DataValueField="Name">
                    </asp:DropDownList>
                    <br />
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server"
                        Text='<%# Bind("entryFunctionName") %>'></asp:TextBox>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("entryFunctionName") %>'></asp:Label>
                </ItemTemplate>
</Fields>
</asp:DetailsView>


C#
string entryID;
        DataTable dtEdit = new DataTable();

        protected void gvEntries_SelectedIndexChanged(object sender, EventArgs e)
        {
            // Determine the index of the selected row.
            int index = gvEntries.SelectedIndex;
            entryID = gvEntries.DataKeys[index].Value.ToString();

            string queryString = ("Select [entryFunctionName], [entrySegment], [entryLOB]," +
            "[entryTime], [entryAccountNumber], [entryProgramRevOrg], [entryQuantity], " +
            "[entryNotes] From tblEntries Where entryEntryID = " + entryID);
            dtEdit = DDLGetData(queryString);

            DetailsView1.ChangeMode(DetailsViewMode.Edit);
            DetailsView1.DataSource = dtEdit;
            DetailsView1.DataBind();

            ModalPopupExtender1.Controls.Add(editPanel);
            ModalPopupExtender1.Show();
        }
Posted

1 solution

If you want to show only your template fields you should set
DetailsView.AutoGenerateRows = false;
or
ASP.NET
<asp:detailsview id="DetailsView1" runat="server" autogeneraterows="false" onmodechanging="DetailsView1_ModeChanging" onitemupdating="DetailsView1_ItemUpdating" defaultmode="Edit" cssclass="panelStyle" ondatabound="DetailsView1_DataBound" causesvalidation="false" gridlines="None" xmlns:asp="#unknown">

</asp:detailsview>
 
Share this answer
 
Comments
Richard C Bishop 13-Sep-12 13:31pm    
Oh man, I did not notice that it was set to True because it was not in the HTML, only the Properties window. Thank you very much.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900