void LoadCategory() { objCategory = new Category(); dt = objCategory.SelectCategory(); if (dt.Rows.Count > PageSize) tblPaging.Visible = true; else tblPaging.Visible = false; if (dt.Rows.Count > 0) { if (tblPaging.Visible == true) { // Setting viewstate for TotalRecords LabelTotalRecords.Text = dt.Rows.Count.ToString(); // Setting viewstate for TotalPages if (int.Parse(LabelTotalRecords.Text) % PageSize > 0) // If page size is not exactly divisible by total records ViewState["TotalPages"] = int.Parse(LabelTotalRecords.Text) / PageSize; else // If page is exactly divisible by total records ViewState["TotalPages"] = int.Parse(LabelTotalRecords.Text) / PageSize - 1; ViewState["dataTable"] = dt; if (!object.Equals(dt, null)) { BindList(ManagePaging(dt)); } } else { DataList1.DataSource = dt; DataList1.DataBind(); } } else PagingRow.Visible = false; }
void LoadCategory() { Category cnt = new Category(); ddlCategory.Items.Clear(); DataTable dt1 = cnt.SelectCategory(); ListItem listItem = new ListItem(); listItem.Text = ""; listItem.Value = "0"; //listItem.Attributes.Add("style", "background-Black:white;color:White"); ddlCategory.Items.Add(listItem); for (int i = 0; i < dt1.Rows.Count; i++) { listItem = new ListItem(); listItem.Text = dt1.Rows[i]["CategoryName"].ToString(); listItem.Value = dt1.Rows[i]["CategoryId"].ToString(); //listItem.Attributes.Add("style", "background-color:Black;color:white"); ddlCategory.Items.Add(listItem); } //ddlCountry.SelectedIndex = 0; }