Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7187555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:52:20+00:00 2026-05-28T18:52:20+00:00

My page has a DetailsView that has a hidden field in it that gets

  • 0

My page has a DetailsView that has a hidden field in it that gets referenced by an SQLDataSource to populate a different field in the same DetailsView. I cannot get the codebehind to find the Control, no matter how many different ways I try. I really need to be able to show the TEXT field which is associated with the dsPicklist SqlDataSource. I have marked the code that is causing problems. I would really appreciate some help in trying to display this information.

<asp:Label ID="Label1" runat="server" Text="Select Survey:"></asp:Label>

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
    DataSourceID="dsSurvey" DataTextField="SurveyName" DataValueField="SurveyID">
</asp:DropDownList>

<asp:DetailsView ID="dvSurveyQuestions" runat="server" AllowPaging="True" 
AutoGenerateRows="False" CellPadding="4" DataKeyNames="QuestionID" 
DataSourceID="dsSurveyQuestions" ForeColor="#333333" GridLines="None" Height="50px" 
Width="100%">
<Fields>
    <asp:BoundField DataField="QuestionNum" HeaderText="Question Number" 
        SortExpression="QuestionNum" />

    **<asp:TemplateField>
        <ItemTemplate>
            <asp:HiddenField ID="hiddenQuestionID" runat="server" 
            Value='<%# Bind("QuestionID") %>'>
            </asp:HiddenField>
        </ItemTemplate>
    </asp:TemplateField>**

    <asp:TemplateField HeaderText="Question Type" SortExpression="QType">
        <EditItemTemplate>
            <asp:DropDownList ID="DropDownList4" runat="server" 
                SelectedValue='<%# Bind("QType") %>'>
                <asp:ListItem Value="Picklist">Picklist</asp:ListItem>
                <asp:ListItem Value="Text">Text</asp:ListItem>
            </asp:DropDownList>
        </EditItemTemplate>
        <InsertItemTemplate>
            <asp:DropDownList ID="DropDownList5" runat="server" 
                SelectedValue='<%# Bind("QType") %>'>
                <asp:ListItem Value="Picklist">Picklist</asp:ListItem>
                <asp:ListItem Value="Text">Text</asp:ListItem>
            </asp:DropDownList>
        </InsertItemTemplate>
        <ItemTemplate>
            <asp:Label ID="lblQType" runat="server" Text='<%# Bind("QType") %>'>
            </asp:Label>
        </ItemTemplate>
    </asp:TemplateField>

    <asp:TemplateField HeaderText="Question" SortExpression="Question">
        <EditItemTemplate>
            <asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" 
            Text='<%# Bind("Question") %>'>
            </asp:TextBox>
        </EditItemTemplate>
        <InsertItemTemplate>
            <asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" 
            Text='<%# Bind("Question") %>'>
            </asp:TextBox>
        </InsertItemTemplate>
        <ItemTemplate>
            <asp:Label ID="lblQuestion" runat="server" Text='<%# Bind("Question") %>'>    
            </asp:Label>
        </ItemTemplate>
    </asp:TemplateField>

    <asp:TemplateField HeaderText="Answer" SortExpression="PicklistID">
        <EditItemTemplate>
        <!-- put something here after ItemTemplate testing -->
        </EditItemTemplate>
        <InsertItemTemplate>
        <!-- put something here after ItemTemplate testing -->
        </InsertItemTemplate>
        <ItemTemplate>
            <asp:HiddenField ID="hiddenPicklistID" runat="server"  
            Value='<%# Bind("PicklistID") %>' />
            <asp:BulletedList ID="blText" runat="server" DataSourceID="dsPicklist" 
            DataTextField="TEXT">
            </asp:BulletedList>
        </ItemTemplate>
    </asp:TemplateField>

    <asp:TemplateField HeaderText="Answer Type" SortExpression="AnswerType">
        <EditItemTemplate>
            <asp:DropDownList ID="DropDownList2" runat="server" 
                SelectedValue='<%# Bind("AnswerType") %>'>
                <asp:ListItem Value="S">Single Choice (radio button)</asp:ListItem>
                <asp:ListItem Value="M">Multiple Choices (checkboxes)</asp:ListItem>
                <asp:ListItem Value="T">Text (textbox)</asp:ListItem>
            </asp:DropDownList>
        </EditItemTemplate>
        <InsertItemTemplate>
            <asp:DropDownList ID="DropDownList3" runat="server" 
                SelectedValue='<%# Bind("AnswerType") %>'>
                <asp:ListItem Value="S">Single Choice (radio button)</asp:ListItem>
                <asp:ListItem Value="M">Multiple Choices (checkboxes)</asp:ListItem>
                <asp:ListItem Value="T">Text (textbox)</asp:ListItem>
            </asp:DropDownList>
        </InsertItemTemplate>
        <ItemTemplate>
            <asp:Label ID="lblAnswerType" runat="server" Text='<%# Bind("AnswerType") %>'></asp:Label>
        </ItemTemplate>
    </asp:TemplateField>

    <asp:BoundField DataField="Subsequence" HeaderText="Subsequence" 
        SortExpression="Subsequence" />
    <asp:CheckBoxField DataField="Active" HeaderText="Active" 
            SortExpression="Active" />
    <asp:CheckBoxField DataField="Question_Locked" HeaderText="Question Locked" 
            SortExpression="Question_Locked" />
    <asp:BoundField DataField="QHelp" HeaderText="Question Help" SortExpression="QHelp" />
    <asp:BoundField DataField="Script" HeaderText="Script" 
        SortExpression="Script" />
    <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" 
        ShowInsertButton="True" />
    </Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="dsPicklist" runat="server" 
    ConnectionString="<%$ ConnectionStrings:SurveyConnectionString %>" 
    SelectCommand="SELECT p.TEXT 
                   FROM PICKLIST p 
                   JOIN C_Survey_Questions c 
                   ON p.PICKLISTID = c.PicklistID 
                   AND c.QuestionID = @QuestionID 
                   AND c.SurveyID = @SurveyID 
                   WHERE p.PICKLISTID IS NOT NULL 
                   AND c.PicklistID IS NOT NULL">
    <SelectParameters>
        <asp:ControlParameter ControlID="DropDownList1" Name="SurveyID" 
            PropertyName="SelectedValue" Type="Int32" />
        **<asp:ControlParameter ControlID="hiddenQuestionID" Name="QuestionID" 
            PropertyName="SelectedValue" Type="Int32" />**
    </SelectParameters>
