You cannot include DataFormatString in an asp:textbox like you can an asp:boundcolumn. However, you can format it in the binding expression as shown in the link: DataBinder.Eval(Container, "DataItem.DateRequired", "{0:d}")
I needed to include a date column in my datagrid which could possible be null. I therefore had to insert null, or the value entered by the user if appropriate. I wrote a small function which created the parameter: Function CreateSQLDateParam(ByRef Name As String, ByRef Val As String) As SqlParameter
Dim SQL_P As SqlParameter
SQL_P = New SqlParameter(Name, SqlDbType.DateTime)
If Val <> "" Then
SQL_P.Value = CDate(Val)
Else
SQL_P.Value = DBNull.Value
End If
Return SQL_P
End Function
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