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 9000155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:16:29+00:00 2026-06-16T00:16:29+00:00

I have the following code in an ASP.NET datagrid: <asp:TemplateField HeaderText= Visible=True > <ItemTemplate>

  • 0

I have the following code in an ASP.NET datagrid:

<asp:TemplateField HeaderText="" Visible="True" >
                            <ItemTemplate>
                            <%--<asp:TextBox ID="txtAnswer" Text='<%# Bind("Answer") %>' runat="server" 
                                       TextMode="MultiLine" Height="76px" MaxLength="2000" Width="377px"  >
                            </asp:TextBox>--%>
                            <asp:HiddenField ID="hfQuestionID" Value='<%# Bind("QuestionID") %>' runat="server" />
                            <asp:HiddenField ID="hfAnswerID" Value='<%# Bind("AnswerID") %>' runat="server" />
                            <asp:HiddenField ID="hfAnswer" Value='<%# Bind("Answer") %>' runat="server" />
                            <asp:PlaceHolder ID="ph1" runat="server" />
                            <%--<%# GetAnswerControl(DataBinder.Eval(Container.DataItem,"QuestionID").ToString(), 
                                DataBinder.Eval(Container.DataItem,"Answer").ToString()) %>--%>
                            </ItemTemplate>
                           <EditItemTemplate>
                            <asp:HiddenField ID="hfQuestionID" Value='<%# Bind("QuestionID") %>' runat="server" />
                            <asp:HiddenField ID="hfAnswerID" Value='<%# Bind("AnswerID") %>' runat="server" />
                            <asp:HiddenField ID="hfAnswer" Value='<%# Bind("Answer") %>' runat="server" />
                            <asp:PlaceHolder ID="ph1" runat="server" />
                               <%--<asp:TextBox ID="txtAnswer" Text='<%# Bind("Answer") %>' runat="server" 
                                       TextMode="MultiLine" Height="76px" MaxLength="2000" Width="377px"  ></asp:TextBox>--%>
                           </EditItemTemplate>
                         </asp:TemplateField>

The placeholder is dynamically populated with either a textbox or a dropdownlist depending on the type of answer the user needs to give. The code to render the initial answer fields (textbox or dropdown) works fine.

However, when I fire my button click event, the controls property of the placeholder is always empty. Why is this happening? I’ve been wracking my brain for days over this and it doesn’t make any sense to me.

A snippet where I’m trying to access the datagrid’s dynamically added controls follows…what am I doing wrong?

foreach (GridViewRow r in gridUserSupplierTypeQuestionsAndAnswers.Rows)
        //if (IsRowModified(r))
        //{
        //    gridUserSupplierTypeQuestionsAndAnswers.UpdateRow(r.RowIndex, false);
        //}
        {
            PlaceHolder ph =(PlaceHolder) r.FindControl("ph1");
            Control c = ph.FindControl("Answer");
            string answer = string.Empty;
            if(c.GetType() == typeof(TextBox))
            {
                TextBox tb = (TextBox) c;
                answer = tb.Text;
            }
            else if (c.GetType() == typeof(DropDownList))
            {
                DropDownList dl = (DropDownList)c;
                answer = dl.SelectedValue;
            }
  • 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-06-16T00:16:30+00:00Added an answer on June 16, 2026 at 12:16 am

    I wound up abandoning the placeholder and instead went with two controls – a textbox and a dropdownlist – with their visibility set to false.

    I store the answer type in the database, and depending on that value turn the appropriate control on through a helper function. There are probably more elegant ways to handle this, but I’m tight on time and just need to get this working.

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

Sidebar

Related Questions

I am using the followng code to bind to an ASP.NET DataGrid. I have
I have the following code in the codebehind file of an ASP.Net page txtStartDate.Text
In asp.net website, inside .aspx i have following code <script type=text/javascript> function callme(option) {
I have the following code in an Asp.Net user control: Me.pnlAddComment.Visible = MyBase.Associate.IsAgent() Me.lblRating.Visible
Anything I have tried didn't work. Currenly I have following code to change asp.net
I have the following code in my ASP.NET project public sealed class IoC {
i have the following code in an asp.net mvc view. <% = Html.DropDownList(Filter, new
I have the following code in a ASP.NET master page: <div id=hyperlinkimage><asp:HyperLink ID=SomeHyperLink runat=Server
I have following asp.net code but it gives error when I change dropdown selected
I am using ASP.NET 3.5 with iTextSharp and I have the following code: var

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.