Hello Everyone,

I need help in this issue and if I solve it, I will solve all of my problems in the web program I am building. I have a list of cateogries where I can do 2 things: Start a new list under that category (list of sub categories) and there is no issue with that and second is edit the name of that category and this is where I have the issue. You see When I click on a certain category (no matter its position) I can locate that category via its ID number. Therefore, I direct the user to a page let's say, Edit.aspx?ID=##, in that file, I build my form and my issue is I can retrieve the value of the chosen category but I can't place its value inside the following element:

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

to update the database when the user clicks on the save button. Is there a way to update the asp.net textbox via calling a sub and returning a value? You see it is important to do it this way because When having many elements in a single form, it would be a hastle and black work to build the asp.net controls in a Sub / Function which by the way, it did not work out for me also. I tried the below but it did work. It gave the actual code as the text value. Maybe you can understand my direction through the below code:

Sub that reads from the database by getting the ID through request.querystring (a classic ASP command), and then return the value of the category. Inside my aspx file, I set the following

<asp:TextBox ID="TextBox1" runat="server" text="<%=ID%>></asp:TextBox>

Just above it I do the following

<%
ID = callingsub()
%>

I tried using ID = CallingSub() in the asp classic tags

<%
ID = CallingSub()
%>

But I used the TextBox1.Text = ID inside the aspx.vb file inside my function / sub. Below is what I mean:

Suppliers.aspx file:

<%

DisplaySupplier()

%>

<asp:TextBox ID="EditItem" CssClass="InputText" runat="server" direction="rtl"></asp:TextBox>

Suppliers.aspx.vb file:

Public  Sub DisplaySupplier()

Dim Item As String = ""
Dim Id As Integer
Dim mainId As Integer
Dim Level As Integer

Id = Request.QueryString("Id")
mainId = Request.QueryString("mainId")
Level = Request.QueryString("Level")

If mainId.ToString Is Nothing Then
mainId = 0
End If

If Level.ToString Is Nothing Then
Level = 1
Else
Level = Level + 1
End If


Dim dr As System.Data.SqlClient.SqlDataReader

Dim sql As String = "SELECT * FROM tblSuppliers WHERE Id = " & Id

Dim SQLConn As SqlConnection = New SqlConnection(SetSQLConnection())

SQLConn.Open()


Try

Dim command As New SqlCommand(sql, SQLConn)
dr = command.ExecuteReader


While dr.Read()

  Item = dr("Item").ToString()
  EditItem.Text = Item


End While

Catch


End Try


dr.Close()
SQLConn.Close()

dr = Nothing
SQLConn = Nothing


End Sub

Am I missing something here? This also does not work for the password field.

Thanks

Awny

another way to retrieve just one value from the database is using the executescalar method.
in that case you will add after this line

Dim commando As New SqlCommand(sql,SQLConn)
SQLConn.Open()
EditItem.Text = commando.ExecuteScalar().ToString()
SQLConn.Close()

ExecuteScalar return an object. so maybe you want to check if that object is not null first.
Try that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.