Monday, March 12, 2012

Want TitleID to go into Database instead of title(name)

Could someone assist me. I'm using a tree view. I have the Title being displayed which is fine. I then want the selected title to go over to another page and into a text box which again is fine. This is how I'm sending it over:

Response.Redirect("RequestForm.aspx?TitleID=" & TreeView1.SelectedValue)

On the RequestForm.aspx page load section I have this:

TitleTxt.Text = Request.QueryString("TitleID")


I have this for my button click:
.CommandText ="AddLoanRequest"'

.Parameters.AddWithValue("@dotnet.itags.org.RequestorEmail", EmailAdd.Text)

.Parameters.AddWithValue("@dotnet.itags.org.TitleID", TitleTxt.Text)

How do I get just the title ID to go into the database. Right now it's going in as the title ("name") but I only want the Title ID

Here's AddLoanRequest Stored Procedure

@dotnet.itags.org.RequestorEmail varchar (75),
@dotnet.itags.org.TitleID varchar(255),

AS

INSERT INTO Requestors(RequestorEmail,TitleID)

values

(@dotnet.itags.org.RequestorEmail,
@dotnet.itags.org.TitleID)

Thanks for your help

It appears to me that you're setting the ValueField of nodes in the tree with the text value. You should set it with the ID value, then send both the TextField and ValueField in queryString.

Set your textBox with the textfield and give your storedprocedure the ID.


.Parameters.AddWithValue("@.TitleID", Request.QueryString("TitleID")) ??


Hello JJ297,

Is it possible that the treeview doestn't have the correct values?

E.g. the treeviewitem value contains the TitleText in stead of the TitleID.

Jeroen Molenaar


I looked it over and I believe it has the correct value. Here's the tree view

Dim daClassificationsAsNew Data.SqlClient.SqlDataAdapter

Dim sqlcomAsNew Data.SqlClient.SqlCommand

With sqlcom

.Connection = myconn

.CommandType = CommandType.StoredProcedure

.CommandText ="GetClassifications"

EndWith

daClassifications.SelectCommand = sqlcom

Dim sqlcom1AsNew Data.SqlClient.SqlCommandWith sqlcom1

.Connection = myconn

.CommandType = CommandType.StoredProcedure

.CommandText ="GetListing"

EndWith

Dim daTitleAsNew Data.SqlClient.SqlDataAdapter

'Dim daMedia As New Data.SqlClient.SqlDataAdapter

daTitle.SelectCommand = sqlcom1

Dim dsFaqAsNew dsFaw

daclassifications.Fill(dsFaq,"Classifications")

daTitle.Fill(dsFaq,"TitleID")

dsFaq.Relations.Add("TopToQues", dsFaq.Tables("Classifications").Columns("ClassificationID"), dsFaq.Tables("TitleID").Columns("classificationid"))

Dim nodeTop, nodeClass, nodeTitleAs TreeNode

Dim rowTop, rowClassAs DataRow

ForEach rowTopIn dsFaq.Tables("classifications").Rows

nodeTop =New TreeNode

nodeTop.Text = rowTop("description")

TreeView1.Nodes.Add(nodeTop)

ForEach rowclassIn rowTop.GetChildRows("TopToQues")

nodeClass =New TreeNode

nodeClass.Text = rowClass("Title")

nodeTop.ChildNodes.Add(nodeClass)

nodeTitle =New TreeNodenodeTitle.Text = rowClass("description")

nodeClass.ChildNodes.Add(nodeTitle)

nodeTitle =New TreeNode

nodeTitle.Text = rowClass("quantityowned")

nodeClass.ChildNodes.Add(nodeTitle)

Next

Next

EndIf

EndSub

ProtectedSub TreeView1_SelectedNodeChanged(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles TreeView1.SelectedNodeChanged

Response.Redirect("RequestForm.aspx?TitleID=" & TreeView1.SelectedValue)

'Response.Redirect("default.aspx?nodeclass.text =" & TreeView1.SelectedValue)

EndSub


I tried your code of line but the title is still going into the databaseConfused


I'm not sure but I think you should be setting the value of nodes as well as the text.

i.e.nodeClass.Value = rowClass("TitleID_FieldName").

Then you should be passing both the Text and the Value to the next page, set the textbox with the text, and give the ID to the procedure.


I tried the

nodeClass.Value = rowClass("TitleID_TitleTxt") but all id does now is change my value to the TitleID instead of listing my titleConfused


Here's what I want you to do:

For tree nodes, you set both: nodeClass.Value = rowClass("IDColumnName") and nodeClass.Text=rowClass("TitleTxtColumnName");

Then you do this to redirect to the RequestForm page:

Response.Redirect("RequestForm.aspx?TitleID=" & TreeView1.SelectedNode.Value &"&TitleText=" & TreeView1.SelectedNode.Text)

'On the RequestForm.aspx page load section you have this:

TitleTxt.Text = Request.QueryString("TitleText")

'for your button click:

.CommandText ="AddLoanRequest"'

.Parameters.AddWithValue("@.RequestorEmail", EmailAdd.Text).Parameters.AddWithValue("@.TitleID",Integer.Parse(Request.QueryString("TitleID")))


Thanks so much Ania it worked (you knew that anyway). Glad you could help me out.


Great :)


Another question for you...how do I add check boxes to the tree node?


Set the ShowCheckBoxes property of the tree with the desired value:

TreeView1.ShowCheckBoxes = TreeNodeTypes.All

0 comments:

Post a Comment