Wednesday, October 13, 2004

Setting DataGrid Textbox

Setting DataGrid Textbox to current date by default.

I needed to set a textbox control within a datagrid footer to display the current date by default. This is the solution I found after a little research. I used the DataGrid_ItemCreated event:

Private Sub DataGrid_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid.ItemCreated
Dim strTemp As String = "TextBox"
Dim temptext As TextBox
temptext = e.Item.FindControl(strTemp)
If Not temptext Is Nothing Then
temptext.Text = Date.Today
End If
End Sub

No comments: