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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Clear a datagrid cell when the user hits the select Button

Status
Not open for further replies.

dbsquared

Programmer
Nov 7, 2002
175
US
Hi all,
I have a datagrid that works great the only problem I have is when a user selects the row to alter the contents with the select button.

What happens now is I set a certain cell.text = "" withthis code.
Code:
dgEquip.Items(dgEquip.EditItemIndex).Cells(5).Text = ""
when I do that the textbox is no longer editable by the user
I have a test that if they enter nothing in that field when they try to update it doesn't and returns a message and then the textbox becomes visible and theuser can then enter text.

my question is this:
Is there a way to clear the contents of a datagrid celland keep the textbox active? or how to reactivate the text box with out having to go through the error process?


Any suggestions would be greatly appreciated.
Thanks
Dan B.


To go where no programmer has gone before.
 
In the ItemDataBound event you can check if the row is in edit mode, and then clear the textbox
Code:
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
   If e.Item.ItemType = ListItemType.EditItem Then
      Dim tb As New TextBox
      tb = e.Item.Cells(<cellindex>).Controls(0)
      tb.Text = ""
   End If
End Sub

Jim
 
I think you should be able do it declaratively, too.

Try converting the given column to a TemplateColumn then designate in the markup that it doesn't pull a value from the data item when it's being bound.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top