Infragistics Community Forum / Web / Ignite UI for ASP.NET Core / Insert check all/Uncheck all checkbox in template column header at Runtime
Insert check all/Uncheck all checkbox in template column header at Runtime
New DiscussionHi,
I have created a column at runtime that I need to be able to modify and add a checkbox in the header. This checkbox should enable the user to select all / unselect all items in the ultrawebgrid. If anyone knows please tell me how I can add this checkbox to the header at runtime and make this happen. I tried doing
Dim CheckAll As New CheckBox
column.HeaderItem.TemplateControl.Controls.Add(CheckAll)
but this did not work. I have to create this at Runtime since the column is also created in Runtime, all examples I found so far show how to do this in design. Any help is greatly appreciated
Replies
-
0
Hello,
Alright so to do this we need to add the checkbox to the header template before the column is even created… so before I assigned the datasource property of the grid I needed to setup the template column. <In the snippet you added I am guessing you did that in the InitializeLayout event handler or after you've set the DataSource and called DataBind and that is too late to hook items into the HeaderTemplate, do it in the Page's OnInit instead.>
So here's the code to do that column setup:
C#
protected
override void OnInit(EventArgs e)
{
base.OnInit(e);
// Create a templated column
TemplatedColumn col = new TemplatedColumn(true);
this.UltraWebGrid1.DisplayLayout.Bands[0].Columns.Add(col);
col.Key = "CheckBoxCol";
col.Header.Caption = "";
GridHeaderTemplate tempHeader = new GridHeaderTemplate();
// Set the header template.
col.HeaderTemplate = tempHeader;
this.UltraWebGrid1.DataSource = LoadGrid();
this.UltraWebGrid1.DataBind();
}
VB.NET
Protected Overrides Sub OnInit(ByVal e As EventArgs)
MyBase.OnInit(e)
' Create a templated column
Dim col As New TemplatedColumn(True)
Me.UltraWebGrid1.DisplayLayout.Bands(0).Columns.Add(col)
col.Key = "CheckBoxCol"
col.Header.Caption = ""
Dim tempHeader As New GridHeaderTemplate()
' Set the header template.
col.HeaderTemplate = tempHeader
Me.UltraWebGrid1.DataSource = LoadGrid()
Me.UltraWebGrid1.DataBind()
End SubSo now what does my GridHeaderTemplate look like:
C#
public
class GridHeaderTemplate : ITemplate
{
public void InstantiateIn(Control container)
{
// Cast the container to a HeaderItem
HeaderItem headerItem = (HeaderItem)container;
CheckBox checkBox = new CheckBox();
CheckBox cb = new CheckBox();
cb.ID = "headerCB";
cb.Attributes.Add("onclick", "HeaderCheckedChanged();");
headerItem.Controls.Add(cb);
}
}
VB.NET
Public Class GridHeaderTemplate
Implements ITemplate
Public Sub InstantiateIn(ByVal container As Control)
' Cast the container to a HeaderItem
Dim headerItem As HeaderItem = DirectCast(container, HeaderItem)
Dim checkBox As New CheckBox()
Dim cb As New CheckBox()
cb.ID = "headerCB"
cb.Attributes.Add("onclick", "HeaderCheckedChanged();")
headerItem.Controls.Add(cb)
End Sub
End ClassNext I setup the Cell Template dynamically in the WebGrid's InitializeLayout event handler:
C#
TemplatedColumn
col = (TemplatedColumn)(e.Layout.Bands[0].Columns.FromKey("CheckBoxCol"));
PlaceHolderTemplate tempCell = new PlaceHolderTemplate();
// Set the cell template.
col.CellTemplate = tempCell;
// make the checkbox the last column of band 0.
col.Move(e.Layout.Bands[0].Columns.Count – 1);
this.ClientScript.RegisterClientScriptBlock(this.GetType(), "CheckBoxKey", "<script type='text/javascript'>var headerCheckBoxID = '" + col.HeaderItem.FindControl("headerCB").ClientID + "';</script>");
this.ClientScript.RegisterClientScriptBlock(this.GetType(), "GridKey", "var gridID = '" + this.UltraWebGrid1.ClientID + "';", true);
VB.NET
Dim col As TemplatedColumn = DirectCast((e.Layout.Bands(0).Columns.FromKey("CheckBoxCol")), TemplatedColumn)
Dim tempCell As New PlaceHolderTemplate()
' Set the cell template.
col.CellTemplate = tempCell' make the checkbox the last column of band 0.
col.Move(e.Layout.Bands(0).Columns.Count – 1)Me.ClientScript.RegisterClientScriptBlock(Me.[GetType](), "CheckBoxKey", "<script type='text/javascript'>var headerCheckBoxID = '" + col.HeaderItem.FindControl("headerCB").ClientID + "';</script>")
Me.ClientScript.RegisterClientScriptBlock(Me.[GetType](), "GridKey", "var gridID = '" + Me.UltraWebGrid1.ClientID + "';", True)The PlaceHolderTemplate used for the Cell Template should be awfully familiar now that we've seen the header…
C#
public
class PlaceHolderTemplate : ITemplate
{
public void InstantiateIn(Control container)
{
// Cast the container to a CellItem
CellItem cellitem = (CellItem)container;
CheckBox cb = new CheckBox();
cb.ID = "cellCB";
cellitem.Controls.Add(cb);
}
}
VB.NET
Public Class PlaceHolderTemplate
Implements ITemplate
Public Sub InstantiateIn(ByVal container As Control)
' Cast the container to a CellItem
Dim cellitem As CellItem = DirectCast(container, CellItem)
Dim cb As New CheckBox()
cb.ID = "cellCB"
cellitem.Controls.Add(cb)
End Sub
End ClassNow I told the Header Checkbox to call a javascript function when its onclick fires… so here's the js I used to toggle the checkbox:
<
script type="text/javascript">
function HeaderCheckedChanged(){
var headerCheckBox = document.getElementById(headerCheckBoxID);
var grid = igtbl_getGridById(gridID);
for (i = 0; i < grid.Rows.length; i++)
{
grid.Rows.getRow(i).getCellFromKey("CheckBoxCol").getElement().children[0].checked = headerCheckBox.checked;
}
}
</script>
The javascript function can be written in several ways and accomplish the same task this is merely one way to accomplish this task.
Also as you can see in the code behind I registered a script block to render the grid's id to the client for use in my HeaderCheckedChanged function and I also threw the Header CheckBox's Id out to the client as well. You can use a stringbuilder and do this part a little neater but I think the point of what I've done to solve the task presented has been displayed in these code snippets.
What have others done in the past to solve this task?
EDIT: Updated code snippets to handle OnInit instead of Page_Load as page load was again too late in the Page's Lifecycle.
-
0
hi,
what I have done is added a CheckBox in template column header and called javascript function to check/uncheck all the checkboxes in the cell template this works fine, but I cant access checkboxes inside grid added in celltemplate. here is HTML and C# code which I am using.<Bands><igtbl:UltraGridBand>
<
AddNewRow Visible="NotSet" View="NotSet"></AddNewRow>
<
Columns>
<igtbl:TemplatedColumn Key="selectall" >
<Header Caption="Select" >
<RowLayoutColumnInfo OriginX="1" />
</Header>
<HeaderTemplate>
<asp:CheckBox ID="cbSelectAll" runat="server" onclick="BLOCKED SCRIPTcheckall()" />
<asp:Label ID="lbl_select" runat="server" Text="Select"></asp:Label>
</HeaderTemplate><CellTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" Value="False" />
</CellTemplate>
<CellStyle HorizontalAlign="Center" ></CellStyle>
<HeaderStyle HorizontalAlign="Center" />
<Footer>
<RowLayoutColumnInfo OriginX="1" />
</Footer>
</igtbl:TemplatedColumn>
<igtbl:UltraGridColumn BaseColumnName="Name" Key="Name" IsBound="True" >
<Header Caption="Name" ></Header>
</igtbl:UltraGridColumn>
</
Columns>
<RowTemplateStyle BackColor="Window" BorderColor="Window" BorderStyle="Ridge">
<BorderDetails WidthBottom="3px" WidthLeft="3px" WidthRight="3px" WidthTop="3px" />
</RowTemplateStyle>
<RowEditTemplate>
<br />
</RowEditTemplate>
</
igtbl:UltraGridBand></Bands>
and following is the scriptfunction checkall()
{
var frm = document.forms[0];for (i=0;i<frm.elements.length;i++)
{
if (frm.elements
.name.lastIndexOf("CheckBox1")!= -1) {
frm.elements
.checked = document.getElementById("UltraWebGrid1_ctl01_cbSelectAll").checked;//document.getElementById(id).checked;
}
}
}
and following is the code for checking which text boxes are checked or uncheked.for (int i = 0; i < UltraWebGrid1.Rows.Count; i++)
{
Response.Write(UltraWebGrid1.Rows
.Cells[0].Value);}
this code returns me always blank value though i have tick some of the checkboxes.
Plz help me.
Thanks.
-
0
Hi,
A few things first:
Try to avoid hard coding any ids in your script
[quote user="amol123"]
frm.elements
.checked = document.getElementById("UltraWebGrid1_ctl01_cbSelectAll").checked;//document.getElementById(id).checked;
[/quote]
instead render out the clientID to a global javascript variable for the page like I did here:
[quote user="mkraft"]
this.ClientScript.RegisterClientScriptBlock(this.GetType(), "CheckBoxKey", "<script type='text/javascript'>var headerCheckBoxID = '" + col.HeaderItem.FindControl("headerCB").ClientID + "';</script>");
this.ClientScript.RegisterClientScriptBlock(this.GetType(), "GridKey", "var gridID = '" + this.UltraWebGrid1.ClientID + "';", true);
[/quote]
so anywhere in the javascript I can reference the grid and the HeaderCheckBox. I've also seen others render an array of the id's of the checkboxes in the cells to the client in the same manner so they can just call document.getElementById(x) where "x" is the id from the array.
On the client I showed how to do access the checkbox in my HeaderCheckedChange function which looked like this:
[quote user="mkraft"]
<script type="text/javascript">
function HeaderCheckedChanged(){
var headerCheckBox = document.getElementById(headerCheckBoxID);
var grid = igtbl_getGridById(gridID);
for (i = 0; i < grid.Rows.length; i++)
{
grid.Rows.getRow(i).getCellFromKey("CheckBoxCol").getElement().children[0].checked = headerCheckBox.checked;
}
}
</script>
[/quote]
On the Server if you want access the CheckBox in the CellTemplate it would look like this:
//create a variable for the templated column in the WebGrid
TemplatedColumn templatedColumn = (TemplatedColumn) this.UltraWebGrid1.Columns.FromKey("TemplatedColumn");//get a cellitem reference in the cellitems collection
CellItem cellItem = (CellItem) templatedColumn.CellItems[myRowIndex];//find the control
Control cs = cellItem.FindControl("CheckBox1");//cast the control into the correct type
CheckBox myCheckBox = (CheckBox) cs;Now you have a reference to the CheckBox control that is in the cell… interrogate the value of the checked property or set it as you see fit.
-
0
Hi Matthew
Thank you very much for this article! It's one of the better articles i have ever read about how to solve something special with UltraWebGrid!
Hope to read more such articles from you Matthew, for example how to synchronize values from Controls in TempaltedColumns with the underlying DataSource as this doesn't work automatically (by my actual understanding of the things about TemplatedColumns).
Adrian
-
-
0
Mathew
When binding the second time.. one thing which I noticed is "InstantiateIn" of GridHeaderTemplate doesn't fire, because of which the checkbox is not getting added. Another thing is the reference to "col.HeaderItem.FindControl("headerCB").ClientID" is not available which again because the HeaderCB didn't get added. Any help?
Thanks
Saran
-
0
I'm using more or less the same code to create a checkbox in the CellItem instead of the Header. It works fine the first time it renders, but on post back the checkbox is no longer accessible when I iterate through the rows of the grid, and disappears when the page renders after the post back.
I put the code for inserting the checkbox in the OnInit event of the page, but it appears to behave the same as it did in OnLoad.
Is the checkbox not getting stored in the ViewState for the UltraWebGrid? If so, do I need to do something to ensure that it's state is maintained between post backs?
-
0
Hi Rumen
I moved the code that dynamically sets up the templated column to OnInit. I am still having the same problem. Following is the code I have written.
Imports System.Data
Imports Infragistics.WebUI.UltraWebGrid
Imports Infragistics.WebUI.UltraWebNavigatorPartial Class View_Edit_Surcharge
Inherits System.Web.UI.Page
Protected Overrides Sub OnInit(ByVal e As EventArgs)
MyBase.OnInit(e)If (Not IsPostBack()) Then
AddGridColumns()
End If
End SubProtected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If (Not IsPostBack()) Then
LoadData()
End If
End SubProtected Sub LoadData()
PopulateCustomerGridView()
End SubProtected Sub AddGridColumns()
' Create a templated columnDim col As New TemplatedColumn(True)
Me.UltraWebGrid1.DisplayLayout.Bands(0).Columns.Add(col)
col.Key = "Select"
col.Header.Caption = ""
Dim tempHeader As New GridHeaderTemplate()
' Set the header template.
col.HeaderTemplate = tempHeaderEnd Sub
Private Sub PopulateFilteredCustomerGridView(ByVal custName As String, ByVal type As String, ByVal grade As String)
Dim surchargeCustDs As DataSet = CType(Session.Item("surchargeCustDs"), DataSet)
Dim filteredDT As DataTable = CType(Session.Item("filteredDT"), DataTable)Dim whereClause As String = ""
Dim custNameClause As String = "1=1"
Dim typeClause As String = "1=1"
Dim gradeClause As String = "1=1"Try
If (custName <> "") Then
custNameClause = "CUSTOMER_NAME='" + custName + "'"
End If
If (type <> "") Then
typeClause = "charge_code='" + type + "'"
End If
If (grade <> "") Then
gradeClause = "AISIXXCODE='" + grade + "'"
End IfwhereClause = custNameClause + " And " + typeClause + " And " + gradeClause
filteredDT = surchargeCustDs.Tables(0).Clone
For Each tmpRow As DataRow In surchargeCustDs.Tables(0).Select(whereClause)
filteredDT.ImportRow(tmpRow)
Next
Session.Item("isBinding") = True
UltraWebGrid1.DataSource = filteredDT
UltraWebGrid1.DataBind()
Session.Item("isBinding") = False
Session.Item("filteredDT") = filteredDT
Catch ex As Exception
End Try
End SubPrivate Sub PopulateCustomerGridView()
Dim surchargeCustDs As DataSet = CType(Session.Item("surchargeCustDs"), DataSet)
Dim filteredDT As DataTable = CType(Session.Item("filteredDT"), DataTable)
Dim isRefreshed As Boolean = CType(Session.Item("isRefreshed"), Boolean)Try
If (surchargeCustDs Is Nothing Or isRefreshed) Then
surchargeCustDs = DataAccess.GetCustomerSurchargeDetails()
Session.Item("surchargeCustDs") = surchargeCustDs
Session.Item("isRefreshed") = False
End IffilteredDT = surchargeCustDs.Tables(0).Clone
For Each tmpRow As DataRow In surchargeCustDs.Tables(0).Rows
filteredDT.ImportRow(tmpRow)
Next
Session.Item("isBinding") = True
UltraWebGrid1.DataSource = filteredDT
UltraWebGrid1.DataBind()
Session.Item("isBinding") = False
Session.Item("filteredDT") = filteredDTCatch ex As Exception
End Try
End SubProtected Sub UltraWebTree1_NodeSelectionChanged(ByVal sender As Object, ByVal e As Infragistics.WebUI.UltraWebNavigator.WebTreeNodeEventArgs) Handles UltraWebTree1.NodeSelectionChanged
Dim uTNode As Node
Dim uTSelLevel As IntegerTry
'hasToBeFocused = False
uTNode = e.Node
uTNode.Expand(False)
uTSelLevel = uTNode.LevelSelect Case uTSelLevel
Case 0
PopulateCustomerGridView()
Case 1
PopulateFilteredCustomerGridView(uTNode.Text, "", "")
Case 2
PopulateFilteredCustomerGridView(uTNode.Parent.Text, uTNode.Text, "")
Case 3
PopulateFilteredCustomerGridView(uTNode.Parent.Parent.Text, uTNode.Parent.Text, uTNode.Text)
End Select
Catch ex As Exception
End TryEnd Sub
Protected Sub UltraWebGrid1_InitializeLayout(ByVal sender As Object, ByVal e As Infragistics.WebUI.UltraWebGrid.LayoutEventArgs) Handles UltraWebGrid1.InitializeLayout
Dim col As TemplatedColumn = DirectCast((e.Layout.Bands(0).Columns.FromKey("Select")), TemplatedColumn)
Dim tempCell As New PlaceHolderTemplate()
' Set the cell template.
col.CellTemplate = tempCell' make the checkbox the last column of band 0.
col.Move(e.Layout.Bands(0).Columns.Count – 1)Me.ClientScript.RegisterClientScriptBlock(Me.[GetType](), "CheckBoxKey", "<script type='text/javascript'>var headerCheckBoxID = '" + col.HeaderItem.FindControl("headerCB").ClientID + "';</script>")
Me.ClientScript.RegisterClientScriptBlock(Me.[GetType](), "GridKey", "var gridID = '" + Me.UltraWebGrid1.ClientID + "';", True)e.Layout.Bands(0).Columns.FromKey("CHARGE_TYPE").Hidden = True
e.Layout.Bands(0).Columns.FromKey("CUST_ID").Hidden = True
e.Layout.Bands(0).Columns.FromKey("SURCHARGE_ID").Hidden = True
e.Layout.Bands(0).Columns.FromKey("FUT_SURCHARGE_ID").Hidden = Truee.Layout.Bands(0).Columns.FromKey("CUSTOMER_NUMBER").Header.Caption = "ACCOUNT"
e.Layout.Bands(0).Columns.FromKey("CUSTOMER_NUMBER").Move(0)
e.Layout.Bands(0).Columns.FromKey("CUSTOMER_NUMBER").CellStyle.Font.Name = "MS Sans Serif"
e.Layout.Bands(0).Columns.FromKey("CUSTOMER_NUMBER").CellStyle.Font.Size = FontSize.Medium
e.Layout.Bands(0).Columns.FromKey("CUSTOMER_NAME").Header.Caption = "NAME"
e.Layout.Bands(0).Columns.FromKey("CUSTOMER_NAME").Move(1)
e.Layout.Bands(0).Columns.FromKey("CUSTOMER_NAME").CellStyle.Font.Name = "MS Sans Serif"
e.Layout.Bands(0).Columns.FromKey("CUSTOMER_NAME").CellStyle.Font.Size = FontSize.Medium
e.Layout.Bands(0).Columns.FromKey("CHARGE_CODE").Header.Caption = "Charge"
e.Layout.Bands(0).Columns.FromKey("CHARGE_CODE").Move(2)
e.Layout.Bands(0).Columns.FromKey("CHARGE_CODE").CellStyle.Font.Name = "MS Sans Serif"
e.Layout.Bands(0).Columns.FromKey("CHARGE_CODE").CellStyle.Font.Size = FontSize.Medium
e.Layout.Bands(0).Columns.FromKey("AISIXXCODE").Header.Caption = "AISIXX"
e.Layout.Bands(0).Columns.FromKey("AISIXXCODE").Move(3)
e.Layout.Bands(0).Columns.FromKey("AISIXXCODE").CellStyle.Font.Name = "MS Sans Serif"
e.Layout.Bands(0).Columns.FromKey("AISIXXCODE").CellStyle.Font.Size = FontSize.Medium
e.Layout.Bands(0).Columns.FromKey("AMT").Header.Caption = "AMT"
e.Layout.Bands(0).Columns.FromKey("AMT").Move(4)
e.Layout.Bands(0).Columns.FromKey("AMT").CellStyle.Font.Name = "MS Sans Serif"
e.Layout.Bands(0).Columns.FromKey("AMT").CellStyle.Font.Size = FontSize.Medium
e.Layout.Bands(0).Columns.FromKey("AMT").CellStyle.BackColor = Drawing.Color.FromArgb(204, 255, 204)
e.Layout.Bands(0).Columns.FromKey("UOM").Header.Caption = "UOM"
e.Layout.Bands(0).Columns.FromKey("UOM").Move(5)
e.Layout.Bands(0).Columns.FromKey("UOM").CellStyle.Font.Name = "MS Sans Serif"
e.Layout.Bands(0).Columns.FromKey("UOM").CellStyle.Font.Size = FontSize.Medium
e.Layout.Bands(0).Columns.FromKey("UOM").CellStyle.BackColor = Drawing.Color.FromArgb(204, 255, 204)
e.Layout.Bands(0).Columns.FromKey("START_DATE").Header.Caption = "Start"
e.Layout.Bands(0).Columns.FromKey("START_DATE").Move(6)
e.Layout.Bands(0).Columns.FromKey("START_DATE").CellStyle.Font.Name = "MS Sans Serif"
e.Layout.Bands(0).Columns.FromKey("START_DATE").CellStyle.Font.Size = FontSize.Medium
e.Layout.Bands(0).Columns.FromKey("START_DATE").CellStyle.BackColor = Drawing.Color.FromArgb(204, 255, 204)
e.Layout.Bands(0).Columns.FromKey("END_DATE").Header.Caption = "End"
e.Layout.Bands(0).Columns.FromKey("END_DATE").Move(7)
e.Layout.Bands(0).Columns.FromKey("END_DATE").CellStyle.Font.Name = "MS Sans Serif"
e.Layout.Bands(0).Columns.FromKey("END_DATE").CellStyle.Font.Size = FontSize.Medium
e.Layout.Bands(0).Columns.FromKey("END_DATE").CellStyle.BackColor = Drawing.Color.FromArgb(204, 255, 204)
e.Layout.Bands(0).Columns.FromKey("FUT_AMT").Header.Caption = "AMT"
e.Layout.Bands(0).Columns.FromKey("FUT_AMT").Move(8)
e.Layout.Bands(0).Columns.FromKey("FUT_AMT").CellStyle.Font.Name = "MS Sans Serif"
e.Layout.Bands(0).Columns.FromKey("FUT_AMT").CellStyle.Font.Size = FontSize.Medium
e.Layout.Bands(0).Columns.FromKey("FUT_AMT").CellStyle.BackColor = Drawing.Color.FromArgb(255, 255, 153)
e.Layout.Bands(0).Columns.FromKey("FUT_UOM").Header.Caption = "UOM"
e.Layout.Bands(0).Columns.FromKey("FUT_UOM").Move(9)
e.Layout.Bands(0).Columns.FromKey("FUT_UOM").CellStyle.Font.Name = "MS Sans Serif"
e.Layout.Bands(0).Columns.FromKey("FUT_UOM").CellStyle.Font.Size = FontSize.Medium
e.Layout.Bands(0).Columns.FromKey("FUT_UOM").CellStyle.BackColor = Drawing.Color.FromArgb(255, 255, 153)
e.Layout.Bands(0).Columns.FromKey("FUT_START_DATE").Header.Caption = "Start"
e.Layout.Bands(0).Columns.FromKey("FUT_START_DATE").Move(10)
e.Layout.Bands(0).Columns.FromKey("FUT_START_DATE").CellStyle.Font.Name = "MS Sans Serif"
e.Layout.Bands(0).Columns.FromKey("FUT_START_DATE").CellStyle.Font.Size = FontSize.Medium
e.Layout.Bands(0).Columns.FromKey("FUT_START_DATE").CellStyle.BackColor = Drawing.Color.FromArgb(255, 255, 153)
e.Layout.Bands(0).Columns.FromKey("FUT_END_DATE").Header.Caption = "End"
e.Layout.Bands(0).Columns.FromKey("FUT_END_DATE").Move(11)
e.Layout.Bands(0).Columns.FromKey("FUT_END_DATE").CellStyle.Font.Name = "MS Sans Serif"
e.Layout.Bands(0).Columns.FromKey("FUT_END_DATE").CellStyle.Font.Size = FontSize.Medium
e.Layout.Bands(0).Columns.FromKey("FUT_END_DATE").CellStyle.BackColor = Drawing.Color.FromArgb(255, 255, 153)
'e.Layout.Bands(0).Columns.FromKey("Select").Move(12)
'e.Layout.Bands(0).FilterOptions.FilterRowStyle.BackColor = Drawing.Color.FromArgb(254, 254, 254)'The boolean parameter inserts this header into viewstate, so that the grid will maintain
' it over a postback if it is not recreated.Dim colHead As ColumnHeader
For i As Integer = 0 To e.Layout.Bands(0).HeaderLayout.Count – 1
colHead = e.Layout.Bands(0).HeaderLayout(i)
colHead.RowLayoutColumnInfo.OriginY = 1
NextDim customerGroup As New ColumnHeader(True)
Dim chargeParametersGroup As New ColumnHeader(True)
Dim currentPricesGroup As New ColumnHeader(True)
Dim futurePricesGroup As New ColumnHeader(True)
Dim restGroup As New ColumnHeader(True)customerGroup.Caption = "Customer"
customerGroup.Style.HorizontalAlign = HorizontalAlign.Center
customerGroup.RowLayoutColumnInfo.OriginX = 0
customerGroup.RowLayoutColumnInfo.OriginY = 0chargeParametersGroup.Caption = "Charge Parameters"
chargeParametersGroup.Style.HorizontalAlign = HorizontalAlign.Center
chargeParametersGroup.RowLayoutColumnInfo.OriginX = 2
chargeParametersGroup.RowLayoutColumnInfo.OriginY = 0currentPricesGroup.Caption = "Current Prices"
currentPricesGroup.Style.HorizontalAlign = HorizontalAlign.Center
currentPricesGroup.Style.BackColor = Drawing.Color.FromArgb(204, 255, 204)
currentPricesGroup.RowLayoutColumnInfo.OriginX = 4
currentPricesGroup.RowLayoutColumnInfo.OriginY = 0futurePricesGroup.Caption = "Future Prices"
futurePricesGroup.Style.HorizontalAlign = HorizontalAlign.Center
futurePricesGroup.Style.BackColor = Drawing.Color.FromArgb(255, 255, 153)
futurePricesGroup.RowLayoutColumnInfo.OriginX = 8
futurePricesGroup.RowLayoutColumnInfo.OriginY = 0restGroup.Caption = " "
restGroup.RowLayoutColumnInfo.OriginX = 12
restGroup.RowLayoutColumnInfo.OriginY = 0' Add the newly created Header object to the HeaderLayout object
e.Layout.Bands(0).HeaderLayout.Add(customerGroup)
e.Layout.Bands(0).HeaderLayout.Add(chargeParametersGroup)
e.Layout.Bands(0).HeaderLayout.Add(currentPricesGroup)
e.Layout.Bands(0).HeaderLayout.Add(futurePricesGroup)
e.Layout.Bands(0).HeaderLayout.Add(restGroup)e.Layout.Bands(0).HeaderStyle.Height = Unit.Point(15)
e.Layout.Bands(0).HeaderStyle.Font.Name = "MS Sans Serif"
e.Layout.Bands(0).HeaderStyle.Font.Bold = True
e.Layout.Bands(0).HeaderStyle.Font.Size = FontSize.LargecustomerGroup.RowLayoutColumnInfo.SpanX = 2
chargeParametersGroup.RowLayoutColumnInfo.SpanX = 2
currentPricesGroup.RowLayoutColumnInfo.SpanX = 4
futurePricesGroup.RowLayoutColumnInfo.SpanX = 4End Sub
Protected Sub UltraWebGrid1_InitializeRow(ByVal sender As Object, ByVal e As Infragistics.WebUI.UltraWebGrid.RowEventArgs) Handles UltraWebGrid1.InitializeRow
Try
Dim isBinding As Boolean = CType(Session.Item("isBinding"), Boolean)
If (isBinding) Then
'e.Row.Cells("Select").Value = FalseFor Each cl As UltraGridCell In e.Row.Cells
If (cl.Column.Header.Caption = "Select") Then
cl.AllowEditing = AllowEditing.Yes
End If
If (Not (cl.Column.Header.Caption = "Select")) Then
cl.AllowEditing = AllowEditing.No
End If
Next
End If
Catch ex As Exception
'showMessage(ex.Message + " ** in function UltraGrid1_InitializeRow", "")
End Try
End Sub
End ClassPublic Class GridHeaderTemplate
Implements ITemplatePublic Sub InstantiateIn(ByVal container As Control) Implements System.Web.UI.ITemplate.InstantiateIn
' Cast the container to a HeaderItem
Dim headerItem As HeaderItem = DirectCast(container, HeaderItem)Dim checkBox As New CheckBox()
Dim cb As New CheckBox()
cb.ID = "headerCB"
'cb.Text = "Select"
cb.Attributes.Add("onclick", "HeaderCheckedChanged();")
headerItem.Controls.Add(cb)
End Sub
End ClassPublic Class PlaceHolderTemplate
Implements ITemplate
Public Sub InstantiateIn(ByVal container As Control) Implements System.Web.UI.ITemplate.InstantiateIn
' Cast the container to a CellItem
Dim cellitem As CellItem = DirectCast(container, CellItem)
Dim cb As New CheckBox()
cb.ID = "cellCB"
cellitem.Controls.Add(cb)
End Sub
End ClassThanks
Saran
-
- You must be logged in to reply to this topic.
Suggested Discussions
Check/Uncheck Select All header checkbox using jquery
Hi, i wanted to check or uncheck SelectAll header checkbox on specific condition. so how can i che…IGX Grid – Controls in Column Header Template (input, select, etc) don't get focus when click on it, because of the header gets the focus inmediately
I need a input text on the header of certain columns, i found some examples of that, using headerTe…Could not load ‘Infragistics4.Web.v13.2’ assembly or one of its dependencies
I get this error: Could not load file or assembly ‘Infragistics4.Web.v13.2’ or one of …How to default the 'Check All Rows' checkbox in header of a cell
Hi, How can I default the highlighted value so that it is not checked? Thanks! M.Created by
Created on
Nov 19, 2009 4:23 PM
Last activity on
Feb 11, 2026 2:24 PM