• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1228
  • Last Modified:

How align text of checkboxlist control in ASP.Net?

I want text in my checkbox list to align right to the checkbox. Somehow it is not align to the right, it is being displayed in the bottom, did i miss something?
----------------
<asp:CheckBoxlist ID="chkLst" runat="server" TextAlign="Right"
      AutoPostBack="True" ></asp:CheckBoxlist>
-----------------
I am populating my list items programmatically from the dataset
-----------------
Dim Row As DataRow
            If Not DS Is Nothing Then
                  If DS.Tables.Count > 0 Then
                        If DS.Tables(0).Rows.Count > 0 Then
                              For Each Row In DS.Tables(0).Rows
                                    Dim li As New ListItem()
                                    li.Text = Row("NAME").ToString.Trim
                                    chkLst.Items.Add(li)
                                    chkLst.TextAlign = TextAlign.Right
                              Next
                        End If
                  End If
            End If
            DS.Dispose()
0
ASPNet_Learner
Asked:
ASPNet_Learner
3 Solutions
 
devlab2012Commented:
Check the width of container tag of <asp:CheckBoxList> i.e. tag like <td> or <div> which contains your checkboxlist.
0
 
ASPNet_LearnerAuthor Commented:
I added  Width="266px" for <asp:CheckBoxList> but still it is doing same
0
 
Rajar AhmedConsultantCommented:
please post d screen shot

do u want it like repeatcolumn or repeatdirection . ?

chkLst.RepeatColumns = 2
chkLst.RepeatDirection = RepeatDirection.Horizontal

Am not clear wit ur question ?


Does d below code works as expected to ur need try
n tel me d problm clearly?

Meeran03
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="checkboxalign.aspx.vb" Inherits="checkboxalign" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:CheckBoxlist ID="chkLst" runat="server"></asp:CheckBoxlist>
    </div>
    </form>
</body>
</html>
'Code Behind

Imports System.Data
Partial Class checkboxalign
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim dt As New DataTable()
        '-- Create datatable object
        Dim cl As New DataColumn("No")
        '-- Create column 'No'
        dt.Columns.Add(cl)
        '--Add 'No' Column in datatable 
        cl = New DataColumn("Name")
        '-- Create column 'Name'
        dt.Columns.Add(cl)
        '--Add 'Name' Column in datatable 

        '-- add first row in datatable
        Dim dr As DataRow = dt.NewRow()
        '-- get new row for datatable.
        dr(0) = 1
        '-- assign value for 'No' column
        dr(1) = "John"
        '-- assign value for 'Name' column
        dt.Rows.Add(dr)
        ' Add row in datatable
        '-- add second row in datatable
        dr = dt.NewRow()
        dr(0) = 2
        dr(1) = "Smith"
        dt.Rows.Add(dr)

        dr = dt.NewRow()
        dr(0) = 2
        dr(1) = "jack"
        dt.Rows.Add(dr)

        dr = dt.NewRow()
        dr(0) = 2
        dr(1) = "jimm"
        dt.Rows.Add(dr)

        dr = dt.NewRow()
        dr(0) = 2
        dr(1) = "jill"
        dt.Rows.Add(dr)

        Dim Row As DataRow
        chkLst.RepeatColumns = 2
        chkLst.RepeatDirection = RepeatDirection.Horizontal
        If Not dt Is Nothing Then
            If dt.Rows.Count > 0 Then
                For Each Row In dt.Rows
                    Dim li As New ListItem()
                    li.Text = Row("Name").ToString.Trim
                    chkLst.Items.Add(li)
                    chkLst.TextAlign = TextAlign.Right
                Next
            End If
        End If

    End Sub

End Class

Open in new window

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
ASPNet_LearnerAuthor Commented:
Data table is populated from a select SQL. Number of rows in the dataset may vary for me to use
chkLst.RepeatColumns = 2

0
 
ASPNet_LearnerAuthor Commented:
I already have the RepeaterDirection=Horizontal in the properties window of the checkboxlist.
0
 
mr_nadgerCommented:
have you set up any CSS?
0
 
ASPNet_LearnerAuthor Commented:
It was prob. with my CSS file, thank for the help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now