Problem with Drop Down List

F

fazee.ent

i am using a drop down list and have sucessfuly populated it proble is
this i have set
DataValueField = "cat_id" but value for dropdownlist appears a string
"cat_id" instead of numer value of cat_id

plz help me

Faisal Iqbal Ch
 
F

fazee.ent

*****************
Data binding Code
*******************
Const strSQL2 as String ="SELECT * FROM book_cat"
Dim objCmd2 as New SqlCommand(strSQL2, objConn)

objConn.Open() 'Open the connection

cmbcat.DataSource =
objCmd2.ExecuteReader(CommandBehavior. CloseConnection)
cmbcat.DataBind()


****************
Insertion Code
****************

sql="INSERT INTO book_cat_sub
(cat_name,cat_keywords,cat_head)VALUES('" & txtname.Text & "','" &
txtkeywords.Text & "',"& cmbcat.DataValueField & ")"

dbcomm=New OleDbCommand(sql,dbconn)
dbread=dbcomm.ExecuteReader()

dbread.Close()
dbconn.Close()



****************
Drop Down Lis code
****************

<asp:DropDownList id="cmbcat" runat="server" DataTextField="cat_name"
DataValueField="cat_id" ></asp:DropDownList>
 
F

fazee.ent

*****************
Data binding Code
*******************
Const strSQL2 as String ="SELECT * FROM book_cat"
Dim objCmd2 as New SqlCommand(strSQL2, objConn)

objConn.Open() 'Open the connection

cmbcat.DataSource =
objCmd2.ExecuteReader(CommandBehavior. CloseConnection)
cmbcat.DataBind()


****************
Insertion Code
****************

sql="INSERT INTO book_cat_sub
(cat_name,cat_keywords,cat_head)VALUES('" & txtname.Text & "','" &
txtkeywords.Text & "',"& cmbcat.DataValueField & ")"

dbcomm=New OleDbCommand(sql,dbconn)
dbread=dbcomm.ExecuteReader()

dbread.Close()
dbconn.Close()



****************
Drop Down Lis code
****************

<asp:DropDownList id="cmbcat" runat="server" DataTextField="cat_name"
DataValueField="cat_id" ></asp:DropDownList>
 
D

David Lozzi

Can you look at the page source of the returned page and see if the value of
the list items in then drop down box is also cat_id?
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top