Problem in getting value from textbox & radiobuttonlist to a valua

G

Guest

Problem in getting value from textbox & radiobuttonlist to a valuable inside
a datagid.

I want to insert a record into a table thru datagrid. Here is the code (see
below)

Private Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
DataGrid1.ItemCommand

Select Case e.CommandName

Case "rate_it"

If ((e.Item.ItemType <> ListItemType.Header) And (e.Item.ItemType <>
ListItemType.Footer)) Then

DocumentID = Convert.ToInt32(e.Item.Cells(7).Text)



Dim UserIP As String
UserIP = CStr(Request.UserHostAddress)

Dim comments As String
Dim TB As TextBox
TB = CType(e.Item.FindControl("TestBox1"), TextBox)
comments = TB.Text >>>>>>>>>>>>>>>>>>>>>>>>>>> Object reference not set to
an instance of an object. !!!!!!!!!!!!!!!!!!!!!!!!!!here is where I get
error!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Description: An unhandled exception occurred during the execution of the
current web request. Please review

Dim rate As String

Dim RBL As New RadioButtonList
RBL = CType(e.Item.FindControl("RadioButtonList1"), RadioButtonList)
rate = Request.Form("RadioButtonList1")

Dim conPubs As SqlConnection
Dim cmdIns As SqlCommand
conPubs = New SqlConnection("server=BGLAMDJVELU;Database=Pubs;Integrated
security=sspi")
cmdIns = New SqlCommand("INSERT INTO tbl_rating (rating, ip, documentID,
usercomment) VALUES (" & rate & " ,'" & UserIP & "'," & DocumentID & ",'" &
comments & "');", conPubs)
conPubs.Open()
cmdIns.ExecuteReader()
conPubs.Close()

End If

End Select

Pls help me I have been working for more than 5 days

Thx
Jk
 
K

Karl Seguin

The error seems straighforward. There is no TextBox1 for that item...
Check out what e.Item.ItemType is when you get that error...I bet it isn't
what you expect....maybe something like PageTemplate or soemthing...try
changing your if statement to

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListITemType.AlternateItem)

if that doens't work, like I said, it seem slike something wrong w/your
html..

Karl
 
G

Guest

ya i did try to change the if statment but no use. i dont see anything wrong
in the HTML part.

in fact i get value for UserIP and rate DocumentID. some how i need to store
the rate and Comments....

any thoughs ?
 
K

Karl Seguin

It is possible that TestBox1 is embedded within another control, in this
case you'd need to do
e.Item.FindControl("parentControl').FindControl("TestBox1")

Karl
 
G

Guest

Yes i did try that

e.Item.FindControl("panel1").FindControl("TestBox1") still i get "0"

I wonder we are somewere near. :-(
 
K

Karl Seguin

You might need to start debugging your code, simplifying your html and stuff
:)

Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top