Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How align text of checkboxlist control in ASP.Net?

Posted on 2011-04-25
7
Medium Priority
?
1,221 Views
Last Modified: 2012-05-11
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
Comment
Question by:ASPNet_Learner
7 Comments
 
LVL 13

Accepted Solution

by:
devlab2012 earned 668 total points
ID: 35459977
Check the width of container tag of <asp:CheckBoxList> i.e. tag like <td> or <div> which contains your checkboxlist.
0
 

Author Comment

by:ASPNet_Learner
ID: 35460080
I added  Width="266px" for <asp:CheckBoxList> but still it is doing same
0
 
LVL 18

Assisted Solution

by:Rajar Ahmed
Rajar Ahmed earned 664 total points
ID: 35460253
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

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

0
 

Author Comment

by:ASPNet_Learner
ID: 35461871
I already have the RepeaterDirection=Horizontal in the properties window of the checkboxlist.
0
 
LVL 7

Assisted Solution

by:mr_nadger
mr_nadger earned 668 total points
ID: 35465408
have you set up any CSS?
0
 

Author Closing Comment

by:ASPNet_Learner
ID: 35470139
It was prob. with my CSS file, thank for the help.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question