</asp:SqlDataSource>

<asp:SqlDataSource ID="dsSurvey" runat="server" 
    ConnectionString="<%$ ConnectionStrings:SurveyConnectionString %>" 
    SelectCommand="SELECT [SurveyID], [SurveyName] 
                   FROM [C_Survey] 
                   ORDER BY [SurveyName]">
</asp:SqlDataSource>

<asp:SqlDataSource ID="dsSurveyQuestions" runat="server" 
    ConnectionString="<%$ ConnectionStrings:SurveyConnectionString %>" 
    DeleteCommand="DELETE FROM [C_Survey_Questions] WHERE [QuestionID] = @QuestionID" 
    InsertCommand="INSERT INTO [C_Survey_Questions] ([SurveyID], [Question], [QType],
                   [PickListID], [QuestionNum], [Subsequence], [Active], [Script], 
                   [Question_Locked], [QHelp], [Createdate], [Modifydate],
                   [AnswerType]) 
                   VALUES (@SurveyID, @Question, @QType, @PickListID, @QuestionNum, 
                   @Subsequence, @Active, @Script, @Question_Locked, @QHelp, getdate(), 
                   getdate(), @AnswerType)" 
    SelectCommand="SELECT * FROM C_Survey_Questions WHERE SurveyID = @SurveyID" 
    UpdateCommand="UPDATE [C_Survey_Questions] 
                   SET [SurveyID] = @SurveyID, [Question] = @Question,
                   [QType] = @QType, [PickListID] = @PickListID, 
                   [QuestionNum] = @QuestionNum, [Subsequence] = @Subsequence, 
                   [Active] = @Active, [Script] = @Script, 
                   [Question_Locked] = @Question_Locked, 
                   [QHelp] = @QHelp, [Modifydate] = getdate(), 
                   [AnswerType] = @AnswerType WHERE [QuestionID] = @QuestionID">
    <DeleteParameters>
        <asp:Parameter Name="QuestionID" Type="Int32" />
    </DeleteParameters>
    <InsertParameters>
        <asp:Parameter Name="SurveyID" Type="Int32" />
        <asp:Parameter Name="Question" Type="String" />
        <asp:Parameter Name="QType" Type="String" />
        <asp:Parameter Name="PickListID" Type="String" />
        <asp:Parameter Name="QuestionNum" Type="Int32" />
        <asp:Parameter Name="Subsequence" Type="Int32" />
        <asp:Parameter Name="Active" Type="Boolean" />
        <asp:Parameter Name="Script" Type="String" />
        <asp:Parameter Name="Question_Locked" Type="Boolean" />
        <asp:Parameter Name="QHelp" Type="String" />
        <asp:Parameter Name="Createdate" Type="DateTime" />
        <asp:Parameter Name="Modifydate" Type="DateTime" />
        <asp:Parameter Name="AnswerType" Type="String" />
    </InsertParameters>
    <SelectParameters>
        <asp:ControlParameter ControlID="DropDownList1" Name="SurveyID" 
            PropertyName="SelectedValue" Type="Int32" />
    </SelectParameters>
    <UpdateParameters>
        <asp:Parameter Name="SurveyID" Type="Int32" />
        <asp:Parameter Name="Question" Type="String" />
        <asp:Parameter Name="QType" Type="String" />
        <asp:Parameter Name="PickListID" Type="String" />
        <asp:Parameter Name="QuestionNum" Type="Int32" />
        <asp:Parameter Name="Subsequence" Type="Int32" />
        <asp:Parameter Name="Active" Type="Boolean" />
        <asp:Parameter Name="Script" Type="String" />
        <asp:Parameter Name="Question_Locked" Type="Boolean" />
        <asp:Parameter Name="QHelp" Type="String" />
        <asp:Parameter Name="Modifydate" Type="DateTime" />
        <asp:Parameter Name="AnswerType" Type="String" />
    </UpdateParameters>
