Here is some code that would be useful for reports where your user would like to choose the columns of the datagrid that he or she wants to see.
I use a checkboxlist with a checkbox for each column of my datagrid. The checkboxes are created on the fly in the pageload event. There is also a button at the end that triggers the event.
CheckBoxList
'******************************************
Select data you would like to view
<asp:checkboxlist id="check1" runat="server" RepeatDirection="Horizontal"
</asp:checkboxlist>
Finally I have the button's click event behind the page. The commented out lines of code will let you set specific column size. If you do not uncomment these lines of code, the columns will shrink to whatever the longest value's length in the column is. Setting the column width makes reports look a lot cleaner, but if you are pressed for space then just leave those lines commented.
'******************************************
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim i As Integer
'Dim columnwidth As Integer = 100
Dim maxcolumns As Integer = check1.Items.Count
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.