John
John

Reputation: 3945

asp.net center align checkbox

Attempting to center align a checkbox, which is displayed using a repeater for each record.

asp:Repeater id="rptSelected" runat="server">
<HeaderTemplate>
  <table class="detailstable FadeOutOnEdit">
    <tr>
      <th style="width:200px;">Contacted</th>
    </tr>
 </HeaderTemplate>

<ItemTemplate>
  <tr>
    <th style="width:200px;">
      <input type="checkbox" class="AlignCheckBox" name='<%# CallUtilityChangeId((int)Eval("CompanyId")) %>'
       <%# SetCheckboxValue((bool)Eval("Contacted"))%> />
    </th>
  </tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>

Using:

    .AlignCheckBox
{
    text-align: center;
}

but to no avail...any ideas?

thank ye

Upvotes: 1

Views: 7935

Answers (3)

Floremin
Floremin

Reputation: 4089

In the ItemTemplate, I think you want "td" tag instead of "th" ;) and add "text-align: center;" to the style attribute:

<ItemTemplate>
  <tr>
    <td style="width:200px; text-align: center;">
      <input type="checkbox" name='<%# CallUtilityChangeId((int)Eval("CompanyId")) %>'
      <%# SetCheckboxValue((bool)Eval("Contacted"))%> />
    </td>
  </tr>
</ItemTemplate>

Upvotes: 1

BinaryTox1n
BinaryTox1n

Reputation: 3556

The css you have there will center align the text within the textbox. In order to align the textbox itself, you need to use that same css but on the texbox's container.

A quick example would be:

th {
    text-align: center;
}

As for your exact code, you could get away with this:

<ItemTemplate>
  <tr>
    <th style="width:200px; text-align: center;">
      <input type="checkbox" class="AlignCheckBox" name='<%# CallUtilityChangeId((int)Eval("CompanyId")) %>'
       <%# SetCheckboxValue((bool)Eval("Contacted"))%> />
    </th>
  </tr>
</ItemTemplate>

Adding it to the style tag of your th.

Upvotes: 1

donstack
donstack

Reputation: 2715

apply center align on th of checkbox

Upvotes: 0

Related Questions