STEP 1: Create a VisualWebPart like NewsAndArticlesReadMore
STEP 2: Write a coding in NewsAndArticlesReadMoreUserControl.ascx
STEP 3:
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using VCSB.INTRANET.BLL;
using System.Data;
namespace VCSB01.INTRANET.WebPartDetailsPage.NewsAndArticlesReadMore
{
public partial class NewsAndArticlesReadMoreUserControl : BasePage
{
string moreId,moreid1;
protected void Page_Load(object sender, EventArgs e)
{
moreId =Convert.ToString(Request.QueryString["moreId"]);
Session.Add(moreid1, moreId);
if (!IsPostBack)
{
if (IsSuperAdmin || IsAdmin || IsManager)
{
imgbtnAdd.Visible = true;
imgbtnEdit.Visible = true;
imgbtnDelete.Visible = true;
}
if(IsEndUser)
{
imgbtnAdd.Visible = false;
imgbtnEdit.Visible = false;
imgbtnDelete.Visible = false;
}
if (!string.IsNullOrEmpty(moreId) || !string.IsNullOrEmpty(moreid1))
{
NewsAndArticlesSingleRow();
}
else
{
NewsAndArticlesAll();
}
//}
}
}
public void NewsAndArticlesSingleRow()
{
NewsAndArticlesBL newsAndArticlesSingleRow = new NewsAndArticlesBL(Convert.ToInt32(moreId));
grdNewsAndArticleAll.DataSource = newsAndArticlesSingleRow.GetSingleRowListItem();
grdNewsAndArticleAll.DataBind();
}
public void NewsAndArticlesAll()
{
NewsAndArticlesBL newsAndArticlesAll = new NewsAndArticlesBL();
grdNewsAndArticleAll.DataSource = newsAndArticlesAll.GetAllListItem();
grdNewsAndArticleAll.DataBind();
Session["TaskTable"] = newsAndArticlesAll.GetAllListItem();
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
foreach (GridViewRow di in grdNewsAndArticleAll.Rows)
{
CheckBox chkBx = (CheckBox)di.FindControl("chkSelect");
HiddenField htnobj = (HiddenField)di.FindControl("hdnNewsAndArticle");
if (chkBx.Checked)
{
NewsAndArticlesBL newsAndArticlesBL = new NewsAndArticlesBL(Convert.ToInt32(htnobj.Value), txtTitle.Text, txtDescription.Text, Convert.ToDateTime(txtArticleDate.Text), fldNewsImage);
if (newsAndArticlesBL.update())
{
}
}
}
NewsAndArticlesAll();
}
protected void imgbtnEdit_Click(object sender, ImageClickEventArgs e)
{
btnSubmit.Visible = false;
DataTable dt = new DataTable();
foreach (GridViewRow di in grdNewsAndArticleAll.Rows)
{
CheckBox chkBx = (CheckBox)di.FindControl("chkSelect");
HiddenField htnobj = (HiddenField)di.FindControl("hdnNewsAndArticle");
if (chkBx.Checked)
{
NewsAndArticlesBL newsAndArticlesSingleRow = new NewsAndArticlesBL(Convert.ToInt32(htnobj.Value));
dt = newsAndArticlesSingleRow.GetSingleRowListItem();
txtTitle.Focus();
txtTitle.Text = Convert.ToString(dt.Rows[0]["NewsTitle"]);
txtArticleDate.Text = Convert.ToString(dt.Rows[0]["NewsDate"]);
txtDescription.Text = Convert.ToString(dt.Rows[0]["NewsDescription"]);
string path = Convert.ToString(dt.Rows[0]["NewsImage"]);
}
}
mpupNewsAndArticlesEdit.Show();
}
protected void imgbtnDelete_Click(object sender, ImageClickEventArgs e)
{
foreach (GridViewRow di in grdNewsAndArticleAll.Rows)
{
CheckBox chkBx = (CheckBox)di.FindControl("chkSelect");
HiddenField htnobj = (HiddenField)di.FindControl("hdfPropeller");
if (chkBx.Checked)
{
NewsAndArticlesBL newsAndArticlesSingleRow = new NewsAndArticlesBL(Convert.ToInt32(htnobj.Value));
if (newsAndArticlesSingleRow.delete())
{
//
}
}
}
NewsAndArticlesAll();
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(txtTitle.Text) && !string.IsNullOrEmpty(txtDescription.Text) && !string.IsNullOrEmpty(txtArticleDate.Text))
{
NewsAndArticlesBL newsAndArticlesBL = new NewsAndArticlesBL(txtTitle.Text, txtDescription.Text, Convert.ToDateTime(txtArticleDate.Text), fldNewsImage);
if (newsAndArticlesBL.insert())
{
NewsAndArticlesAll();
//insert success
}
else
{
//fail
}
}
}
protected void grdNewsAndArticleAllDetails_Sorting(object sender, GridViewSortEventArgs e)
{
//Retrieve the table from the session object.
DataTable dt = Session["TaskTable"] as DataTable;
if (dt != null)
{
//Sort the data.
dt.DefaultView.Sort = e.SortExpression + " " + GetSortDirection(e.SortExpression);
grdNewsAndArticleAll.DataSource = Session["TaskTable"];
grdNewsAndArticleAll.DataBind();
}
}
private string GetSortDirection(string column)
{
// By default, set the sort direction to ascending.
string sortDirection = "ASC";
// Retrieve the last column that was sorted.
string sortExpression = ViewState["SortExpression"] as string;
if (sortExpression != null)
{
// Check if the same column is being sorted.
// Otherwise, the default value can be returned.
if (sortExpression == column)
{
string lastDirection = ViewState["SortDirection"] as string;
if ((lastDirection != null) && (lastDirection == "ASC"))
{
sortDirection = "DESC";
}
}
}
// Save new values in ViewState.
ViewState["SortDirection"] = sortDirection;
ViewState["SortExpression"] = column;
return sortDirection;
}
}
}
STEP 2: Write a coding in NewsAndArticlesReadMoreUserControl.ascx
STEP 3:
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using VCSB.INTRANET.BLL;
using System.Data;
namespace VCSB01.INTRANET.WebPartDetailsPage.NewsAndArticlesReadMore
{
public partial class NewsAndArticlesReadMoreUserControl : BasePage
{
string moreId,moreid1;
protected void Page_Load(object sender, EventArgs e)
{
moreId =Convert.ToString(Request.QueryString["moreId"]);
Session.Add(moreid1, moreId);
if (!IsPostBack)
{
if (IsSuperAdmin || IsAdmin || IsManager)
{
imgbtnAdd.Visible = true;
imgbtnEdit.Visible = true;
imgbtnDelete.Visible = true;
}
if(IsEndUser)
{
imgbtnAdd.Visible = false;
imgbtnEdit.Visible = false;
imgbtnDelete.Visible = false;
}
if (!string.IsNullOrEmpty(moreId) || !string.IsNullOrEmpty(moreid1))
{
NewsAndArticlesSingleRow();
}
else
{
NewsAndArticlesAll();
}
//}
}
}
public void NewsAndArticlesSingleRow()
{
NewsAndArticlesBL newsAndArticlesSingleRow = new NewsAndArticlesBL(Convert.ToInt32(moreId));
grdNewsAndArticleAll.DataSource = newsAndArticlesSingleRow.GetSingleRowListItem();
grdNewsAndArticleAll.DataBind();
}
public void NewsAndArticlesAll()
{
NewsAndArticlesBL newsAndArticlesAll = new NewsAndArticlesBL();
grdNewsAndArticleAll.DataSource = newsAndArticlesAll.GetAllListItem();
grdNewsAndArticleAll.DataBind();
Session["TaskTable"] = newsAndArticlesAll.GetAllListItem();
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
foreach (GridViewRow di in grdNewsAndArticleAll.Rows)
{
CheckBox chkBx = (CheckBox)di.FindControl("chkSelect");
HiddenField htnobj = (HiddenField)di.FindControl("hdnNewsAndArticle");
if (chkBx.Checked)
{
NewsAndArticlesBL newsAndArticlesBL = new NewsAndArticlesBL(Convert.ToInt32(htnobj.Value), txtTitle.Text, txtDescription.Text, Convert.ToDateTime(txtArticleDate.Text), fldNewsImage);
if (newsAndArticlesBL.update())
{
}
}
}
NewsAndArticlesAll();
}
protected void imgbtnEdit_Click(object sender, ImageClickEventArgs e)
{
btnSubmit.Visible = false;
DataTable dt = new DataTable();
foreach (GridViewRow di in grdNewsAndArticleAll.Rows)
{
CheckBox chkBx = (CheckBox)di.FindControl("chkSelect");
HiddenField htnobj = (HiddenField)di.FindControl("hdnNewsAndArticle");
if (chkBx.Checked)
{
NewsAndArticlesBL newsAndArticlesSingleRow = new NewsAndArticlesBL(Convert.ToInt32(htnobj.Value));
dt = newsAndArticlesSingleRow.GetSingleRowListItem();
txtTitle.Focus();
txtTitle.Text = Convert.ToString(dt.Rows[0]["NewsTitle"]);
txtArticleDate.Text = Convert.ToString(dt.Rows[0]["NewsDate"]);
txtDescription.Text = Convert.ToString(dt.Rows[0]["NewsDescription"]);
string path = Convert.ToString(dt.Rows[0]["NewsImage"]);
}
}
mpupNewsAndArticlesEdit.Show();
}
protected void imgbtnDelete_Click(object sender, ImageClickEventArgs e)
{
foreach (GridViewRow di in grdNewsAndArticleAll.Rows)
{
CheckBox chkBx = (CheckBox)di.FindControl("chkSelect");
HiddenField htnobj = (HiddenField)di.FindControl("hdfPropeller");
if (chkBx.Checked)
{
NewsAndArticlesBL newsAndArticlesSingleRow = new NewsAndArticlesBL(Convert.ToInt32(htnobj.Value));
if (newsAndArticlesSingleRow.delete())
{
//
}
}
}
NewsAndArticlesAll();
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(txtTitle.Text) && !string.IsNullOrEmpty(txtDescription.Text) && !string.IsNullOrEmpty(txtArticleDate.Text))
{
NewsAndArticlesBL newsAndArticlesBL = new NewsAndArticlesBL(txtTitle.Text, txtDescription.Text, Convert.ToDateTime(txtArticleDate.Text), fldNewsImage);
if (newsAndArticlesBL.insert())
{
NewsAndArticlesAll();
//insert success
}
else
{
//fail
}
}
}
protected void grdNewsAndArticleAllDetails_Sorting(object sender, GridViewSortEventArgs e)
{
//Retrieve the table from the session object.
DataTable dt = Session["TaskTable"] as DataTable;
if (dt != null)
{
//Sort the data.
dt.DefaultView.Sort = e.SortExpression + " " + GetSortDirection(e.SortExpression);
grdNewsAndArticleAll.DataSource = Session["TaskTable"];
grdNewsAndArticleAll.DataBind();
}
}
private string GetSortDirection(string column)
{
// By default, set the sort direction to ascending.
string sortDirection = "ASC";
// Retrieve the last column that was sorted.
string sortExpression = ViewState["SortExpression"] as string;
if (sortExpression != null)
{
// Check if the same column is being sorted.
// Otherwise, the default value can be returned.
if (sortExpression == column)
{
string lastDirection = ViewState["SortDirection"] as string;
if ((lastDirection != null) && (lastDirection == "ASC"))
{
sortDirection = "DESC";
}
}
}
// Save new values in ViewState.
ViewState["SortDirection"] = sortDirection;
ViewState["SortExpression"] = column;
return sortDirection;
}
}
}
No comments:
Post a Comment