protected void btnSave_Click(object sender, EventArgs e)
 {
     objCategory = new Category();
     int r = objCategory.CategoryUpdate(0, txtName.Text.ToString().Trim(),Convert.ToInt32(ddlCategory.SelectedItem.Value.ToString()));
     txtName.Text = "";
     ddlCategory.SelectedIndex = 0;
     LoadCategory();
 }
        protected void DataList1_DeleteCommand(object source, DataListCommandEventArgs e)
        {
            objCategory = new Category();
            int catId = (int)DataList1.DataKeys[(int)e.Item.ItemIndex];

            objCategory.CategoryDelete(catId);

            DataList1.EditItemIndex = -1;
            LoadCategory();
        }
 protected void btnSave_Click(object sender, EventArgs e)
 {
     int r=0;
     objCategory = new Category();
     DataTable dt = objCategory.AvailableCategoryGroup(txtcategory.Text.ToString().Trim());
     if (dt.Rows.Count == 0 && txtcategory.Text.ToString().Trim() != "")
         r = objCategory.CategoryGroupUpdate(0, txtcategory.Text.ToString().Trim());
     txtcategory.Text = "";
     LoadCategory();
 }
 void LoadCategoryGroup(DropDownList ddl)
 {
     Category cat = new Category();
     ddl.Items.Clear();
     DataTable dt1 = cat.SelectCategoryGroup();
     ListItem listItem = new ListItem();
     listItem.Text = "<Select Category Group>";
     listItem.Value = "0";
     //listItem.Attributes.Add("style", "background-Black:white;color:White");
     ddl.Items.Add(listItem);
     for (int i = 0; i < dt1.Rows.Count; i++)
     {
         listItem = new ListItem();
         listItem.Text = dt1.Rows[i]["CategoryGroupName"].ToString();
         listItem.Value = dt1.Rows[i]["CategoryGroupId"].ToString();
         //listItem.Attributes.Add("style", "background-color:Black;color:white");
         ddl.Items.Add(listItem);
     }
 }
        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;
        }
        protected void DataList1_UpdateCommand(object source, DataListCommandEventArgs e)
        {
            // Get the DataKey value associated with current Item Index.
            int catId = (int)DataList1.DataKeys[(int)e.Item.ItemIndex];
            // Get updated value entered by user in textbox control for
            // Name field.
            TextBox txtId;
            txtId = (TextBox)e.Item.FindControl("txtId");
            TextBox txtCName;
            txtCName = (TextBox)e.Item.FindControl("txtCName");
            DropDownList ddlCat = (DropDownList)e.Item.FindControl("ddlCat");
            //LoadCategoryGroup(ddlCat);
            //for (int i = 0; i < ddlCat.Items.Count; i++)
            //{
            //    if (ddlCat.Items[i].Text == e.Item.Attributes["CategoryGroupName"])
            //        ddlCat.SelectedIndex = i;
            //}

            // string variable to store the connection string
            // retrieved from the connectionStrings section of web.config
            objCategory = new Category();
            int r = objCategory.CategoryUpdate(Convert.ToInt32(txtId.Text.ToString().Trim()), txtCName.Text.ToString().Trim(),Convert.ToInt32(ddlCat.SelectedItem.Value.ToString()));
            // reset the DataList mode back to its initial state
            DataList1.EditItemIndex = -1;
            LoadCategory();
        }
 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;
 }
        protected void DataList1_UpdateCommand(object source, DataListCommandEventArgs e)
        {
            // Get the DataKey value associated with current Item Index.
            int catId = (int)DataList1.DataKeys[(int)e.Item.ItemIndex];
            // Get updated value entered by user in textbox control for
            // Name field.
            TextBox txtId;
            txtId = (TextBox)e.Item.FindControl("txtId");
            TextBox txtCName;
            txtCName = (TextBox)e.Item.FindControl("txtCName");

            // string variable to store the connection string
            // retrieved from the connectionStrings section of web.config
            objCategory = new Category();
            int r = objCategory.CategoryGroupUpdate(Convert.ToInt32(txtId.Text.ToString().Trim()), txtCName.Text.ToString().Trim());
            // reset the DataList mode back to its initial state
            DataList1.EditItemIndex = -1;
            LoadCategory();
        }