473,856 Members | 1,638 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

datagrid selectedindexch anged not firing

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

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

Protected Sub DataGrid1_Selec tedIndexChanged (ByVal sender As
Object, ByVal e As System.EventArg s) Handles
DataGrid1.Selec tedIndexChanged

Label2.Text = "what the H"
End Sub

label2 fills with nothing.

I can get ItemCommand to fire

Protected Sub DataGrid1_ItemC ommand(ByVal source As Object, ByVal e
As System.Web.UI.W ebControls.Data GridCommandEven tArgs) Handles
DataGrid1.ItemC ommand

Label2.Text = "this shows"

End sub

but with itemcommand I can't get

datagrid1.selec teditem.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 5165
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.dt d">

<script runat="server">
Protected Sub Page_Load _
(ByVal sender As Object, _
ByVal e As System.EventArg s)
If Not IsPostBack Then
DataGrid1.DataS ource = CreateDataSourc e()
DataGrid1.DataB ind()
End If
End Sub

Protected Sub DataGrid1_Selec tedIndexChanged _
(ByVal sender As Object, _
ByVal e As System.EventArg s) _
Handles DataGrid1.Selec tedIndexChanged
Label2.Text = "what the H"
End Sub

Protected Sub DataGrid1_ItemC ommand _
(ByVal source As Object, _
ByVal e As System.Web.UI.W ebControls.Data GridCommandEven tArgs) _
Handles DataGrid1.ItemC ommand
Label2.Text = "this shows the ItemCommand"
End Sub

Function CreateDataSourc e() As System.Data.Dat aTable
Dim dt As New System.Data.Dat aTable
Dim dr As System.Data.Dat aRow
dt.Columns.Add( New System.Data.Dat aColumn _
("IntegerValue" , GetType(Int32)) )
dt.Columns.Add( New System.Data.Dat aColumn _
("StringValu e", GetType(String) ))
dt.Columns.Add( New System.Data.Dat aColumn _
("CurrencyValue ", GetType(Double) ))
dt.Columns.Add( New System.Data.Dat aColumn _
("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 'CreateDataSour ce
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Selected IndexChanged Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:datagrid id="DataGrid1" runat="server" >
<columns>
<asp:editcomman dcolumn canceltext="Can cel" edittext="Edit"
headertext="Edi t item" updatetext="Upd ate">
<itemstyle wrap="False" />
<headerstyle wrap="False" />
</asp:editcommand column>
<asp:buttoncolu mn commandname="Se lect"
text="Select"></asp:buttoncolum n>
</columns>
</asp:datagrid><b r />
<asp:label id="Label2" runat="server" text="Label"></asp:label>
</div>
</form>
</body>
</html>

<ke***@webpagec oncepts.comwrot e in message
news:11******** **************@ m79g2000cwm.goo glegroups.com.. .
Hi, I'm working with VS 2005 and Framework 2.0

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

Protected Sub DataGrid1_Selec tedIndexChanged (ByVal sender As
Object, ByVal e As System.EventArg s) Handles
DataGrid1.Selec tedIndexChanged

Label2.Text = "what the H"
End Sub

label2 fills with nothing.

I can get ItemCommand to fire

Protected Sub DataGrid1_ItemC ommand(ByVal source As Object, ByVal e
As System.Web.UI.W ebControls.Data GridCommandEven tArgs) Handles
DataGrid1.ItemC ommand

Label2.Text = "this shows"

End sub

but with itemcommand I can't get

datagrid1.selec teditem.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
2553
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; namespace DOMBuilder.GUI { public delegate void SelectedDomainObjectChangedHandler();
0
5430
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 board. I have a form that contains a ListView and a GroupBox control. The GroupBox control itself contains several TextBox Controls. I have Validating and Validated event handlers set for the GroupBox control, and a SelectedIndexChanged event...
8
1717
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) AdminGrid.EditItemIndex = -1 BindData()
1
8437
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 I want to do is to allow the user to click on the row that corresponds to the correct address, and have the code behind populate the form's Address1, Address2 etc. controls with the relevant data items. I put the code for this into the...
4
4185
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
1763
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 add more columns to the datagrid. This is a sample of how I am adding these colums: templateColumn = New TemplateColumn
1
1676
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 type of behaviour before? Can anyone suggest a solution? Thanks in advance, Stu
3
2642
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 defined by my own classes. On the first form, I use an approach to reduce the number of database calls. This essentially consists of :
2
3308
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 details first. The DropDownList is actually a custom control called DropDownListWithCommandEvent that inherits from DropDownList. The reason I have created this is to create a DropDownList that will bubble a Command event to the containing...
0
9919
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11061
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10699
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10390
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9534
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7932
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5960
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4578
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3203
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.