I have a nested grid and want to pull the value of the cell double clicked on.
Below is the code I am using and its giving me object not set to an instance of an object. I am pulling a value from another grid with the same double click event and I am not sure why it will not work here.
Thanks!
Imports SystemImports System.CollectionsImports System.ComponentModelImports System.DataImports System.DrawingImports System.WebImports System.Web.SessionStateImports System.Web.UIImports System.Web.UI.WebControlsImports System.Web.UI.HtmlControlsImports System.Data.SqlClientImports System.Data.SqlImports Infragistics.WebUI.UltraWebGridImports Microsoft.Win32
Namespace WebSamplesVB.WebGrid.HierarchicalGrid
'/ <summary> '/ Summary description for WebForm1. '/ </summary>
Partial Class HierarchicalGrid Inherits System.Web.UI.Page Protected sqlConn As System.Data.SqlClient.SqlConnection Private contactsDataSet1 As New System.Data.DataSet
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load ' WebPanel2.Visible = WebSamplesVB.Config.ShowDescription; If Not IsPostBack Then Me.UG1.DataBind() Me.UG1.DisplayLayout.ActiveRow = Me.UG1.Rows(0) End If
End Sub 'Page_Load
#Region "Web Form Designer generated code"
Protected Overrides Sub OnInit(ByVal e As EventArgs) ' ' CODEGEN: This call is required by the ASP.NET Web Form Designer. ' InitializeComponent() MyBase.OnInit(e)
End Sub 'OnInit
'/ <summary> '/ Required method for Designer support - do not modify '/ the contents of this method with the code editor. '/ </summary> Private Sub InitializeComponent() Me.sqlConn = New System.Data.SqlClient.SqlConnection ' ' oleDbConnection1 ' Me.sqlConn.ConnectionString = ConfigurationManager.ConnectionStrings("bob").ConnectionString
End Sub 'InitializeComponent
#End Region
Protected Sub UG1_DblClick(ByVal sender As Object, ByVal e As Infragistics.WebUI.UltraWebGrid.ClickEventArgs) Handles UG1.DblClick Dim rows As SelectedRowsCollection = Me.UG1.DisplayLayout.SelectedRows If rows Is Nothing OrElse rows.Count = 0 Then If Me.UG1.Rows.Count > 0 Then Me.UG1.Rows(0).Selected = True End If End If
Me.UG1.Rows(0).Selected.ToString()
wdw_ChannelDrillDown.WindowState = Infragistics.Web.UI.LayoutControls.DialogWindowState.Maximized wdw_ChannelDrillDown.Visible = "True" wdw_ChannelDrillDown.ContentPane.ContentUrl = "ChannelLoadDetails.aspx?channel=" + e.Row.Cells(0).ToString() + "&messagetype=" + e.Row.Cells(2).ToString()
End Sub
Private Sub UG1_PageIndexChanged(ByVal sender As Object, ByVal e As Infragistics.WebUI.UltraWebGrid.PageEventArgs) Handles UG1.PageIndexChanged Me.UG1.DisplayLayout.Pager.CurrentPageIndex = e.NewPageIndex Me.UG1.DataBind()
End Sub 'UG1_PageIndexChanged
Private Sub UG1_InitializeLayout(ByVal sender As Object, ByVal e As LayoutEventArgs) Handles UG1.InitializeLayout UG1.Bands(1).Columns.FromKey("Channel").HeaderText = "Channel" UG1.Bands(1).Columns.FromKey("Channel").CellStyle.HorizontalAlign = HorizontalAlign.Center
UG1.Bands(1).DefaultColWidth = New Unit("100px") UG1.Bands(1).Columns.FromKey("Message_Count").Width = New Unit("100 px") UG1.Bands(1).SelectTypeCol = SelectType.Extended UG1.Bands(1).HeaderClickAction = HeaderClickAction.Select UG1.DisplayLayout.Bands(0).Columns(0).Header.Caption = "Channel" UG1.DisplayLayout.Bands(0).Columns(1).Header.Caption = "Total" UG1.DisplayLayout.Bands(1).Columns(0).Header.Caption = "Message Type" UG1.DisplayLayout.Bands(1).Columns(1).Header.Caption = "Message Type" UG1.DisplayLayout.Bands(1).Columns(2).Header.Caption = "Count" UG1.DisplayLayout.Bands(1).Columns(0).Hidden = "True"
End Sub 'UG1_InitializeLayout
Private Sub UG1_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs) Handles UG1.dataBinding 'oleDbConnection1.ConnectionString = WebSamplesVB.Config.NorthwindMDBConnString sqlConn.ConnectionString = ConfigurationManager.ConnectionStrings("bob").ConnectionString Dim cmdChannels As New SqlDataAdapter("Execute dbo.usp_dailychanneltotals", sqlConn) Dim cmdMessages As New SqlDataAdapter("Execute dbo.usp_dailymessagetotals", sqlConn) cmdChannels.Fill(contactsDataSet1, "Channels") cmdMessages.Fill(contactsDataSet1, "Messages") Try contactsDataSet1.Relations.Add("Channels", contactsDataSet1.Tables("Channels").Columns("Channel"), contactsDataSet1.Tables("Messages").Columns("Channel")) Catch x As System.Exception Dim s As String = x.Message Dim m As String = s End Try
Me.UG1.DataSource = contactsDataSet1.Tables("Channels").DefaultView
End Sub 'UG1_DataBinding End Class 'HierarchicalGrid
End Namespace
Hello rydavis,
You should be able to step through your code in the debugger to determine which line is causing the exception. That would help in determining the cause of your issue.
Thanks for your reply. I already know what line is causing the problem I just do not understand why. Below is where it is blowing up. Specifically e.Row.Cells(0).ToString()
Any help would be much appreciated.
wdw_ChannelDrillDown.ContentPane.ContentUrl = "ChannelLoadDetails.aspx?channel=" + e.Row.Cells(0).ToString() + "&messagetype=" + e.Row.Cells(2).ToString()
Depending on which element is clicked (the column, row, or cell), the others will be null. If you are clicking on a cell for instance, you will need to call e.Cell.Row.Cells(0). I would check to see if the row is null before calling anything for e.Row and likewise for any of the others.
Hope that helps.