Binding accessdatasource to "normal" controls

G

Guest

Hi

I'm trying to use my AccessDataSource which retrieves 1 record based on a
querystring, and display the various fields as Label controls on my page.

At the moment, the code compiles, but nothing appears on the page. Can some
explain why, and what I need to do to make it work?

Cheers, Dan.


Here's my data source...

<asp:AccessDataSource ID="adsStory" runat="server"
DataFile="~/App_Data/BeggarsBelief.mdb"
SelectCommand="SELECT [StoryTitle], [Synopsis], [Story], [Name],
[Visits] FROM [Stories] WHERE ([StoryID] = ?)">
<SelectParameters>
<asp:QueryStringParameter Type="Int32"
QueryStringField="id" />
</SelectParameters>
</asp:AccessDataSource>

and here's the label for the StoryTitle...

<h1><asp:Label runat="server" Text='<%# DataBinder.Eval(adsStory,
"[StoryTitle]") %>' ID="lblHeading" /></h1>

There's nothing added to the codebehind for the page.
 
W

WenYuan Wang

Hi Dan,

According to your description, I understand that Label("lblHeading") cannot
display the StoryTitle from the AccessDataSouce("adsStory"). Please feel
free to correct me if I have misunderstood anything here.

AccessDataSource only work with data-bound controls (GridView,Repeater...).
For these reason, we can not bind AccessDataSource and Label directly.
There are two ways to achieve this.
1. Using a FormView control binding with AccessDataSource.
<asp:FormView ID="FormView1" runat="server" DataSourceID="adsStory">
<ItemTemplate>
<h1><asp:Label runat="server" Text='<%# Eval("StoryTitle") %>'
ID="lblHeading" /></h1>
</ItemTemplate>
</asp:FormView>

2. Using Codebehind to get value from AccessDataSource and set it to Label.
this. lblHeading.Text =
((DataView)(adsStory.Select(DataSourceSelectArguments.Empty)))[0]["
StoryTitle"].ToString();

Please feel free to reply me if you have anything unclear. I'm glad to work
with you.
Hope this helps.
Sincerely.
Wen Yuan
 
W

WenYuan Wang

Hi Dan,

I haven't heard from you two days. I just want to know if the issue has
been resolved.
Please feel free to let me know if you have anything unclear.

Have a great day.
Best regards,
Wen Yuan
 

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