Hello,
I would like to build a webdatagrid in codebehind in vb.net.
I need help with:
adding behaviors
adding columns
Any Help would be great!!!!
Thanks!!!!
Hi jouin,
I would suggest you to check the following links from the documentation, which you may find helpful - http://help.infragistics.com/Help/NetAdvantage/ASPNET/2011.2/CLR4.0/html/WebDataGrid_Add_or_Remove_a_Column.html, http://help.infragistics.com/Help/NetAdvantage/ASPNET/2011.2/CLR4.0/html/WebDataGrid_Behaviors.html.
If you have any questions, please do not hesitate to ask.
Hello jouin,
Please let me know if you need any further assistance with the matter.
That is just what I needed!!!! I only need an example on how to create a templatedatafield and add and image button.
Thanks!
Jack
Hi Jack,
Here is an example of using item templates - http://help.infragistics.com/Help/NetAdvantage/ASPNET/2011.2/CLR4.0/html/WebDataGrid_Using_Item_Template.html.
Please let me know if this helps.
Nikolay,
I too am trying to construct WebDataGrids in code behind throughout a large system that we are still trying to upgrade from old UltraWebGrids. We are attempting to use both ViewState and DataViewState to persist data between postbacks. I am struggling with determining the appropriate events in the page lifecycle during which construct the columns, behaviors and editorproviders. I have seen many odd behaviors in a multitude of attempts that including dropdownproviders that lose knowledge of their list items during AJAX postbacks (while the overall grid still retains data), currencyeditorproviders that remember the column to which they belong, but forget their MaxValue parameter, DropDownProviders that forget not to EnableRenderingAnchors, and many more I will not detail here.
I am looking for a best practices guide or complete published example of how to constuct a WebDataGrid in code behind (any .NET language will suffice). Preferably the example would include texteditor providers, numeric and/or currency editor providers, data providers, and most importantly DropDownProviders that have a dynamically loaded list of values (as in a real world scenario in which values come from DB) rather than hardcoded items in markup.
Does such an example or guide exist for public distribution?
Thanks,
rsutton333
If you have any further questions, please feel free to contact me.
I would suggest you to create the grid behaviors on page load.
Let me know if this helps.
I am getting index was outside the bounds of the array when I click on button:
ASPX
<ig:WebDataGrid ID="WebDataGrid1" runat="server" DataSourceID
="SqlDataSource1">
</ig:WebDataGrid>
Codebehind:
Private Class CustomItemTemplate Implements ITemplate #Region "ITemplate Members" Public Sub InstantiateIn(ByVal container As Control) Implements ITemplate.InstantiateIn Dim edit As New ImageButton() edit.ID = "EditButton" edit.AlternateText = "Edit" edit.CommandName = "edit" edit.ImageUrl = "icons/pen_24.png" edit.CommandArgument = DirectCast(DirectCast(container, TemplateContainer).DataItem, DataRowView)("Id").ToString() edit.ToolTip = "edit" container.Controls.Add(edit) End Sub #End Region End Class Protected Sub Page_Init(sender As Object, e As System.EventArgs) Handles Me.Init 'Load Data SqlDataSource1.SelectCommand = "select * from InterestTypes order by Name" 'Build Base Grid WebDataGrid1.Height = "400" WebDataGrid1.Width = New Unit("100%") WebDataGrid1.AutoGenerateColumns = False WebDataGrid1.DataKeyFields = "ID" 'Build Columns Dim DFid As New BoundDataField(True) DFid.Key = "ID" DFid.Header.Text = "ID" DFid.DataFieldName = "ID" DFid.Hidden = True Me.WebDataGrid1.Columns.Add(DFid) Dim DFPName As New BoundDataField(True) DFPName.Key = "Name" DFPName.Header.Text = "Interest Type" DFPName.DataFieldName = "Name" Me.WebDataGrid1.Columns.Add(DFPName) Dim DFActive As New BoundCheckBoxField(True) DFActive.Key = "Active" DFActive.Header.Text = "Active" DFActive.DataFieldName = "Active" Me.WebDataGrid1.Columns.Add(DFActive) Dim field1 As New TemplateDataField() field1.Key = "TemplateColumn1" field1.Header.Text = "Edit" Me.WebDataGrid1.Columns.Add(field1) Dim templateColumn1 As TemplateDataField = DirectCast(Me.WebDataGrid1.Columns("TemplateColumn1"), TemplateDataField) templateColumn1.ItemTemplate = New CustomItemTemplate() 'Build Paging WebDataGrid1.Behaviors.CreateBehavior( Of Infragistics.Web.UI.GridControls.Paging)() WebDataGrid1.Behaviors.Paging.PageSize = 10 WebDataGrid1.Behaviors.Paging.PagerMode = Infragistics.Web.UI.GridControls. PagerMode.NumericFirstLast 'Build Sorting 'WebDataGrid1.Behaviors.CreateBehavior(Of Infragistics.Web.UI.GridControls.Sorting)() 'WebDataGrid1.Behaviors.Sorting.SortedColumns.Add(WebDataGrid1.Columns("MSecurity"), Infragistics.Web.UI.SortDirection.None) End Sub Also when I change pages using the pager I get "Async Request Failed"
Private Class CustomItemTemplate
Implements ITemplate
#Region
"ITemplate Members"
Public Sub InstantiateIn(ByVal container As Control) Implements ITemplate.InstantiateIn
Dim edit As New ImageButton() edit.ID =
edit.ID =
"EditButton"
edit.AlternateText =
"Edit"
edit.CommandName =
"edit"
edit.ImageUrl =
"icons/pen_24.png"
edit.CommandArgument =
DirectCast(DirectCast(container, TemplateContainer).DataItem, DataRowView)("Id").ToString() edit.ToolTip =
edit.ToolTip =
container.Controls.Add(edit)
End Sub
#End
Region
End Class
Protected Sub Page_Init(sender As Object, e As System.EventArgs) Handles Me.Init 'Load Data SqlDataSource1.SelectCommand = "select * from InterestTypes order by Name" 'Build Base Grid WebDataGrid1.Height = "400" WebDataGrid1.Width = New Unit("100%") WebDataGrid1.AutoGenerateColumns = False WebDataGrid1.DataKeyFields = "ID" 'Build Columns Dim DFid As New BoundDataField(True) DFid.Key = "ID" DFid.Header.Text = "ID" DFid.DataFieldName = "ID" DFid.Hidden = True Me.WebDataGrid1.Columns.Add(DFid) Dim DFPName As New BoundDataField(True) DFPName.Key = "Name" DFPName.Header.Text = "Interest Type" DFPName.DataFieldName = "Name" Me.WebDataGrid1.Columns.Add(DFPName) Dim DFActive As New BoundCheckBoxField(True) DFActive.Key = "Active" DFActive.Header.Text = "Active" DFActive.DataFieldName = "Active" Me.WebDataGrid1.Columns.Add(DFActive) Dim field1 As New TemplateDataField() field1.Key = "TemplateColumn1" field1.Header.Text = "Edit" Me.WebDataGrid1.Columns.Add(field1) Dim templateColumn1 As TemplateDataField = DirectCast(Me.WebDataGrid1.Columns("TemplateColumn1"), TemplateDataField) templateColumn1.ItemTemplate = New CustomItemTemplate() 'Build Paging WebDataGrid1.Behaviors.CreateBehavior( Of Infragistics.Web.UI.GridControls.Paging)() WebDataGrid1.Behaviors.Paging.PageSize = 10 WebDataGrid1.Behaviors.Paging.PagerMode = Infragistics.Web.UI.GridControls. PagerMode.NumericFirstLast 'Build Sorting 'WebDataGrid1.Behaviors.CreateBehavior(Of Infragistics.Web.UI.GridControls.Sorting)() 'WebDataGrid1.Behaviors.Sorting.SortedColumns.Add(WebDataGrid1.Columns("MSecurity"), Infragistics.Web.UI.SortDirection.None) End Sub Also when I change pages using the pager I get "Async Request Failed"
Protected Sub Page_Init(sender As Object, e As System.EventArgs) Handles Me.Init
'Load Data
SqlDataSource1.SelectCommand =
"select * from InterestTypes order by Name"
'Build Base Grid
WebDataGrid1.Height =
"400"
WebDataGrid1.Width =
New Unit("100%") WebDataGrid1.AutoGenerateColumns =
WebDataGrid1.AutoGenerateColumns =
False
WebDataGrid1.DataKeyFields =
"ID"
'Build Columns
Dim DFid As New BoundDataField(True) DFid.Key =
DFid.Key =
DFid.Header.Text =
DFid.DataFieldName =
DFid.Hidden =
True
Me.WebDataGrid1.Columns.Add(DFid)
Dim DFPName As New BoundDataField(True) DFPName.Key =
DFPName.Key =
"Name"
DFPName.Header.Text =
"Interest Type"
DFPName.DataFieldName =
Me.WebDataGrid1.Columns.Add(DFPName)
Dim DFActive As New BoundCheckBoxField(True) DFActive.Key =
DFActive.Key =
"Active"
DFActive.Header.Text =
DFActive.DataFieldName =
Me.WebDataGrid1.Columns.Add(DFActive)
Dim field1 As New TemplateDataField() field1.Key =
field1.Key =
"TemplateColumn1"
field1.Header.Text =
Me.WebDataGrid1.Columns.Add(field1)
Dim templateColumn1 As TemplateDataField = DirectCast(Me.WebDataGrid1.Columns("TemplateColumn1"), TemplateDataField) templateColumn1.ItemTemplate =
templateColumn1.ItemTemplate =
New CustomItemTemplate()
'Build Paging
WebDataGrid1.Behaviors.CreateBehavior(
Of Infragistics.Web.UI.GridControls.Paging)() WebDataGrid1.Behaviors.Paging.PageSize = 10 WebDataGrid1.Behaviors.Paging.PagerMode = Infragistics.Web.UI.GridControls.
WebDataGrid1.Behaviors.Paging.PageSize = 10
WebDataGrid1.Behaviors.Paging.PagerMode = Infragistics.Web.UI.GridControls.
PagerMode.NumericFirstLast
'Build Sorting
'WebDataGrid1.Behaviors.CreateBehavior(Of Infragistics.Web.UI.GridControls.Sorting)()
'WebDataGrid1.Behaviors.Sorting.SortedColumns.Add(WebDataGrid1.Columns("MSecurity"), Infragistics.Web.UI.SortDirection.None)
Also when I change pages using the pager I get "Async Request Failed"
>