-1

私は以下のコードを持っています:

                <%for (int index = 1; index < 7; ++index) {%>
                    <tr>
                        <td>
                            <div class="indicacao_gdp">
                                <asp:TextBox ReadOnly="true" ID="inp_txt_indicacao_<%= index %>" CssClass="inp_txt_indicacao" runat="server" MaxLength="12"></asp:TextBox>
                            </div>
                        </td>
                        <td>
                            <div class="codigo_debito_credito_gdp">
                                <asp:TextBox ReadOnly="true" ID="inp_txt_codigo_debito_credito_<%= index %>" CssClass="inp_txt_codigo_debito_credito" runat="server" MaxLength="2"></asp:TextBox>
                            </div>
                        </td>
                        <td>
                            <div class="descricao_debito_credito_gdp">
                                <asp:TextBox ReadOnly="true" ID="inp_txt_descricao_debito_credito_<%= index %>" CssClass="inp_txt_descricao_debito_credito" runat="server" MaxLength="2"></asp:TextBox>
                            </div>
                        </td>
                        <td>
                            <div class="valor_debito_credito_gdp">
                                <asp:TextBox ReadOnly="true" ID="inp_txt_valor_debito_credito_inteiro_<%= index %>" CssClass="inp_txt_valor_inteiro" runat="server" MaxLength="8"></asp:TextBox>
                                ,
                                <asp:TextBox ReadOnly="true" ID="inp_txt_valor_debito_credito_decimal_<%= index %>" CssClass="inp_txt_valor_decimal" runat="server" MaxLength="2"></asp:TextBox>
                            </div>
                        </td>
                    </tr>
                <%}%>

しかし、コードが機能しません...

Parser Error Message: 'inp_txt_indicacao_<%= index %>' is not a valid identifier.

どのように解決しましたか?

4

3 に答える 3

0

runat="server" を使用すると、実際の html ではなく .net オブジェクトが作成されます。

2 つのオプションがあります。Repeater を使用し、ID を ID="inp_txt_indicacao" に設定できます (.net が一意にします)

または、 <asp:TextBox を使用する代わりに、定期的に配置します

<input type="textbox" id="inp_txt_indicacao_<%= index %>" />

リピータ

オンラインには多くの優れたチュートリアルがありますが、ここでは簡単に理解できます。

リピーターを使用するには、データを何らかのリストに入れる必要があります。

Public Class TestClass

    Public Sub New(ByVal v1 As String, ByVal v2 As String)

        Value1 = v1
        Value2 = v2

    End Sub

    Public Property Value1() As String
    Public Property Value2() As String

End Class

    Dim tc As New List(Of TestClass)

    tc.Add(New TestClass("aa", "bb"))
    tc.Add(New TestClass("cc", "dd"))
    tc.Add(New TestClass("ee", "ff"))

データをリピーターにバインドするだけです

    rpData.DataSource = tc
    rpData.DataBind()


    <asp:Repeater ID="rpData" runat="server">
    <HeaderTemplate>
        <table>
        <tr>
            <th>Header 1</th>
            <th>Header 2</th>
        </tr>
    </HeaderTemplate>
    <ItemTemplate>
        <tr>
            <td><asp:TextBox ID="txtValue1" Text='<%# Bind("Value1") %>' runat="server" /></td>
            <td><asp:TextBox ID="txtValue2" Text='<%# Bind("Value2") %>' runat="server" /></td>
        </tr>
    </ItemTemplate>
    <FooterTemplate>
        </table>
    </FooterTemplate>
    </asp:Repeater>
于 2013-08-15T19:42:40.540 に答える