BIND ID DYNAMICALLY ON A TEXTBOX

Mark M

Total Post:28

Points:196
Posted by  Mark M
C# 
 1082  View(s)
Ratings:
Rate this:

I have

<asp:TextBox ID="txtBidAmmount<%#Eval("id") %>" Width="250" runat="server"></asp:TextBox>

That wouldn't work and I have read some options that I have to replace the " with ', so I did:

<asp:TextBox ID='txtBidAmmount<%#Eval("id") %>' Width="250" runat="server"></asp:TextBox>

But I get:

Parser Error Message: 'txtBidAmmount<%#Eval("id") %>' is not a valid identifier.

  1. ezra heywood

    Post:145

    Points:1019
    Re: Bind ID dynamically on a textbox

    try this

    ID='<%# "txtBidAmmount" + eval("id") %>'

    OR

    ID='<%# Eval("id", "txtBidAmmount {0}") %>'

  1. Takeshi Okada

    Post:89

    Points:629
    Re: Bind ID dynamically on a textbox

    <asp:GridView ID="EmployeesNoSuffix" runat="server"

        AutoGenerateColumns="false" ClientIDMode="Predictable">

    <Columns>

        <asp:TemplateField HeaderText="ID">

             <ItemTemplate>

                  <asp:Label ID="EmployeeID" runat="server" Text='<%# Eval("ID") %>' />

             </ItemTemplate>

        </asp:TemplateField>

        <asp:TemplateField HeaderText="Name">

             <ItemTemplate>

                  <asp:Label ID="EmployeeName"

            runat="server" Text='<%# Eval("Name") %>' />

             </ItemTemplate>

        </asp:TemplateField>

    </Columns>

    </asp:GridView>

    Output HTML

     

    <table id="EmployeesNoSuffix" style="border-collapse: collapse"

        cellspacing="0" rules="all" border="1">

      <tbody>

        <tr>

           <th scope="col">ID</th>

           <th scope="col">Name</th>

        </tr>

        <tr>

           <td><span id="EmployeesNoSuffix_EmployeeID_0">1</span></td>

           <td><span id="EmployeesNoSuffix_EmployeeName_0">EmployeeName1</span></td>

        </tr>

        ...

        <tr>

          <td>

             <span id="EmployeesNoSuffix_EmployeeID_8">9</span>

          </td>

          <td>

             <span id="EmployeesNoSuffix_EmployeeName_8">EmployeeName9</span>

          </td>

        </tr>

      </tbody>

    </table>

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!