Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > datagrid selectedindexchanged not firing

Reply
Thread Tools

datagrid selectedindexchanged not firing

 
 
kevin@webpageconcepts.com
Guest
Posts: n/a
 
      07-26-2006
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

 
Reply With Quote
 
 
 
 
Ken Cox [Microsoft MVP]
Guest
Posts: n/a
 
      07-26-2006
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>

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
selectedindexchanged event not firing in custom control derived from datagrid John Blair ASP .Net Web Controls 6 06-29-2006 04:07 PM
DropDownList SelectedIndexChanged event not firing when in a panel Paul Lacey ASP .Net 2 02-17-2005 09:51 AM
dropdownlist selectedindexchanged event not firing.. please help. DesignerX ASP .Net 2 11-14-2003 03:25 PM
Re: SelectedIndexChanged event not firing Severin ASP .Net 0 08-04-2003 07:39 PM
Re: SelectedIndexChanged event not firing Kevin Spencer ASP .Net 7 08-02-2003 03:14 PM



Advertisments