- 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?