How to bind DataList control in asp.net. this lesson only provide programming parts of DataList control.tomorrow i will post the HTML portion of this program. Not like GridView. it is simple to code.
C# ASP.NET CODER
public int PageCount
{
get
{
object o = this.ViewState["_PageCount"];
if (o == null)
return 0;
else
return (int)o;
}
set
{
ViewState["_PageCount"] = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostback)
{
FillDataList(true);
}
else
{
FillDataList(false);
}
}
public void FillDataList(bool a)
{
if (a)
PageCount = 0;
lbtnNext.Enabled = true;
lbtnNext2.Enabled = true;
lbtnPrevious.Enabled = true;
lbtnPrevious2.Enabled = true;
string cmd = string.Empty;
cmd = string.Format("SELECT table_field1,table_field2,table_field3,table_field4 FROM table WHERE condition1 >'{0}' AND condition1 ='{1}' AND condition1 >'0'", DateTime.Now, Request.QueryString["sdd"]);
DataTable BTab = objDBHelper.GetReaderTable(cmd, 7);
if (BTab.Rows.Count > 0)
{
if (a)
PageCount = 0;
lbtnNext.Enabled = true;
lbtnNext2.Enabled = true;
lbtnPrevious.Enabled = true;
lbtnPrevious2.Enabled = true;
DataColumn newcol = new DataColumn("imagecol", typeof(object));
DataColumn newcolm = new DataColumn("clubNamecol", typeof(object));
DataColumn newcolm1 = new DataColumn("bookme", typeof(object));
DataColumn calCol = new DataColumn("viewcal", typeof(string));
DataColumn calCol2 = new DataColumn("view", typeof(string));
BTab.Columns.Add(newcol);
BTab.Columns.Add(newcolm);
BTab.Columns.Add(newcolm1);
BTab.Columns.Add(calCol);
BTab.Columns.Add(calCol2);
for (int i = 0; i < BTab.Rows.Count; i++)
{
BTab.Rows[i]["imagecol"] = "imagefile";
BTab.Rows[i]["clubNamecol"] = (object)objDBHelper.ExecuteScalar(string.Format("SELECT xx FROM table WHERE condition='{0}'", BTab.Rows[i][1].ToString()));
BTab.Rows[i]["bookme"] = string.Format("BCalendar.aspx?bid={0}&cid={1}", BTab.Rows[i][0].ToString(), BTab.Rows[i][1].ToString());
BTab.Rows[i]["viewcal"] = string.Format("ECalendar.aspx?cid={0}&bid={1}", BTab.Rows[i][1].ToString(), BTab.Rows[i][0].ToString());
BTab.Rows[i]["view"] = string.Format("ClubDetails.aspx?cid={0}&bid={1}", BTab.Rows[i][1].ToString(), BTab.Rows[i][0].ToString());
}
pgddata = new PagedDataSource();
pgddata.DataSource = BTab.DefaultView;
pgddata.AllowPaging = true;
pgddata.CurrentPageIndex = PageCount;
pgddata.PageSize = 5;
lbtnPrevious2.Visible = !pgddata.IsFirstPage;
lbtnPrevious.Visible = !pgddata.IsFirstPage;
lbtnNext2.Visible = !pgddata.IsLastPage;
lbtnNext.Visible = !pgddata.IsLastPage;
dlClubList.DataSource = pgddata;
dlClubList.DataBind();
dlClubList.Visible = true;
}
else
{
dlClubList.Visible = false;
lbtnNext.Visible = false;
lbtnNext2.Visible = false;
lbtnPrevious.Visible = false;
lbtnPrevious2.Visible = false;
Label1.Visible = true;
Label1.Text = "No Events found..Please search for another City";
LinkButton2.Visible = true;
}
}
No comments:
Post a Comment