protected void Page_Load(object sender, EventArgs e)
{
ListView1.AlternatingItemTemplate = new TempLate("AlternatingItemTemplate");
// ListView1.LayoutTemplate = new TempLate("LayoutTemplate");
ListView1.EmptyDataTemplate = new TempLate("EmptyDataTemplate");
ListView1.ItemTemplate = new TempLate("ItemTemplate");
DataSet ResultSet = RunQuery("Select * From UserInfo");
ListView1.DataSource = ResultSet;
ListView1.DataBind();
}
DataSet RunQuery(String QueryString)
{
// Declare the connection string. This example uses Microsoft SQL Server
// and connects to the Northwind sample database.
String ConnectionString = "Data Source=XU-AE42BC5C42AC;Initial Catalog=uzone;Persist Security Info=True;User ID=sa;Password=sa";
SqlConnection DBConnection = new SqlConnection(ConnectionString);
SqlDataAdapter DBAdapter;
DataSet ResultsDataSet = new DataSet();
try
{
// Run the query and create a DataSet.
DBAdapter = new SqlDataAdapter(QueryString, DBConnection);
DBAdapter.Fill(ResultsDataSet);
// Close the database connection.
DBConnection.Close();
}
catch (Exception ex)
{
// Close the database connection if it is still open.
if (DBConnection.State == ConnectionState.Open)
{
DBConnection.Close();
}
Message.Text = "Unable to connect to the database.";
}
return ResultsDataSet;
}
public class TempLate : ITemplate
{
private string templateType = "";
public TempLate(string type)
{
this.templateType = type;
}
//region ITemplate Members
public void InstantiateIn(Control container)
{
PlaceHolder ph = new PlaceHolder();
PlaceHolder itemPlaceholder = new PlaceHolder();
itemPlaceholder.ID = "itemPlaceholder";