Datagrid ItemCreated event & Edit botton - vb.net

  • Thread starter Maulik shah via .NET 247
  • Start date
M

Maulik shah via .NET 247

hi,

I am displaying various task from task table toDatagrid.I have to display task according to category ingrid.for eg.

Cat 1
task 1 A B c 1 2 <EditLinkbutton>
task 2 D E F 3 4 <EditLinkbutton>

cat 2
task 3 p q r 5 6 <EditLinkbutton>
task 4 --- -- -- -- <EditLinkbutton>

like that. To display category on Data Grid i musing logic for Populating the Summary Row in grid.
for that i cretaed DataGrid_ItemCreated event in that i takingvalue of row using datarowview object.it is displaying fine ongrid accordingly what i need. but now i have <Editlinkbutton> ongrid so when i m clicking on that same DataGrid_ItemCreated fires and giving "System.NullReferenceException: Objectreference not set to an instance of an object" below is my codefor event

Private Sub DisciplineDataGrid_ItemCreated(ByVal sender AsObject, ByVal e AsSystem.Web.UI.WebControls.DataGridItemEventArgs) HandlesDisciplineDataGrid.ItemCreated
Dim drv As DataRowView = CType(e.Item.DataItem,DataRowView)
Dim itemType As New ListItemType
Dim m_PrevCategory As String
itemType = e.Item.ItemType
If (itemType = ListItemType.Item Or itemType =ListItemType.AlternatingItem) Then
If (m_PrevCategory = drv.Item(0)) Then
e.Item.Cells(0).ForeColor() =e.Item.Cells(0).BackColor.LightYellow
Else
e.Item.Cells(0).ColumnSpan = 0
m_PrevCategory = drv.Item(0)
End If
End If

End Sub

On click of edit button on grid i m getting errorat "If (m_PrevCategory = drv.Item(0)) Then" line as drv.Item(o)does not contain any value at run time. how i can makeeditbutton to raise 'EditCommand" event instead of ItemCreatedevent so i can write two lines of code to put grid row in editmode.

thanks
Maulik
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top