locked
Problem with setting value for Request.Form[myControlName]. RRS feed

  • Question

  • User-79977429 posted

    Hi

    In my aspx, i've used this code :

    <select id="cmbMedicalCategorization" name="cmbMedicalCategorization" class="txtsamedev">
                    <asp:Repeater ID="RepeaterMedicalCategorization" runat="server">
                        <ItemTemplate>
                            <option value="<%#Eval("MedicalCategorizationID")%>"><%#Eval("MedicalCategorizationName")%></option>
                        </ItemTemplate>
                    </asp:Repeater>
                </select>

    And can be access (for read data) easily via this code :

    curServiceRow.MedicalCategorizationID = Convert.ToInt32(Request.Form["cmbMedicalCategorization"].ToString());

    but i can not set value on this, because as you see, it is container for repeater control and can not add runAt"Server" property, because i'm facing this error :

    System.Web.HttpException: 'HtmlSelect' cannot have children of type 'Repeater

    Can anybody help me how to set value for this type of control(s) ?

    Thanks in advance.

    Sunday, June 2, 2019 4:12 PM

All replies

  • User475983607 posted

    I recommend that you use the standard DropDownList server control.   The server control has everything needed to work with the HTML select.

    Otherwise; you'll need to set the "selected" attribute of the option element within the repeater.

    https://www.w3schools.com/tags/att_option_selected.asp

    Sunday, June 2, 2019 8:14 PM
  • User409696431 posted

    Why are you trying to put a repeater inside a select?  Please explain the problem you are trying to solve with that design.

    Sunday, June 2, 2019 8:16 PM
  • User839733648 posted

    Hi hamed_1983,

    According to your description and code, I‘ve tested it and it really works well.

    but i can not set value on this,

    But I'd like to ask that what value you want to set on?

    Do you mean that you want to set the value to the options?

    If it is, I suggest that you could use asp:Dropdownlist instead of the select option tag.

    You could use this control to bind and set the value you want.

    Best Regards,

    Jenfier

    Monday, June 3, 2019 7:30 AM
  • User61956409 posted

    Hi hamed_1983,

    And can be access (for read data) easily via this code :

    curServiceRow.MedicalCategorizationID = Convert.ToInt32(Request.Form["cmbMedicalCategorization"].ToString());

    but i can not set value on this

    I'd like to confirm following information with you:

    • would you like to set selected value for your html <select> element from code behind?
    • as others mentioned, if you'd like to bind/populate drop down with your data source, why not use asp:DropDownList control?

    Example

    <asp:DropDownList ID="ddl_cmbMedicalCategorization" runat="server"></asp:DropDownList>

    Code behind

    ddl_cmbMedicalCategorization.DataValueField = "MedicalCategorizationID";
    ddl_cmbMedicalCategorization.DataTextField = "MedicalCategorizationName";
    ddl_cmbMedicalCategorization.DataSource = dt;
    ddl_cmbMedicalCategorization.DataBind();

    With Regards,

    Fei Han

    Tuesday, June 4, 2019 3:05 AM