Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enabling a disabled button in datagrid footer

Status
Not open for further replies.

vedicman

Programmer
Sep 5, 2003
128
US
I have a button (btnADD)in the footer of a datagrid for adding new rows to the grid. Initially I am setting the enabled property to false, then I want to enable the button when data is entered into a specific textbox (also in the footer). I'm using the ontextchanged event to run:

Sub EnableAddButton(sender As Object, e As System.EventArgs)

'Dim btnAdd as button = e.Item.FindControl("btnAdd")
Dim btnAdd as button=CType(FindControl("btnAdd"), button)
btnAdd.enabled="true"

End Sub

I'm getting the following error:
Object reference not set to an instance of an object.

Obviously I don't have this wired up properly and I'm looking for guidance. I think I'm not using the correct parameters in the sub. I've tried others, but I haven't hit upon the right one. I've also dimmed btnAdd as shown with the line that is commented out. It gives the same error.

Thanks....Franco
 
you should do this in the itemdatabound event of the datacontrol...

-DNG
 
oops...i meant to say...

you should do this in the itemdatabound event of the datagrid]/b]...

-DNG
 
Can you provide some details?

I wired the OnItemDatabound method of the datagrid to the sub below:

Sub EnableAddButton(sender As Object, e As System.Web.UI.WebControls.DataGridItemEventArgs)

Dim btnAdd as button = e.Item.FindControl("btnAdd")
btnAdd.enabled="true"

End Sub

I'm getting this error: Object reference not set to an instance of an object on this line:

btnAdd.enabled="true"

Obviously, I'm still not understanding the concept!

 
That's probably because the button won't exist on every row - make sure you are only checking on item or alternating item rows.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Add this IF to your event:

If e.Item.ItemType = ListItemType.Footer Then
...Your code
End If
 
something like this:

Private Sub yourdatagrid_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles yourgrid.ItemDataBound
If e.item.itemtype = ListItemType.Footer then
Dim btnAdd as button = e.Item.FindControl("btnAdd")
btnAdd.enabled="true"

End Sub

-DNG
 
Oops, I just saw that the button was in the footer - try using jbenson001's example instead.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
jbenson001

With the following code, the button(btnAdd) is loading disabled, but when I enter data into the textbox(txtWeek) it is not becomming enabled. I'm still missing something. Any other ideas?

Sub EnableAddButton(sender As Object, e As System.Web.UI.WebControls.DataGridItemEventArgs)

If e.Item.ItemType = ListItemType.Footer Then
Dim txtWeek as textbox = e.Item.FindControl("txtWeek")
If txtWeek.text <> "" Then
Dim btnAdd as button = e.Item.FindControl("btnAdd")
btnAdd.enabled="true"
End If
End If

End Sub
 
It won't be enabled unless you tell it to (at the minute you are checking the text when the footer is bound to the grid, but not once the text changes).


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
ca8msm

We've come full circle...how do I enable the button when txtWeek changes? See my initial post.

Thanks...Franco
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top