Home > DeveloperSection > Forums > Bind ID dynamically on a textbox
Kamlakar Singh
Kamlakar Singh

Total Post:28

Points:196
Posted on    December-11-2014 10:31 PM

 ASP.Net C# 
Ratings:


 2 Reply(s)
 708  View(s)
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.



ezra heywood
ezra heywood

Total Post:145

Points:1019
Posted on    December-12-2014 6:07 AM

try this

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

OR

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


Takeshi Okada
Takeshi Okada

Total Post:89

Points:629
Posted on    December-12-2014 6:52 AM

<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>


Don't want to miss updates? Please click the below button!

Follow MindStick