473,406 Members | 2,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

datagrid selectedindexchanged not firing

Hi, I'm working with VS 2005 and Framework 2.0

I have a datagrid with a link and the selectedindexchanged will not
fire. The page posts back but does nothing.

Protected Sub DataGrid1_SelectedIndexChanged(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
DataGrid1.SelectedIndexChanged

Label2.Text = "what the H"
End Sub

label2 fills with nothing.

I can get ItemCommand to fire

Protected Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e
As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
DataGrid1.ItemCommand

Label2.Text = "this shows"

End sub

but with itemcommand I can't get

datagrid1.selecteditem.cells(0) when I hit the link in the grid to
pass the data

I get: Object reference not set to an instance of an object. error

any help would be appreciated. Thanks Kevin

Jul 26 '06 #1
1 5105
Hi Kevin,

Here's a sample that shows both events firing.

Make sure you are checking ispostback in your Load event?

Let us know what you find?

Ken
Microsoft MVP [ASP.NET]

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
Protected Sub Page_Load _
(ByVal sender As Object, _
ByVal e As System.EventArgs)
If Not IsPostBack Then
DataGrid1.DataSource = CreateDataSource()
DataGrid1.DataBind()
End If
End Sub

Protected Sub DataGrid1_SelectedIndexChanged _
(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles DataGrid1.SelectedIndexChanged
Label2.Text = "what the H"
End Sub

Protected Sub DataGrid1_ItemCommand _
(ByVal source As Object, _
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) _
Handles DataGrid1.ItemCommand
Label2.Text = "this shows the ItemCommand"
End Sub

Function CreateDataSource() As System.Data.DataTable
Dim dt As New System.Data.DataTable
Dim dr As System.Data.DataRow
dt.Columns.Add(New System.Data.DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New System.Data.DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New System.Data.DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New System.Data.DataColumn _
("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>SelectedIndexChanged Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:datagrid id="DataGrid1" runat="server" >
<columns>
<asp:editcommandcolumn canceltext="Cancel" edittext="Edit"
headertext="Edit item" updatetext="Update">
<itemstyle wrap="False" />
<headerstyle wrap="False" />
</asp:editcommandcolumn>
<asp:buttoncolumn commandname="Select"
text="Select"></asp:buttoncolumn>
</columns>
</asp:datagrid><br />
<asp:label id="Label2" runat="server" text="Label"></asp:label>
</div>
</form>
</body>
</html>

<ke***@webpageconcepts.comwrote in message
news:11**********************@m79g2000cwm.googlegr oups.com...
Hi, I'm working with VS 2005 and Framework 2.0

I have a datagrid with a link and the selectedindexchanged will not
fire. The page posts back but does nothing.

Protected Sub DataGrid1_SelectedIndexChanged(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
DataGrid1.SelectedIndexChanged

Label2.Text = "what the H"
End Sub

label2 fills with nothing.

I can get ItemCommand to fire

Protected Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e
As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
DataGrid1.ItemCommand

Label2.Text = "this shows"

End sub

but with itemcommand I can't get

datagrid1.selecteditem.cells(0) when I hit the link in the grid to
pass the data

I get: Object reference not set to an instance of an object. error

any help would be appreciated. Thanks Kevin

Jul 26 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: LV | last post by:
Hello, When I manually set a list view item to be a selected item, the SelectedIndexChanged event is not firing. Am I missing something here? using System; using System.Windows.Forms; ...
0
by: PeacError | last post by:
Using Microsoft Visual Studio .NET 2003, Visual C# .NET 1.1: I apologize if this question has been addressed elsewhere, but I could not find a reference to it in the search engine for this...
8
by: Brent Burkart | last post by:
My datagrid OnCancelCommand event is not firing. HTML OnCancelCommand="AdminGrid_Cancel" 'Code Behind Sub AdminGrid_Cancel(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)...
1
by: Edward | last post by:
I am having a terrible time getting anything useful out of a listbox on my web form. I am populating it with the results from Postcode lookup software, and it is showing the results fine. What...
4
by: Paul Matthews | last post by:
Hi, SelectedIndexChanged NOT Firing in my DropDown ListBox AutoPostBack = true EnableViewState = True Autpostback works, but the SelectedIndexChanged Event does not fire !!! regards Paul
0
by: tafpin | last post by:
I have an application with a datagrid. In the IDE I have 2 template columns. The first has an image button and the second contains a link button. According to the results that I get back I must...
1
by: Stu | last post by:
Hi, I have a button in the footer of a datagrid that sometimes does not tigger the item command. The page is quite large & has a number of homegrown controls in it. Has anyone come across this...
3
by: Alec MacLean | last post by:
Hi, I have a couple of win forms where I am editing values that are stored in a SQL database. I'm using the listbox control to hold the data object each form interacts with. Each object is...
2
by: jnoody | last post by:
The problem I am having is with the SelectedIndexChanged event not always firing or the SelectedIndex property not being correct when the event does fire. The code is below, but here are some...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.