|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Binding accessdatasource to "normal" controlsI'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. 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 |
|||||||||||||||||||||||