By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,491 Members | 1,196 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,491 IT Pros & Developers. It's quick & easy.

Show content

P: n/a
Hi!

I use a Repeater Control (with Item Template/Container.DataItem) to list all
the articles in my different categories. The list displays "title",
"ingress" and a "read more" link.

This is ok when I got many articles in a category. But if there is only one
article, I want to show the detail page for this article (no need to click
the "read more"-link).

How can I do this is ASP.NET (VB)?

Thanks!!!


Nov 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
it's hard to see without knowing how your code works. if the read-more link
is simply ahref= to a separate page, you can do something simple like:

Page_Load
dim articles as arraylist = GetAllArticles(categoryId)
if (articles.count = 1) then
Response.Redirect("details.aspx?articleId=" + ctype(articles(0),
Article).ArticleId)
end if
'normal binding
End sub
similarly, if you are hiding/showing controls, you can do the same

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Řyvind Isaksen" <oy****@webressurs.no> wrote in message
news:uH**************@TK2MSFTNGP09.phx.gbl...
Hi!

I use a Repeater Control (with Item Template/Container.DataItem) to list
all the articles in my different categories. The list displays "title",
"ingress" and a "read more" link.

This is ok when I got many articles in a category. But if there is only
one article, I want to show the detail page for this article (no need to
click the "read more"-link).

How can I do this is ASP.NET (VB)?

Thanks!!!

Nov 19 '05 #2

P: n/a
Thanks for quick answer!!
Yes, what I really need is to have a way to check if there are more than one
article in the category...
This is my (codebehind) code:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
GetArticles(request.querystring("catID"))
End Sub
Private Sub GetArticles(ByVal inputCatID)

Dim SQL As String = "select title,ingress,body from tblArticle"

Dim conn As New SqlConnection(variables.ConnString)
Dim cmd As New SqlCommand(SQL, conn)

cmd.Connection.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader
Me.rptArticle.DataSource = dr
Me.rptArticle.DataBind()
cmd.Connection.Close()

cmd.Dispose()
conn.Dispose()

End Sub
I would be VERY happy if you please can show me how to use your example in
this code :)

Thanks again!!!

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:uH**************@TK2MSFTNGP09.phx.gbl...
it's hard to see without knowing how your code works. if the read-more
link is simply ahref= to a separate page, you can do something simple
like:

Page_Load
dim articles as arraylist = GetAllArticles(categoryId)
if (articles.count = 1) then
Response.Redirect("details.aspx?articleId=" + ctype(articles(0),
Article).ArticleId)
end if
'normal binding
End sub
similarly, if you are hiding/showing controls, you can do the same

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Řyvind Isaksen" <oy****@webressurs.no> wrote in message
news:uH**************@TK2MSFTNGP09.phx.gbl...
Hi!

I use a Repeater Control (with Item Template/Container.DataItem) to list
all the articles in my different categories. The list displays "title",
"ingress" and a "read more" link.

This is ok when I got many articles in a category. But if there is only
one article, I want to show the detail page for this article (no need to
click the "read more"-link).

How can I do this is ASP.NET (VB)?

Thanks!!!


Nov 19 '05 #3

P: n/a
Oh. well, it's much more difficult using a datareader since you can only
move through it once (ie, you can't get the count).

One solution is to switch to a datatable, which you could bind just the same
and use the Rows.Count property.

Another solution is to change ur query so that it uses an output parameter
or a 2nd query such as

"select count(*) from tblArticle;Select title, body from tblArticle;"

which you could then do:

dim count as integer = cint(dr(0))
if count = 1 then
'clean up
'redirect
else
dr.NextResult();
'normal binding here
'clean up
end if
There are other solutions, but those are the best that come to mind early
this morning. Btw, you really need some try/finally statements in there to
make sure your resources are cleaned up even on error.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Řyvind Isaksen" <oy****@webressurs.no> wrote in message
news:ez**************@TK2MSFTNGP15.phx.gbl...
Thanks for quick answer!!
Yes, what I really need is to have a way to check if there are more than
one article in the category...
This is my (codebehind) code:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
GetArticles(request.querystring("catID"))
End Sub
Private Sub GetArticles(ByVal inputCatID)

Dim SQL As String = "select title,ingress,body from tblArticle"

Dim conn As New SqlConnection(variables.ConnString)
Dim cmd As New SqlCommand(SQL, conn)

cmd.Connection.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader
Me.rptArticle.DataSource = dr
Me.rptArticle.DataBind()
cmd.Connection.Close()

cmd.Dispose()
conn.Dispose()

End Sub
I would be VERY happy if you please can show me how to use your example in
this code :)

Thanks again!!!

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:uH**************@TK2MSFTNGP09.phx.gbl...
it's hard to see without knowing how your code works. if the read-more
link is simply ahref= to a separate page, you can do something simple
like:

Page_Load
dim articles as arraylist = GetAllArticles(categoryId)
if (articles.count = 1) then
Response.Redirect("details.aspx?articleId=" + ctype(articles(0),
Article).ArticleId)
end if
'normal binding
End sub
similarly, if you are hiding/showing controls, you can do the same

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Řyvind Isaksen" <oy****@webressurs.no> wrote in message
news:uH**************@TK2MSFTNGP09.phx.gbl...
Hi!

I use a Repeater Control (with Item Template/Container.DataItem) to list
all the articles in my different categories. The list displays "title",
"ingress" and a "read more" link.

This is ok when I got many articles in a category. But if there is only
one article, I want to show the detail page for this article (no need to
click the "read more"-link).

How can I do this is ASP.NET (VB)?

Thanks!!!



Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.