Jump to content
Xtreme .Net Talk

esposito

Avatar/Signature
  • Posts

    107
  • Joined

  • Last visited

Everything posted by esposito

  1. Hello, I need to pass a value stored in a Label from one page to another and I only know how to do it if the receiving page is not a popup one. The VB.NET code I use is the following: Dim MyValue As String MyValue = lblValue.Text Response.Redirect ("newpage.aspx?ID=" & MyValue) I can also open a popup page using the following javascript: Dim sScript As String sScript = "<script>window.open('newpage.aspx','','height=100','width=100','scrollbars=no');<" & "/script>" Response.Write(sScript) What I can't do is modify the javascript code above in such a way as to get the value from the Label and pass it to the popup page. Any help will be greatly appreciated.
  2. Hello, I have a serious problem with a datagrid control that is bound to an Access database. I have put my database in a subfolder of the "admin" folder called "datastore". Inside the "admin" folder, I have also put another folder called "attachments". In a field of my Access database, I have stored the path of my attached files that I upload onto the server when I log on as a designer. This is the code I have used in the upload button: Sub btnLoad00_Click(sender As Object, e As EventArgs) If Not (fileControl00.PostedFile Is Nothing) Then Try Dim FileDest As String Dim myPath As String = fileControl00.value Dim myFileName As String = System.IO.Path.GetFileName(myPath) FileDest = "attachments" & "/" & myFileName hypFileDest.Text = (Server.MapPath(FileDest)) fileControl00.PostedFile.SaveAs((hypFileDest.Text)) End If End Sub As you can see, I add the folder name ("attachments") to the uploaded file name, so I can keep track of the entire path. Now, I have bound two datagrids to my database, one is in the "admin" folder and the other is in the root folder. Each datagrid contains a hyperlink field to the attached file. In the datagrid in the "admin" folder I have no problem launching the attached file when I click on the hyperlink, because the path retrieved from the database is correct. Unfortunately, the datagrid in the root folder does not allow me to launch the attached files, because the path I click on does not contain the "admin" subfolder name. So, my question is, how can I intervene in the datagrid in the root folder so that when I click on the hyperlink field I can add "admin" before the path retrieved from the database? The code I use to populate my datagrid is the following: Dim MySQL as string = "Select * from mytable" Dim myConn As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & server.mappath("datastore/database.mdb") & ";") Dim ds as DataSet=New DataSet() Dim Cmd as New OleDbDataAdapter(MySQL,MyConn) Cmd.Fill(ds,"mytable") dgTabella.Datasource=ds.Tables("mytable").DefaultView dgTabella.DataBind() MyConn.Close() Any help will be greatly appreciated. TIA
  3. Problem solved, thank you anyway: DataGrid1.Items.Count
  4. Hello, I'm new to datagrid management and I would like to know how I coud get the total number of items shown in a datagrid. Any help will be appreciated. TIA
  5. How would you transform my search function using parameters?
  6. Dear VBAHole22, I managed to sort out my problem with a single line of code, which runs as follows: Dim mykeyword As String = Replace(txtKeyWord.Text, "'", "''") You don't need to use the same Replace function in input. Placing it in output is enough to avoid any trouble. Try to believe.
  7. Hello, I have a datagrid control bound to an Access database. To populate the datagrid, I use the following code: Dim mykeyword As String = Replace(txtKeyWord.Text, "'", "''") Dim MySQL as string = "Select * from employees WHERE surname = '" & mykeyword & "' Order by id_employee" Dim myConn As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & server.mappath("employees.mdb") & ";") Dim ds as DataSet=New DataSet() Dim Cmd as New OleDbDataAdapter(MySQL,MyConn) Cmd.Parameters(0) = myKeyword Cmd.Fill(ds,"employees") myDataGrid.Datasource=ds.Tables("employees").DefaultView myDataGrid.DataBind() MyConn.Close() What I would like to do is add a hyperlink field to the datagrid that will allow me to delete the selected record. In WebMatrix (the IDE that I use) it is very easy to transform a field into a hyperlink. What I can't do, as I said, is delete the current record when I click on that hyperlink. I know it is possible because I have seen a datagrid control implementing that function. Any help will be appreciated.
  8. Thanks. I'll do some research into how to use parameters.
  9. Hello, I have a serious problem dealing with database interrogation through SQL statements. To interrogate my database of employees by surname, I use the following code: Dim mykeyword As String = txtKeyWord.Text Dim MySQL as string = "Select * from employees WHERE surname = '" & mykeyword & "' Order by id_employee" Dim myConn As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & server.mappath("employees.mdb") & ";") Dim ds as DataSet=New DataSet() Dim Cmd as New OleDbDataAdapter(MySQL,MyConn) Cmd.Fill(ds,"employees") myDataGrid.Datasource=ds.Tables("employees").DefaultView myDataGrid.DataBind() MyConn.Close() Now, the problem arises when the user types one or more apostrophes (') in the TextBox for the keyword. The apostrophes interfere with the SQL string and the search simply fails. I suppose I should check the content of the textbox before executing the query, to make sure there are no invalid characters, but I don't know how to look for a specific character in a string and replace it. Besides, I think that it would be absurd to prevent the user from typing apostrophes because that character is so common that it would become a serious limitation. I suppose I am not the first person who has encountered such a problem, so if you know the solution, please help me. Thanks in advance.
  10. I tried to use the second method you suggested (embedding the parameter in the javascript code). All I got was a popup window showing an error message (the resource cannot be found). Probably that javascript code is not a good substitute for the Response.Transfer method. Unfortunately, I did not suceed in implementing the first method either. I'm afraid I would need more info on how to proceed. Question: is there any way I could put the javascript code in the Page_Load event of a .aspx page to open it as a popup page? In that way, I could use normal VB.NET code in the calling form. TIA
  11. Hello, I would like to open a popup page in ASP.NET (VB.NET) transporting a value from the calling form to the popup page. Now, to tranfer a value from a page to another, first I declare the classes for the values to be exported and then I use the following code: Server.Transfer ("newwin.aspx?AccessKey=" & "mykey") To get a popup page, I use the following Javascript: Sub btnPopup_Click(sender As Object, e As EventArgs) Dim sScript As String sScript = "<script>window.open('newwin.aspx','','height=100','width=100','scrollbars=no');<" & "/script>" Response.Write(sScript) End Sub What I can't do is get both functions at the same time, i.e. I can't export a value to a popup page. Any help will be appreciated.
  12. Thank you very much indeed for your replies. The problem is now solved. It was only the web master who told me he had removed the protections from the .mdb file and he didn't. You are right when you say that port 80 is all I need to make my app work. Thanks again.
  13. Hello everybody, I badly need your help. I have created an MDB database using Web Matrix and VB.NET and on my computer it works fine. I have then uploaded my ASP.NET pages onto the server but when I try to save data I get an error message, despite all the protections have been removed from the .MDB file. The server web master asked me to tell him which port ASP.NET files use, so he can open it. He told me this port cannot be nr. 80 because it is already open. Any help will be greatly appreciated.
  14. Problem sorted out. Thank you anyway.
  15. I have managed to update an existing record in the database by adding an ID field to the XML file, which now looks as follows: <News_Database> <My_News> <ID>1</ID> <news1>First News A</news1> <news2>Second News A</news2> </My_News> <My_News> <ID>2</ID> <news1>First News B</news1> <news2>Second News B</news2> </My_News> <My_News> <ID>3</ID> <news1>First News C</news1> <news2>Second News C</news2> </My_News> </News_Database> This is the code I have used to update the record. Sub btnUpdateRecord_Click(sender As Object, e As EventArgs) Dim objDataSet As New System.Data.DataSet Dim count As Integer objDataSet.ReadXml(Server.MapPath("news.xml"), XmlReadMode.Auto) count = objDataSet.Tables(0).Rows.Count Dim i As Integer For i = 0 to count - 1 If objDataSet.Tables(0).Rows(i).Item("ID") = txtID.Text Then objDataSet.Tables(0).Rows(i).Item("news1") = txtNews1.Text objDataSet.Tables(0).Rows(i).Item("news2") = txtNews2.Text objDataSet.WriteXml("news.xml") End If Next End Sub I would very much like to know if and how it is possible to DELETE a record from the database, if possible modifying the code above. Any help will be greatly appreciated.
  16. Hello, I need your help. I have created a very simple XML file, called "news.xml", structured in the following way: <News_Database> <My_News> <news1>First News A</news1> <news2>Second News A</news2> </My_News> <My_News> <news1>First News B</news1> <news2>Second News B</news2> </My_News> <My_News> <news1>First News C</news1> <news2>Second News C</news2> </My_News> </News_Database> In order to populate the XML file above, I use the following code: Sub btnSaveRecord_Click(sender As Object, e As EventArgs) Try Dim objDataSet As New System.Data.DataSet objDataSet.ReadXml("news.xml") Dim News1_Var As String Dim News2_Var As String News1_Var = txtNews1.Text News2_Var = txtNews2.Text Dim v(1) As String v(0) = News1_Var v(1) = News2_Var objDataSet.Tables(0).Rows.Add(v) objDataSet.WriteXml("news.xml") Dim count As Integer objDataSet.ReadXml(Server.MapPath("news.xml"), XmlReadMode.Auto) count = objDataSet.Tables(0).Rows.Count lblRecordNumber.Text = count / 2 Catch ex As Exception Exit Sub End Try End Sub As you can see, I have used a Label (lblRecordNumber) to keep track of the current record number. This number could be referred to as an ID when you want to search for a record. Now, my question is, is there any way I can update or delete a record from the database? TIA
  17. Hello, I would like to store records in an XML file called news.xml. The language I use is ASP.NET (VB). The database name is News_Database, whereas the record name is News. Each record contains two fields called news_title and news_text. The code I used is the following. Sub btnSaveRecord_Click(sender As Object, e As EventArgs) Dim myWriter As New XmlTextWriter (Server.MapPath("news.xml"), Nothing) Try myWriter.Formatting = Formatting.Indented myWriter.WriteStartDocument() myWriter.WriteStartElement("News_Database") myWriter.WriteStartElement("News") myWriter.WriteStartElement("news_title", "") myWriter.WriteString(txtNewsTitle.Text) myWriter.WriteEndElement() myWriter.WriteStartElement("news_text", "") myWriter.WriteString(txtNewsText.Text) myWriter.WriteEndElement() myWriter.WriteEndElement() myWriter.WriteEndDocument() myWriter.Flush() myWriter.Close() Catch myWriter.Close() End Try End Sub Unfortunately, the code above only allows me to store one record. If I insert new data in the textboxes and click on the button, the existing record is overwritten with the new data. Do you know how to modify my code in order to add a new record to the XML database instead of overwriting the existing one everytime I click on the button? TIA
  18. Thanks, everybody. So, the problem with the SetFocus method has now been solved. I have tested it and found it works perfectly. And what about the second issue? Do you know how to trap the Enter key while typing in a textbox and make it act as if it were a Tab? Thanks again.
  19. PROBLEM SOLVED! Thank you.
  20. Do you know the Javascript code that can solve my problem?
  21. Dear shahab, I have set the TabIndex property to 1 for TextBox 1 and to 2 for TextBox2. Then I have a button whose TabIndex is set to 3. In spite of this, if I press Enter when the focus is on TextBox1, the Click event of the button is executed. How could I amend this problem? TIA
  22. Dear Arch4ngel, I'm not talking about Windows forms but Web forms and, as far as I know, the Focus() method and the onKeyPress event do not exist when dealing with server controls. Please correct me if I am mistaken.
  23. Hello, I'm new to ASP.NET. I'd like to know if it is possible, while you are typing in a textbox, to set the focus to the next textbox pressing Enter on the keyboard. Any help will be appreciated. TIA
  24. Thank you for your reply. I know I may be asking too much, but please could you give me a step-by-step example of how to create and call the Javascript function you suggested? Unfortunately, I'm new to Javascript. TIA
×
×
  • Create New...