TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Guru Prakash
NA
5
564
How to recover from the error?
Jan 4 2017 5:28 AM
I am retrieving data from database and bind to a gridview & listview controls and here i need to display each "tags"(i.e, comma separated values) as hyperlinks.
string
tags =
string
.Empty;
using
(DataClass1DataContext DcContext =
new
DataClass1DataContext())
{
GridView1(or)ListView1.DataSource = DcContext.tblArticles
.Join(DcContext.tblCategories,
x => x.category,
y => y.categoryId,
(x, y) =>
new
{ x, y })
.Join(DcContext.tblSubCategories,
p => p.x.subcategory,
q => q.subcategoryId,
(p, q) =>
new
{
tags = p.x.keywords,
Article = p.x.articleId,
Published = p.x.articleDate,
Title = p.x.title,
Summary = p.x.description,
Labels = p.x.keywords,
Poster = p.x.image,
Category = p.y.Category,
Subcategory = q.subcategory,
});
What I need is?
The tags which i retrieved will need to display as related keywords in the form of hyperlinks and bind to the gridview/Listview.
<
asp:GridView
ID
=
"GridView1"
runat
=
"server"
Width
=
"100%"
AutoGenerateColumns
=
"false"
>
<
Columns
>
<
asp:TemplateField
>
<
ItemTemplate
>
<
asp:Image
ID
=
"PosterImg"
runat
=
"server"
ImageUrl
=
'<%#Eval("Poster") %>'
Width
=
"50"
Height
=
"50"
/>
</
ItemTemplate
>
</
asp:TemplateField
>
<
asp:BoundField
DataField
=
"Published"
HeaderText
=
"Published on"
/>
<
asp:BoundField
DataField
=
"Title"
HeaderText
=
"Article"
/>
<
asp:BoundField
DataField
=
"Summary"
HeaderText
=
"Summary about your articles"
/>
<
asp:TemplateField
>
<
ItemTemplate
>
<
asp:PlaceHolder
ID
=
"PlaceHolder1"
runat
=
"server"
>
</
asp:PlaceHolder
>
</
ItemTemplate
>
</
asp:TemplateField
>
<
asp:BoundField
DataField
=
"Category"
HeaderText
=
"Category"
/>
<
asp:BoundField
DataField
=
"Subcategory"
HeaderText
=
"Subcategory"
/>
</
Columns
>
</
asp:GridView
>
<
asp:ListView
ID
=
"ListView1"
runat
=
"server"
>
<
ItemTemplate
>
<
asp:Image
ID
=
"PosterImg"
CssClass
=
"thumb"
runat
=
"server"
ImageUrl
=
'<%#Eval("Poster") %>'
Width
=
"120"
Height
=
"150"
/>
<
h4
>
<
asp:HyperLink
ID
=
"HyperLink2"
NavigateUrl
=
'<%#"?p="+Eval("Article") %>'
runat
=
"server"
>
<
%#Eval("Title") %
>
</
asp:HyperLink
>
</
h4
>
<
cite
>
Posted by
<
asp:HyperLink
ID
=
"HyperLink3"
NavigateUrl
=
'<%#"?user="+Eval("Article") %>'
runat
=
"server"
>
Username
</
asp:HyperLink
>
under
<
span
>
<
asp:HyperLink
ID
=
"HyperLink4"
NavigateUrl
=
'<%#"?subcategory="+Eval("Subcategory") %>'
runat
=
"server"
>
<
%#Eval("Subcategory") %
>
</
asp:HyperLink
>
·
<
asp:HyperLink
ID
=
"HyperLink5"
NavigateUrl
=
'<%#"?category="+Eval("Category") %>'
runat
=
"server"
>
<
%#Eval("Category") %
>
</
asp:HyperLink
>
</
span
>
on
<
time
>
<
%#Eval("Published") %
>
</
time
>
</
cite
>
<
br
/>
<
p
>
<
%#Eval("Summary") %
>
</
p
>
<
span
>
<
asp:PlaceHolder
ID
=
"PlaceHolder1"
runat
=
"server"
>
</
asp:PlaceHolder
>
</
span
>
</
ItemTemplate
>
</
asp:ListView
>
What I have tried:
Added a placeholder inside the item template of each control(i.e, GRIDVIEW and LISTVIEW)
and by using LINQ I retrieved it from database and assign it to local string variable.
string
[] strArray = tags.Split(
','
);
foreach
(var obj
in
strArray)
{
HyperLink TagLinks =
new
HyperLink();
TagLinks.NavigateUrl =
"?tags="
+ obj;
TagLinks.Text = obj;
PlaceHolder PlaceHolder1 = (PlaceHolder)GridView1.FindControl(
"PlaceHolder1"
);
PlaceHolder1.Controls.Add(TagLinks);
}
I received an error:
Object reference not set to an instance of an object.
How to resolve this?
Attachment:
default.rar
Reply
Answers (
2
)
How To Send and Receive SMS using GSM Modem ?
Entity framework with business layer and data access layer