Jump to content
Xtreme .Net Talk

calvin

Avatar/Signature
  • Posts

    72
  • Joined

  • Last visited

Everything posted by calvin

  1. I create a data entry page which contain a lot of textbox and using required field validator. So, when required field is not enter, error message will appear. My problem is the page also include a datagrid and bind with bound column and button column. The button column combine Edit & Delete button. When click on the button, the required field validator is activate. User cannot perform edit or delete command until all required fields are enter. How can i set the Causes Validation of Edit/Delete button to "False" since it can be done in form button. I didn't see properties of datagrid allow to set. Appreciate for those giving comments and help. Thanks Calvin
  2. Got Solution Code behind Response.Write("<script>var timeServer = new Date('" + DateTime.Now.ToString() + "');</script>"); Client Side code <script type="text/javascript"> //Users time var timeLocal = new Date(); //Calculate the difference (returns milliseconds) millDiff = timeLocal - timeServer; //initalize the clock on loading of page window.onload=function(){ //set the interval so clock ticks var timeClock=setInterval("TimeTick()",10); } //The ticking clock function function TimeTick(){ //grab updated time timeLocal = new Date(); //add time difference timeLocal.setMilliseconds(timeLocal.getMilliseconds() - millDiff); //display the value document.getElementById("spanTime").innerHTML =timeLocal; } </script> <span id="spanTime"></span>
  3. Hi, I'm doing an attendance system and face a problem to get the server time show in javascript. It was an error since the server time is not same as the local time. This problem occurs when user click the button and get server time add to database, it is no problem save the time to database, but it will confuse :confused: the user if local time is not same as the server time. Anyone have an idea or snippets to solve the problem. I got a lot of sample code of javascript by all get in local time. I need it get from server time. A lot of people said javascript cannot do such function, but i believe that there are another approach to solve such problem. For those comments and suggestions will more appreciate. :) Calvin
  4. Problem Solved The solution solved my problem. Thanks for your help :D Calvin
  5. Hi, I get this error "datatype mismatch in criteria expression" in my sql query. One of datatype in my Acceess database is declare as "Number-Long Integer". This cause error occur while the datatype mismatch. I'm using asp.net with vbscript to code my page. In my sql query, there is a condition. CodeBehind: Dim strabc as (Integer/Long/Short/Single,Int32,Int64/Byte...)<- I had try all of this data type but still error! strabc = CType(textbox.text,Integer/...) Query = "Select * from table where abc = '" & strabc & "'" Microsoft Access Data Type: abc - Number-Long Integer It is easy to use if I declare abc in DB as "Text". IS ANYONE KNOW HOW TO SOLVE IT??? what should delare the variable in my code behind page?? Thank you very much Calvin
  6. I have a datagrid and allow to delete function. But before delete the record, I want to popup a message(using javascript alert message) to confirm to delete record. If user select "Yes" then, I want to call a server side function to check whether the record can be delete or not. So, my problem is start from calling the server side function using javascript. Is it possible to do that. If so, please give me a solution/help. Else any idea to solve the problem??? Below is part of my code to do the delete record command:- Private Sub Delete(ByVal Source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.DeleteCommand Dim strScript As String = "<SCRIPT language='javascript'>" & Environment.NewLine strScript = strScript + "if(confirm('Are you sure to delete?')){document.getElementById('" & txtbox.ID & "').value = 'Yes';***}else{document.getElementById('" & txtbox.ID & "').value = 'No';}" & Environment.NewLine strScript = strScript + "</script>" RegisterStartupScript("focus", strScript) Dim strLocationID As String = e.Item.Cells(2).Text If txtbox.Text = "Yes" Then 'Do a lot of coding here and call function Else ' Do nothing End If End Sub ***Notice the code in red color, it suppose to put inside a (serverside??)function and to be call by javascript function(notice the blue (*)marks), because it will run the code when page is rendered. Thank you for help and comments. Calvin
  7. Hi, I have use the following approach to hide/show a textbox when selecting particular item in dropdownlist. By which approach to give the user more convinient to enter data?? I had try to use this twol approach but unsuccessful. [Autopostback = False] I need to visible a textbox and RequiredFieldValidator when user select the item in dropdownlist before click the submit button. The visible of textbox & Validator are set to false. I want to call function in client script(Javascript) to call out the textbox. For example, If select item "Other", then the textbox is visible to enter data. The control to validate of requiredfieldvalidator is set to this textbox. Other than that item will hide the textbox & validator. I using ASP.NET with VB to do the data entry form. As I know, If we set server-side Visible property to false, ASP.NET will not render control, So, Anyone know how to solve it and give me some sample code. [Autopostback = True] If we use the autopostback, it is take time to refresh the whole page, because I have a lot of dropdownlist with textbox in page. I found some forum, they recommend to use Mirosoft XMLHTTP ActiveX to refresh only the object not whole page when using ASP.NET 1.X. I know this problem has been solved in ASP.NET 2.0 by Callback Manager, but currently I'm using version 1.1 of framework. Lastly I'm very appriaciate for those who give me suggestion and help because I struggle this with long time. Thank you very much. Calvin :D
  8. Hi, I want to popup a dialog box to the user before delete the row in datagrid. I get some code from the internet, it was using "template column" to do the delete command. However, I was using "button column" instead of the previous one. This is the code get from Internet: Public Sub DataGrid1_ItemDataBound(ByVal s As Object, ByVal e As DataGridItemEventArgs) Dim l As LinkButton If e.Item.ItemType = ListItemType.EditItem Or e.Item.ItemType = ListItemType.AlternatingItem Then l = CType(e.Item.Cells(1).FindControl("btnDelete"), LinkButton) l.Attributes.Add("onclick", "return confirm('Are you sure you want to delete this item?');") End Sub My Problem is: In my "Delete" button column, the link button text has been replaced by image path. So, how can I get control to the link button? :confused: Thank for any help and suggestion. :) Calvin
  9. Hi, I got a problem of how to identify the cell was clicked in datagrid. In my datagrid, there are 10 template column and each column have a label and image button. I want to hide the label when user click the image button. I do not know which row of cell is clicked but column. I create a command to the button, for example: HTML: <asp:ImageButton id="btnEdit1" runat="server" ImageUrl=="../Images/Icon.gif" CommandArgument="1" OnClick="GetControl"></asp:ImageButton> CodeBehind(VB.NET) Public Sub GetControl(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.CommandEventArgs) Select Case "e.CommandArgument" Case "1" 'Column 1 Dim Label1 as Label = DataGrid1.item(??).FindControl("Label") Label1.visible = False Case "2" 'Column 2 ... End Select End Sub Notice the ??(row), how can I get it??????? I was struggle on this problem couple of day, appreciate for any help! :) Calvin
  10. I want to "Store" time into datetime datafield, not "Pull" time from DB. :)
  11. Hi, I want to store time into a datetime datafield in MS SQL Database, but eventually, it was include a date prefix the time ! I had try the approach on following and get the invalid result. Approach 1: Dim strTime as String = "11:59:59 AM" Output: 01-01-1900 11:59:59 AM Approach 2: Dim dtTime as DateTime = "11:59:59 AM" Output: 1/1/0001 11:59:59 AM <- (error occur: unable add to DB cause date is not between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM) * The time on the above is accompany with AM/PM. Approach 3: Dim strTime as String = "11:59:59 AM" Dim strStartTime2 = DateTime.ParseExact(strStartTime, "hh:mm:ss", System.Globalization.CultureInfo.CurrentCulture) Output: 01-01-1900 11:59:59 AM Approach 4: Dim strTime as DateTime = "11:59:59 AM" Dim strStartTime2 = DateTime.ParseExact(strStartTime, "hh:mm:ss", System.Globalization.CultureInfo.CurrentCulture) Output: String was not recognized as a valid DateTime. I know what cause the approach 4 get an error. That is because the strTime is declare as DateTime and that contain "AM/PM" in time. My Question: 1]Can I just insert the time only to the DB without date? 2]If possible, what should I delcare in the variable(String/DateTime/..?) 3]How can I deal with the "AM/PM"? It must concate with time to identify daytime/night If you know and have the solution, pls do me a favor and will be more appreciated. Thank you Calvin
  12. I would like to create an object(like label) on each column of datagrid(create column in runtime). I was get an error of "Object reference not set to an instance of an object" in my code. Code: For i = 1 to ... Dim _templateColumn As TemplateColumn _templateColumn = New TemplateColumn _templateColumn.HeaderText = i.ToString("00") Dim lblRegistered As Label = New Label lblRegistered.ID = "lblResult" & i _templateColumn.ItemTemplate.InstantiateIn(lblRegistered) *Error here Controls.Add(lblRegistered) DataGrid1.Columns.Add(_templateColumn) Next Is there any error in my code? Please let me know if you found it. Appreciate for those who give the solution and comments. Thank you. Calvin
  13. Hi, I have a paging datagrid and set the page size to 20. One of the template column consists of textbox. I want to get the child control to the textbox. It was successfully getting the child control on the first 20 record(datarow), but other than that. Let me explain my circumstance: If there are 100 record bind to the datagrid, the first 20 record will be get child control, just because the page size has been set to "20" For those who are given solution and reference will be more appreciated. Thank you Calvin
  14. I got a big problem of my connection string to be shown on the page, where the connection string is store in the web.config. This problem are occurs occasionally, which is loading data to the page. It also happen the connection string shown in the dropdownlist. Is anyone know what make this happens?For any help with more appreciated. Calvin
  15. Oh, I know what's wrong. We use same (i) as integer with For loops. So replace "i" to "j".However still have some error
  16. You are right, first value of item.Cells(0).Text in blank. But I store the value to the UniqueIDList(i) is when the checkbox was checked and also being disable.
  17. No value in item.Cells(0).Text is blank, I did check for it. Like this For.... UniqueIDList(i) = item.Cells(0).Text Response.Write(UniqueIDList(i)) Next But If I show the sID, it must show the comma from the begining
  18. Oh, I put wrong IDFieldName in the "YourIDField". But I still get same error of Syntax error: Missing operand before ',' operator. As I mentioned above, I try to show the string of sID, it show like below: Output: ,abc0001,abc0003,abc0004 I believe that the comma in the begining cause the error. How can I remove that? I had try to used one of the UniqueID like below and successfully get the result. dv.RowFilter = "UniqueID <> 'abc0001'" So, how can I solve this problem? Calvin
  19. I got this error: Syntax error: Missing operand before ',' operator. So, I check the sID -> Response.Write(sID) It was a comma prefix the uniqueID. For Example: ,UniqueID,Unique Then I try to remove the comma in join funtion like this sID = String.Join("", UniqueIDList) And get this error: Cannot find column [YourIDField].
  20. Can we use other as delimeter instead of comma?
  21. Syntax error: Missing operand before ',' operator. dv.RowFilter = sID I think this is made error -> sID = String.Join(",", UniqueIDList)
  22. error again: Object reference not set to an instance of an object. UniqueIDList(0) = item.Cells(0).Text
  23. I get an error on sID= UniqueIDList.Join(",") Error Message: 'Join' is not a member of 'System.Array' Dim UniqueIDList() as String For.... 'UniqueIDList(0) = item.Cells(0).Text Next ------------------------------------------------------------------------- Is UniqueIDList declare correctly on the above?(declare as String?) How to do the looping for UniqueIDList. Dim j as integer = 0 For.. UniqueIDList(j) = item.Cells(0).Text j += 1 Next Calvin
  24. Private Sub btnHide_Click(.....) ---------- ---------- 'Get the indentifier of the records you want to exclude ** The identifier will be the checkbox(checked & disable) If cb.Checked = True And cb.Enabled = False Then 'Get the values from the Grid and store in a variable ???Store all values to variable?? Dim strName as String = item.Cells(1).Text Dim strDOB as String = item.Cells(2).Text Dim strGender as String = item.Cells(3).Text End If 'Considering you have populate a variable - NameList ' which contains the comma seperated names to be excluded ???what's the comma make??? ' Retrieve the data source from session state. Dim dt As DataTable = CType(Session("Source"), DataTable) ' Create a DataView from the DataTable. Dim dv As DataView = New DataView(dt) 'Now fileter the record in DataView and bind it to DataGrid dv.RowFilter = "Name Not In '" & NameList & "%'" <-???(filter the names that start with text in variable "NameList??? dv.RowFilter = strName dv.RowFilter = strDOB dv.RowFilter = strGender DataGrid1.DataSource = dv DataGrid1.DataBind() End Sub Calvin
  25. Function BindTable() sqlQuery = "Select Name, DOB, Gender from PersonalDetails" cn.Open() Dim da As New SqlDataAdapter(sqlGetCandidateDetails, cn) dt = New DataTable("PersonalDetails") da.Fill(dt) DataGrid1.DataSource = dt DataGrid1.DataBind() cn.Close() Dim i As Integer = 0 Dim item As DataGridItem Dim cr As DataRow For Each cr In dt.Rows item = DataGrid1.Items(i) Dim cb As CheckBox = CType(item.FindControl("cb"), CheckBox) If cr.Item("Gender") = "M" Then cb.Checked = True cb.Enabled = False End If Next End Function Private Sub btnHide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHide.Click Dim i As Integer Dim item As DataGridItem Dim cb As CheckBox For i = 0 To DataGrid1.Items.Count - 1 item = DataGrid1.Items(i) cb = CType(item.FindControl("cb"), CheckBox) If cb.Checked = True And cb.Enabled = False Then '**************************** ' How to DataView to hide row ?? Dim dv As DataView ? ? ? End If Next End Sub Calvin
×
×
  • Create New...