I have a button in my Gridview which i would like to execute on postback depending on the value in the 11 cell along (% COMPLETE colum in my gridview).
I am getting "Object reference not set to an instance of an object."
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If IsPostBack = True Then
If GridView1.SelectedRow.Cells(11).Text = "100.00%" Then
MsgBox("100% Completion confirmed, record Saved")
Else
MsgBox("100% Completion required to Save")
End If
End If
End Sub
I cant use index (or at least i think i cant) becuase i want to check if the 10th cell equals "100%". I have added selected row to the Datagrid and it now picks up the selectedrow value which is great!
Problem i now have is that if i click on a record that has 100% in the 10th cell it stores this so when i click on one that doesnt equal 100% it gives me the same message but if i click it again it then realises its not 100% and gives me the correct result.
I cannot see what is wrong with my If statement or why it would do that:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If IsPostBack = True AndAlso GridView1.SelectedRow IsNot Nothing Then
If GridView1.SelectedRow.Cells(10).Text = "100.00%" Then
MsgBox("Completion confirmed")
Else
MsgBox("Error: Order is incomplete. 100% Completion is required to Save")
End If
End If
End Sub
I have a button in my Gridview which i would like to execute on postback depending on the value in the 11 cell along (% COMPLETE colum in my gridview).
I suggest you execute the block code in Button_click event.
Gary yang - MSFT
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
I have a button in my Gridview which i would like to execute on postback depending on the value in the 11 cell along (% COMPLETE colum in my gridview).
I am getting "Object reference not set to an instance of an object."
After reading your post again. It seems that you want to get the selected row and do something according to its value. If in this case, when you click the button, the Button_Click event will be fired only when the Page_load has been finished. Please refer
to the following code:
stephen.adsh...
Member
20 Points
76 Posts
Gridview Button (GridView1.SelectedRow.Cells().Text ) Object error
Mar 27, 2009 10:24 AM|LINK
I have a button in my Gridview which i would like to execute on postback depending on the value in the 11 cell along (% COMPLETE colum in my gridview).
I am getting "Object reference not set to an instance of an object."
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If IsPostBack = True Then If GridView1.SelectedRow.Cells(11).Text = "100.00%" Then MsgBox("100% Completion confirmed, record Saved") Else MsgBox("100% Completion required to Save") End If End If End SubAny ideas where i am going wrong?
gridview button selected row cells ispostback
mohd786hussa...
Contributor
4329 Points
878 Posts
Re: Gridview Button (GridView1.SelectedRow.Cells().Text ) Object error
Mar 27, 2009 12:24 PM|LINK
Have you binded your grid before checking the condition?
Mohammad Hussain
Web design, Logo design & Asp.net development
Sangeeth.Ind...
Participant
1042 Points
297 Posts
Re: Gridview Button (GridView1.SelectedRow.Cells().Text ) Object error
Mar 27, 2009 12:31 PM|LINK
Hi,
Make sure that the GridView has a row 'Selected'. You can try changing the condition to,
If IsPostBack = True AndAlso GridView1.SelectedRow IsNot Nothing Then
EndIf
Or, why don't u try to access the row with its index (rather than SelectedRow)?
Cheers
stephen.adsh...
Member
20 Points
76 Posts
Re: Gridview Button (GridView1.SelectedRow.Cells().Text ) Object error
Mar 27, 2009 02:16 PM|LINK
I cant use index (or at least i think i cant) becuase i want to check if the 10th cell equals "100%". I have added selected row to the Datagrid and it now picks up the selectedrow value which is great!
Problem i now have is that if i click on a record that has 100% in the 10th cell it stores this so when i click on one that doesnt equal 100% it gives me the same message but if i click it again it then realises its not 100% and gives me the correct result.
I cannot see what is wrong with my If statement or why it would do that:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If IsPostBack = True AndAlso GridView1.SelectedRow IsNot Nothing Then If GridView1.SelectedRow.Cells(10).Text = "100.00%" Then MsgBox("Completion confirmed") Else MsgBox("Error: Order is incomplete. 100% Completion is required to Save") End If End If End SubGary yang - ...
All-Star
25901 Points
2588 Posts
Re: Gridview Button (GridView1.SelectedRow.Cells().Text ) Object error
Mar 30, 2009 09:05 AM|LINK
I suggest you execute the block code in Button_click event.
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Gary yang - ...
All-Star
25901 Points
2588 Posts
Re: Gridview Button (GridView1.SelectedRow.Cells().Text ) Object error
Mar 31, 2009 03:19 AM|LINK
After reading your post again. It seems that you want to get the selected row and do something according to its value. If in this case, when you click the button, the Button_Click event will be fired only when the Page_load has been finished. Please refer to the following code:
//Html
//
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.