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
I am attaching a sample that does a similar functionality, with the check boxes displayed in the header.
In the sample provided I am creatimg to templated columns and assigning checkboxes at the header. In the InitilaizeLayout event I am checking/unchecking the CheckBoxes at the header according to the values in the first row using the following code snippet:
if (e.Row.Index == 0) { e.Row.Hidden = true;
foreach (UltraGridCell cell in e.Row.Cells) { TemplatedColumn tc = cell.Column as TemplatedColumn; HeaderItem item = tc.HeaderItem as HeaderItem; CheckBox checkbox1 = item.Controls[1] as CheckBox;
checkbox1.Checked = ((int) cell.Value) != 0; }
}
On the client side I attached an event when the checkbox is fired. First I check the column that was checked, and I get the first row in the Grid and I assign it the value using the following code snippet:
function HeaderCheckedChanged(sender){ var grid = igtbl_getGridById("<%= UltraWebGrid1.ClientID %>"); var column = igtbl_getColumnById(sender.parentElement.id);
if (column == null) { alert("Debugging: Column is null"); return; } var index = column.Index; myrow = gridID.Rows.getRow(0);var cell_value = myrow.getCell(index).getValue();
if((cell_value) == 0) { myrow.getCell(index).setValue(1); } else myrow.getCell(index).setValue(0);
Magued
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...
Any chance you can elaborate a little on this? Maybe an example?
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...