Click to See Complete Forum and Search --> : Access var in aspx page inside of <asp: tag


stonkers
03-13-2006, 10:44 PM
I'm trying to pass an argument to an aspx page to use inside of a <asp:AccessDataSource> tag. Here's the section in the from page (note that I'm in a cell of a calendar in the codebehind):

while (dbReader.Read())
{
e.Cell.Text = "<br><font size = 1px>myLink<a href=myDisplay.aspx?myVar=&quot;" + myVar + "&quot; target=&quot;_blank&quot;></a href></font>";
}


Then in the aspx page I'm calling:

<asp:AccessDataSource id="AccessDataSource" runat="server" DataFile="~/myDB.mdb"
SelectCommand = "select myColumn from t_myTable where eventID=<THISisWHEREiNEEDmyARGUMENT>" />

Any help?

Thanks,
Eric

takkie
03-14-2006, 03:17 PM
where is your eventID stored? is taht a date? or is it that myVar that you have within the DBReader.read??

Assuming its the myVar within your dbreader.read.... do this, SelectCommand= '<%# getSqlStr() %.'.

then in your aspx page, create a function, either public or protected (i think private wont work), called getSqlStr().... and make it do this,

return "select blah from tbl where id = '" & request.params("myVar") & "'"

that should be it...

- tak

stonkers
03-14-2006, 07:37 PM
That would work, but I've changed directions to use the class file for the dataAccess part and I've run into a much easier question. I've got the .cs file returning the correct field (I traced it), but it won't display because I'm doing something stupid, but I'm not sure what. What do I need to do to get the returned data (strings) to display as text?

<div>
<p>
Event Date: <%getEventField("eventDate");%>
</p>
<p>
Event Time: <%getEventField("eventTime");%>
</p>
<p>
Event Title: <%getEventField("eventTitle");%>
</p>
<p>
Event Description: <%getEventField("eventDesc");%>
</p>
</div>

Thanks,
Eric

takkie
03-15-2006, 10:31 AM
Are those data coming from a db? Say you have a table, containing 5 rows (5 events)....

how many set of the "following" do you have in your page?

<div>
<p>
Event Date: <%getEventField("eventDate");%>
</p>
<p>
Event Time: <%getEventField("eventTime");%>
</p>
<p>
Event Title: <%getEventField("eventTitle");%>
</p>
<p>
Event Description: <%getEventField("eventDesc");%>
</p>
</div>

??

And what happens if you have 10 rows? are you hard coding these "sections" individually? Or are they generated dynamically?

Your getEventField() should take 2 params, getEventField(id, eventSource), and in your function, just do a return of a string...that should make it display as text...

tak