Hello,
I have a grid that has columns of data. The first row of each column is a boolean. I would like to display that row as checkboxes to permit a user to check or uncheck that particular box.
Help!
Thanks,
Michael
You might want to use TemplateColumns and in the first row, display a checkbox and for all rows after that display data. You can use the events for each row to set this up...
Any chance you can elaborate a little on this? Maybe an example?
sure! hopefully this can help...i've ripped it out of some code where i am doing a similar thing...
in the .aspx file...set up the template columns...you'll need to do this for all of them etc
<igtbl:UltraWebGrid ID="uwg_myGrid" runat="server"> <Bands> <igtbl:UltraGridBand> <AddNewRow View="NotSet" Visible="NotSet"> </AddNewRow> <Columns> <igtbl:TemplatedColumn Key="COLUMN_1"> <Header Caption="First Name"> </Header> <CellTemplate> <asp:CheckBox ID="chk_value" runat="server" /> <asp:Literal ID="lit_value" runat="server" /> </CellTemplate> </igtbl:TemplatedColumn> </Columns> </igtbl:UltraGridBand> </Bands> <DisplayLayout ...........
Now in the code behind (.vb in my case):
Protected Sub uwg_myGrid_InitializeRow(ByVal sender As Object, ByVal e As RowEventArgs) Handles uwg_myGrid.InitializeRow With e.Row ' Get references to the template cells ' checkbox and literal controls Dim column As TemplatedColumn = CType(.Cells.FromKey("COLUMN_1").Column, TemplatedColumn) Dim cellItem As CellItem = CType(column.CellItems(e.Row.Index), CellItem) Dim chk_value As CheckBox = CType(cellItem.FindControl("chk_value"), CheckBox) Dim lit_value As Literal = CType(cellItem.FindControl("lit_value"), Literal)
If e.Row.Index = 0 Then
// first row chk_value.checked = True ' or whatever is meant to be here // attach a javascript event perhaps? // just need to pass the function some useful information to identify the cell and // whether the checkbox is checked...i haven't tested this...it just looks neat! // chk_value.attributes.add("onclick","chk_value_onclick(" + celIndex + ",this.checked)"
Else
// all other rows if myValue is dbull.value then lit_value.text = " " else lit_value.text = myValue end if
End If
End With
End Sub
brief explanation- set up the template columns that you will display in the aspx code- bind a dataset as you would which has the real values for each column for indexes 1+ and then hide these columns in the initialiseLayout event- populate the literal control and checkbox control in the template column with the correct data from the hidden columns- you will need to get references to each columns controls etc the example only shows one...
hopefully that helps...