Hi
I've added the Webdata grid in the ASPX (vb.net) page and here is the code snippet of the source page (HTML)
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> </div> <asp:Button ID="Button1" runat="server" Text="Button" /> <ig:WebDataGrid ID="WebDataGrid1" runat="server" Height="350px" Width="400px"> <Behaviors> <ig:Selection CellClickAction="Row"> <AutoPostBackFlags CellSelectionChanged="True" ColumnSelectionChanged="True" RowSelectionChanged="True" /> </ig:Selection> <ig:RowSelectors> </ig:RowSelectors> <ig:Activation> </ig:Activation> <ig:EditingCore> </ig:EditingCore> </Behaviors> </ig:WebDataGrid> <ig:WebScriptManager ID="WebScriptManager1" runat="server"> </ig:WebScriptManager> </form> </body> </html>
In the code behind, the code snippet is
Public Class personXXX Public name As String Public age As Int16 Public gender As String Public status As Boolean Public State As String End Class
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
WebDataGrid1.EnableDataViewState = True BuildGrid()
Else
End If
End Sub Private Sub BuildGrid()
Dim dataTab As New DataTable Dim colDB As New DataColumn Dim objRow As DataRow
WebDataGrid1.Rows.Clear()
colDB = New DataColumn("RowID", Type.GetType("System.Int16")) dataTab.Columns.Add(colDB)
colDB = New DataColumn("Name", Type.GetType("System.String")) dataTab.Columns.Add(colDB)
colDB = New DataColumn("Age", Type.GetType("System.Int16")) dataTab.Columns.Add(colDB)
colDB = New DataColumn("Gender", Type.GetType("System.String")) dataTab.Columns.Add(colDB)
colDB = New DataColumn("Status", Type.GetType("System.Boolean")) dataTab.Columns.Add(colDB)
colDB = New DataColumn("State", Type.GetType("System.String")) dataTab.Columns.Add(colDB)
Dim per1 As New personXXX With { _ .name = "Eliza", _ .age = 27, _ .gender = "Female", _ .State = "CA", _ .status = True } Dim per2 As New personXXX With { _ .name = "Sarah", _ .age = 22, _ .gender = "Female", _ .State = "GA", _ .status = True } Dim per3 As New personXXX With { _ .name = "ema", _ .age = 22, _ .gender = "Female", _ .State = "MD", _ .status = False } Dim per4 As New personXXX With { _ .name = "rachel", _ .age = 20, _ .gender = "Female", _ .State = "MD", _ .status = True } Dim per6 As New personXXX With { _ .name = "jim", _ .age = 22, _ .gender = "Male", _ .State = "MD", _ .status = True } Dim per5 As New personXXX With { _ .name = "jack", _ .age = 32, _ .gender = "Male", _ .State = "CA", _ .status = True }
Dim personArr As personXXX() = {New personXXX(), per1, per2, per3, per4, per5, per6}
For introw = 1 To 6 objRow = dataTab.NewRow() objRow(0) = introw objRow(1) = personArr(introw).name.ToString objRow(2) = Integer.Parse(personArr(introw).age) objRow(3) = personArr(introw).gender.ToString objRow(4) = personArr(introw).status objRow(5) = personArr(introw).State dataTab.Rows.Add(objRow) Next
WebDataGrid1.DataSource = dataTab WebDataGrid1.DataBind() End Sub
When I click on the checkbox in the grid, I get an error, see attached.
Any help?
Hello Karthik ,
I’m just following up to see if you’ve been able to resolve your issue. If you have any questions or concerns or if you need further assistance please let me know.
Best Regards,
Maya Kirova
Developer Support Engineer
Infragistics, Inc.
http://ko.infragistics.com/support
Thank you for posting in our forum.
As the error suggests you need to set for the grid the DataKeyFields property in order to be able to update values in the grid.
Generally the DataKeyFields should match the primary key of the collection you’re binding them to and should be unique for each record.
You could set in this case the RowID as the primary key of your data table and then set that in the DataKeyFields property of the grid.
Let me know if you have any questions or concerns.
Developer Support Engineer II