Re: Missing first row when binding a reader to a repeater.
Eron Armour <[email protected]>
| Newsgroups | gmane.comp.windows.devel.dotnet.web |
|---|---|
| Message-ID | <[email protected]> |
Thank you for your reply.
The launch URL is constructed depending on what kind of course it is,
flash based, video, a quiz, etc... So I send the course vars to a class
that handles the construction on the launch URL, weather it builds a url
for our flash course player or quiz and so on.
This was my solution: (sorry for the messy formatting)
protected void repTrainingHistory_ItemDataBound(object
sender,RepeaterItemEventArgs e)
{
URLBuilder url = new URLBuilder();
if (e.Item.ItemType == ListItemType.AlternatingItem ||
e.Item.ItemType == ListItemType.Item)
{
System.Data.Common.DbDataRecord record =
(System.Data.Common.DbDataRecord)e.Item.DataItem;
HyperLink a = e.Item.FindControl("hlTrainingHistLink") as
HyperLink;
if (null != a)
{
a.Attributes["onclick"] =
url.BuildCourseURL(Convert.ToInt32(record["CourseKey"]),Convert.ToInt32(
record["Media"]),Convert.ToInt32(record["CourseEventKey"]),record["TestT
ype"].ToString());
}
}
}
Thanks again for the reply.
-----Original Message-----
From: Discussion of building .NET applications targeted for the Web
[mailto:[email protected]] On Behalf Of Ryan Heath
Sent: Tuesday, April 17, 2007 11:55 PM
To: [email protected]
Subject: Re: [DOTNET-WEB] Missing first row when binding a reader to a
repeater.
if (drHistory.Read())
this line advances to the next record, thats why the first record is
not shown in your repeater.
Why don't you make up your lauch url within the template itself?
<a href="javascript:void(0);" onclick=<%#
url.BuildCourseURL((int)Eval("CourseKey"),(int)Eval("Media"),(int)Eval("
CourseEventKey"),(string)Eval("TestType"))
%> ><%# Eval("Title") %></a>
HTH
// Ryan
On 4/17/07, Eron Armour <[email protected]> wrote:
> I have a method to search a user's course history. When searching with
a
> particular user and search string I get 2 rows back and this is
correct.
>
>
>
> I call a method GetSearchResults(int, string, int, int) and if that
> reader has rows I pass some of the rows to another method,
> BuildCourseURL(int, int, int, string) to build a url depending on the
> test type which is passed to it.
>
>
>
> Here's is my code:
>
>
>
> SqlDataReader drHistory =
search.GetSearchResults(4,
> term, userKey, userGroupKey);
>
> if (!drHistory.HasRows)
>
> {
>
> lblNothing.Visible = true;
>
> }
>
> else
>
> {
>
> if (drHistory.Read())
>
> {
>
> launchURL =
> url.BuildCourseURL(Convert.ToInt32(drHistory["CourseKey"]),
>
>
> Convert.ToInt32(drHistory["Media"]),
>
>
> Convert.ToInt32(drHistory["CourseEventKey"]),
>
>
> drHistory["TestType"].ToString());
>
> }
>
>
>
> repTrainingHistory.DataSource = drHistory;
>
> repTrainingHistory.DataBind();
>
> repeaterSearchResults.Visible = false;
>
> repTrainingHistory.Visible = true;
>
> repTraining.Visible = false;
>
> repeaterSearchResults.Visible = false;
>
> lblNothing.Visible = false;
>
> }
>
>
>
> Everything works as it should and I get 2 results passed back but when
> the datareader is bound to the repreater (I think it is at this point)
> I'm missing the first row. Here's the front end code:
>
>
>
> <asp:Repeater ID="repTrainingHistory" runat="server">
>
> <HeaderTemplate>
>
> <table border="0" cellpadding="5" cellspacing="0"
> width="100%">
>
> <tr>
>
> <td
> width="250px"><strong><em>Source</em></strong></td>
>
> <td><strong><em>Result</em></strong></td>
>
> <td>Date</td>
>
> </tr>
>
> </HeaderTemplate>
>
> <ItemTemplate>
>
> <tr>
>
> <td colspan="3"><hr noshade size="1" /></td>
>
> </tr>
>
> <tr>
>
> <td><%# getCategoryText(category)%></td>
>
> <td>
>
> <a href="javascript:void(0);" onclick=<%# launchURL
> %>><%# Eval("Title")%></a>
>
> <td><%# Eval("Date") %></td>
>
> </tr>
>
> </ItemTemplate>
>
> <FooterTemplate>
>
> </table>
>
> </FooterTemplate>
>
> </asp:Repeater>
>
>
>
> Any help would be greatly appreciated.
>
>
>
>
> ===================================
> This list is hosted by DevelopMentor(r) http://www.develop.com
>
> View archives and manage your subscription(s) at
http://discuss.develop.com
>
===================================
This list is hosted by DevelopMentor(r) http://www.develop.com
View archives and manage your subscription(s) at
http://discuss.develop.com
===================================
This list is hosted by DevelopMentor® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com