I used two web user controls on a single Web form. First web user control includes Grid View for displaying the headings in a vertical manner and second one includes a Data List for displaying headings in a horizontal manner.The two web user controls are in a single folder.The first one in working but the second one is not working.Here's the back end code for Web user control 2 :-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
public partial class WebUserControl2 : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
String st = Server.MapPath("XMLFile.xml");
DataSet ds = new DataSet();
ds.ReadXml(st);
DataList1.RepeatDirection = RepeatDirection.Horizontal;
DataList1.DataSource = ds;
}
}
and the HTML code for web user control 2 : -
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl2.ascx.cs" Inherits="WebUserControl2" %>
<asp:DataList ID="DataList1" runat="server">
<ItemTemplate>
<asp:HyperLink ID="hl" Text='<%# Eval("txt") %>' NavigateUrl='<%#Eval("url") %>' runat="server" />
</ItemTemplate>
</asp:DataList>
I am using these two web user controls on a single web form.The second web user control is not working that I am using for displaying the headings in horizontal manner through Data List.Here's the HTML code for web form :
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register src="WebUserControl.ascx" tagname="WebUserControl" tagprefix="uc1" %>
<%@ Register src="WebUserControl2.ascx" tagname="WebUserControl2" tagprefix="uc2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<uc1:WebUserControl ID="WebUserControl1" runat="server" />
<uc2:WebUserControl2 ID="WebUserControl21" runat="server" />
<br />
<br />
</div>
</form>
You need to DataBind your DataList:
DataList1.RepeatDirection = RepeatDirection.Horizontal;
DataList1.DataSource = ds;
DataList1.DataBind(); //add this