Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Where Am I Going Wrong??????

Status
Not open for further replies.

arpan

Programmer
Oct 16, 2002
336
IN
I want to populate the records existing in SQL Server DB table in a DropDownList. This is what I have done:

<script language=&quot;VB&quot; runat=&quot;server&quot;>
Sub Page_Load(obj As Object,ea As EventArgs)
Dim objDS As DataSet
Dim objConn As SQLConnection
Dim objDapter As SQLDataAdapter

objConn=New SQLConnection(&quot;Server=(local);Database=DBName;UID=sa;PWD=&quot;)
objDapter=New SQLDataAdapter(&quot;SELECT CName,FDate FROM Company ORDER BY CName,FDate&quot;,objConn)
objDS=new DataSet()
objDapter.Fill(objDS,&quot;Comp&quot;)

cname.DataSource=objDS.Tables(&quot;Comp&quot;).DefaultView
cname.DataBind()
End Sub
</script>
<body>
<form runat=&quot;server&quot;>
<asp:DropDownList id=&quot;cname&quot; runat=&quot;server&quot;>
<asp:ListItem>
<%# Container.DataItem(&quot;CName&quot;) & &quot; &quot; & Container.DataItem(&quot;FDate&quot;) %>
</asp:ListItem>
</asp:DropDownList>
</form>

But I am getting an error which says &quot;Code blocks are not supported in this context&quot; which points to the <%#
Container.DataItem..........%> line. Where am I erring? How do I rectify it?

Thanks,

Arpan
 
I assume that you want to display something like this:
xxxx 12/16/02
yyyy 12/15/02

If so,

In the sql statement, try this:

objDapter=New SQLDataAdapter(&quot;SELECT CName + ' ' + FDate as NameDate FROM Company ORDER BY CName,FDate&quot;,objConn

Try this in the DropDownList section:

<asp:DropDownList
Runat=&quot;server&quot;
Id=&quot;cname&quot;
DataTextField=&quot;NameDate&quot; />

Hope this helps...
Regards,
Poornima
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top