Showing posts with label field. Show all posts
Showing posts with label field. Show all posts

Saturday, March 24, 2012

Please help Friends how to control maxlength textbox in datagrid

Is there a way to set the maxlength property for a text box in the datagrid.

My database table field size is only 10 chars for first name.

How can i make the user not to enter more tha 10 chars on the front end.

Is there any Max length property i can assign for the text boxes.

I have 4 text boxes in datagrid.

Thank you very much.Hi,

if it is single-line TextBox, you can use its MaxLength property like you normally can.

<asp:TextBox ID="xxx" MaxLength="4"... /
This works even if TextBox is in a DataGrid.
Thanks Joteke, I have the following code triggered when i click edit in the datagrid, then it will show all text boxes etc. where can i place the maxlength="4" property in the following code.

Thank you very much.

< Code >
Sub MyDataGrid_UpdateCommand(s As Object, e As DataGridCommandEventArgs )
Dim conn As SqlConnection
Dim MyCommand As SqlCommand
Dim strConn as string = "server=Rajender;uid=sa;pwd=sa;database=NORTHWIND"
Dim txtFirstName As textbox = E.Item.cells(2).Controls(0)
Dim txtLastName As textbox = E.Item.cells(3).Controls(0)
Dim txtTitle As textbox = E.Item.cells(4).Controls(0)
Dim strUpdateStmt As String
strUpdateStmt =" UPDATE Employees SET" & _
" FirstName =@.Fname, LastName =@.Lname, Title = @.Title " & _
" WHERE EmployeeID = @.EmpID"
conn = New SqlConnection(strConn)
MyCommand = New SqlCommand(strUpdateStmt, conn)
MyCommand.Parameters.Add(New SQLParameter("@.Fname", txtFirstName.text))
MyCommand.Parameters.Add(New SQLParameter("@.Lname", txtLastName.text))
MyCommand.Parameters.Add(New SQLParameter("@.Title", txtTitle.text))
MyCommand.Parameters.Add(New SQLParameter("@.EmpID", e.Item.Cells(1).Text ))
conn.Open()
MyCommand.ExecuteNonQuery()
MyDataGrid.EditItemIndex = -1
conn.close
BindData
End Sub

</ code >
In that case, you could declare EditItemTemplate for the DataGrid (declaratively in asox) in which you set the TextBox's MaxLength.

If you want to do it programmatically, then you'd do it in ItemDataBound method (when ItemType is EditItem)

Wednesday, March 21, 2012

Please help itemcommand event for a datagrid checking wether the field is blank or not

Please help, I have a problem validating the date field.

When ever if the date field is blank i want to raise the Jscript, But it does'nt work.

Only with date i have the problem rest all fields work excellent, if they are blank it does show the javascript message.

Following code is used under the itemcommand of the datagrid.

txtid = e.Item.FindControl("eventid_add")
txtdate = e.Item.FindControl("eventdt_add")
txtref = e.Item.FindControl("eventref_add")

If txtid.Text <> "" And txtdate.Text <> "" And txtref.Text <> "" Then
'do this
Else
'javascript popup
Dim AlertScript As String
AlertScript = "<script language='javascript'>" & _
"alert('Event Date and Reference No. are required!')" & _
"</script>"
Page.RegisterStartupScript("AlertScript", AlertScript)
End If

Thank you very much for the information.Try doing this on the OnItemDataBound event. During OnItemCreated the data is not bound to the datagrid yet, so it is not accessible.

And if it still doesn't work, try to access the data in the datasource(still during OnItemDataBound), not the datagrid; (my example is C#, but you should get the picture)


if (DataBinder.Eval(e.Item.DataItem, "eventdt_add" == DbNull.Value) {
//do your thing
}

Friday, March 16, 2012

Please help me with this.....

Hello. My name is Shwetha. I'm new to the field of Software. I wanted to know what .NET does. I know what programs are. I'm becoming familiar with programs such as C... So before i staat learning .NET , it would be of great help to me if anyone could explain to me what .NET is , how it works and in which field is it implied.

The information you want is under the Learn and Get Started links on the menu at the top of the page.

Jeff


http://en.wikipedia.org/wiki/Microsoft_.NET


.Net is a huge thing.

In broader terms it is a technology from Microsoft whose Aim is to covers things under common platform.

All language gets converted into intermediate code which produce machine code on demand.

Just go for it.

Go to home page of of asp.net and have a look on some of starting video tutorials.


you can check msdn.microsoft.com and my site too.