Problem in getting value from textbox & radiobuttonlist to a valua

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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
 
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 ?
 
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
 
Yes i did try that

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

I wonder we are somewere near. :-(
 
Back
Top