</asp:SqlDataSource>




Protected Sub dvSurveyQuestions_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertEventArgs) Handles dvSurveyQuestions.ItemInserting
    'The DetailsView does not include SurveyID column...we need to set this column during INSERT operations because each question must belong to some survey.
    e.Values("SurveyID") = DropDownList1.SelectedValue
End Sub
Protected Sub dvSurveyQuestions_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdateEventArgs) Handles dvSurveyQuestions.ItemUpdating
    'The DetailsView does not include SurveyID column...we need to set this column during UPDATE operations because each question must belong to some survey.
    e.NewValues("SurveyID") = DropDownList1.SelectedValue
End Sub
Protected Sub dvSurveyQuestions_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles dvSurveyQuestions.DataBound
    'The event handler checks the row count of the DetailsView control. If it is zero then the mode of the DetailsView is changed to Insert using ChangeMode() method.
    If dvSurveyQuestions.Rows.Count = 0 Then
        dvSurveyQuestions.ChangeMode(DetailsViewMode.Insert)
    End If
    If dvSurveyQuestions.CurrentMode = DetailsViewMode.[ReadOnly] Then
        Dim txtName As TextBox = DirectCast(Page.Form.FindControl("dvSurveyQuestions:hiddenQuestionID"), TextBox)
    End If
End Sub
End Class
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T18:52:22+00:00Added an answer on May 28, 2026 at 6:52 pm

    Try this:

    Dim txtName = DirectCast(dvSurveyQuestions.FindControl("hiddenQuestionID"), TextBox) 
    

    Since the NamingContainer of the TextBox is the DetailsView not the Page.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My page has a form that has a text field in it. I'd like
Page has menu items that would replace a 'div id=foo_(current menu item)' with 'div
My page has 3 divs that are located horizontally. I need to make the
Page has image with hyperlink and that hyperlink has target=_blank and every time i
I need to build a web page with a DetailsView which has a bunch
my page has 2 jqgrids 1) jQuery(#gridmain).jqGrid({.... 2) jQuery(#gridsub).jqGrid({.... I read that to make
My page has this extra padding on the top of page that I'm unable
I have a aspx page that has a GridView with a datasource of an
This page has a simple alert: alert(185.3 + 12.37); To me, that should equal
My page has several items (divs) that are draggable and resizable. My code for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.