Sorting of Gridview
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataSet ds=bindata();
GridView1.DataSource = ds;
GridView1.DataBind();
}
}
private DataSet bindata()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["deoConnectionString1"].ToString());
con.Open();
string cmd = "select id,name, employee.desgid,designation, employee.deptid,deptname,address from employee left outer join" +
" dept on (employee.deptid=dept.deptid)" +
" left outer join " +
" designation on (employee.desgid=designation.desgid)";
SqlDataAdapter da = new SqlDataAdapter(cmd,con);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
DataView dv = sortedView(false);
GridView1.DataSource = dv;
GridView1.DataBind();
}
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
ViewState["col"] = e.SortExpression;
DataView dv= sortedView(true);
GridView1.DataSource = dv;
GridView1.DataBind();
}
private DataView sortedView(Boolean isSort)
{
DataTable dt = bindata().Tables[0];
DataView dv = new DataView(dt);
if (ViewState["order"] == null ViewState["order"].ToString() == "asc")
{
if (isSort)
{
dv.Sort = ViewState["col"].ToString() + " Desc";
ViewState["order"] = "desc";
}
else
{
if(ViewState["order"] != null)
dv.Sort = ViewState["col"].ToString() + " asc";
}
}
else
{
if (isSort)
{
dv.Sort = ViewState["col"].ToString() + " asc";
ViewState["order"] = "asc";
}
else
{
if(ViewState["order"] != null)
dv.Sort = ViewState["col"].ToString() + " desc";
}
}
return dv;
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
DataView dv = sortedView(false);
GridView1.DataSource = dv;
GridView1.DataBind();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
DataView dv = sortedView(false);
GridView1.DataSource = dv;
GridView1.DataBind();
}
this code will sort the gridview by ascending and desceding order.
This concept is a good way to enhance the knowledge.thanks for sharing. please keep it up Salesforce Online Training Hyderabad
ReplyDeletemmorpg oyunlar
ReplyDeleteINSTAGRAM TAKİPCİ SATIN AL
Tiktok Jeton Hilesi
Tiktok jeton hilesi
antalya saç ekimi
referans kimliği nedir
İnstagram takipçi satın al
MT2 PVP SERVERLER
MT2 PVP SERVERLAR
instagram takipçi satın al
Good text Write good content success. Thank you
ReplyDeletekibris bahis siteleri
tipobet
mobil ödeme bahis
betmatik
betpark
slot siteleri
kralbet
bonus veren siteler
Good content. You write beautiful things.
ReplyDeletemrbahis
sportsbet
vbet
hacklink
sportsbet
mrbahis
korsan taksi
taksi
hacklink
sms onay
ReplyDeleteWİ4R