Search code examples
asp.netwebformscheckboxlist

Can I add a THEAD and other columns to a checkboxlist


I am new to C#. I am trying to add a Thead section to the table that a checkboxlist generates so I can use Datatables plugin from https://datatables.net/ to format My table. Also is there a way to add other columns to the table it generates?

<form id="form1" runat="server">
          <div id="alertMessage" runat="server"></div>
                <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="True" Visible="True" PrintMode="Pdf" GroupTreeStyle-ShowLines="False" ReuseParameterValuesOnRefresh="False" HasRefreshButton="True" /> 

<asp:CheckBoxList ID="CheckBoxList1" runat="server"  CssClass="table table-bordered" DataValueField="order_no" DataTextField="order_no" AppendDataBoundItems="false" DataSourceID="OrderQuery" >
            <asp:ListItem></asp:ListItem>
                </asp:CheckBoxList>
        <asp:SqlDataSource ID="OrderQuery" runat="server"
            ConnectionString="<%$ ConnectionStrings:002ConnectionString %>"
            SelectCommand="spOrderDetailsPrint" SelectCommandType="StoredProcedure"></asp:SqlDataSource>

        <asp:Button ID="Button1" runat="server" Text="Print" OnClick="Button_1Click" />


    <div>

    </div>


    </form>  

Solution

  • Basically you are asking two questions in one: How to render THEAD in your view and how to add more columns.

    On this point I strongly suggest you to use a GridView, because you want more columns in your table. You could display a checkbox in the first column, a text in the second column and even more information in other columns.

    A GridView also allows you to enable the rendering of a THEAD section very easy so you can use your datatables component, though the GridView already comes with the same opportunity. The major difference is, it will only change pages via postback and won't allow you to change the count of the rows you see, interactively.