gridview控件的使用,gridview控件选择功能
- 数据库
- 2023-08-31
- 78
大家好,感谢邀请,今天来为大家分享一下gridview控件的使用的问题,以及和gridview控件选择功能的一些困惑,大家要是还不太明白的话,也没有关系,因为接下来将为...
大家好,感谢邀请,今天来为大家分享一下gridview控件的使用的问题,以及和gridview控件选择功能的一些困惑,大家要是还不太明白的话,也没有关系,因为接下来将为大家分享,希望可以帮助到大家,解决大家的问题,下面就开始吧!
gridview控件的什么属性用来设置是否打开分页功能
当GridView中显示的记录很多的时候,可以通过GridView的分页功能来分页显示这些记录。
如果GridView是直接绑定数据库,则很简单:只要点击GridView空间左上角的小三角形,再弹出的选项中,将"启动分页"打上勾即可。如果是用代码实现,则需要这么做:
1、允许分页:设置AllowPaging=True;
2、设置GridView属性栏中PagerSetting里的一些属性中,定义分页的样式;
3、数据部署:将数据显示到GridView上;
4、加入相关事件:PageIndexChanged()、PageIndexChanging();
5、如果要添加分页码显示,即显示当前在第几页,还需添加DataBound()事件。
怎样将LIST中的数据绑定到GridView,并实现增删改查
我的一个GridView操作文件,数据源是实体LIST,删改查功能都有了,你参考下 usingSystem; usingSystem.Collections; usingSystem.Collections.Generic; usingSystem.Configuration; usingSystem.Data; usingSystem.Linq; usingSystem.Web; usingSystem.Web.Security; usingSystem.Web.UI; usingSystem.Web.UI.HtmlControls; usingSystem.Web.UI.WebControls; usingSystem.Web.UI.WebControls.WebParts; usingSystem.Xml.Linq; usinglwf_MVC.CTRL; usinglwf_MVC.lwf_Normal; usinglwf_MVC.MODEL; publicpartialclassadmin_news_edit:System.Web.UI.Page { publicstringicls_name="cls_f_news"; //不同级数系列区别在于iWhere publicstringiWhere="1=1andENG="+WEB.GQ("ENG","0")+"andTID1="+WEB.GQ("SSS","1")+"and1=1"; publicintgetRecordCount() { cls_f_newsif_news=(cls_f_news)CTRL.CreateModel(icls_name); if_news.title=soKey.Text; if_news.contents=soKey.Text; if_news.WHERE=iWhere; inti_recordcount=CTRL.getCount(if_news,"orderbyorderid,iddesc"); returni_recordcount; } protectedvoidPage_Load(objectsender,EventArgse) { if(WEB.getSession("userName")==null||WEB.getSession("userName")=="")JS.RD(System.Web.HttpUtility.UrlDecode("%e7%99%bb%e9%99%86%e8%b6%85%e6%97%b6%2c%e8%af%b7%e9%87%8d%e6%96%b0%e7%99%bb").Trim(),"../login.aspx"); if(!IsPostBack) { AspNetPagerBin(1); GridViewBin(); } } protectedvoidAspNetPagerBin(intcurr) { inti_recordcount=getRecordCount(); AspNetPager1.RecordCount=i_recordcount; AspNetPager1.CurrentPageIndex=curr; } protectedvoidGridView1_RowEditing(objectsender,GridViewEditEventArgse) { GridView1.EditIndex=e.NewEditIndex; GridViewBin(); } protectedvoidGridView1_RowCancelingEdit(objectsender,GridViewCancelEditEventArgse) { GridView1.EditIndex=-1; GridViewBin(); } protectedvoidGridView1_RowUpdating(objectsender,GridViewUpdateEventArgse) { inti_id=int.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString()); cls_f_newsbaseTableObj=(cls_f_news)CTRL.CreateModel(icls_name,i_id); baseTableObj.title=((TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text.ToString(); baseTableObj.newfrom=((TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text.ToString(); baseTableObj.addTime=DateTime.Parse(((TextBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[0]).Text.ToString()); baseTableObj.orderid=int.Parse(((TextBox)GridView1.Rows[e.RowIndex].FindControl("tb_orderid_b")).Text.ToString()); if(CTRL.Update(baseTableObj)) { JS.alert(System.Web.HttpUtility.UrlDecode("%e4%bf%ae%e6%94%b9%e6%88%90%e5%8a%9f").Trim()); } else { JS.alert(System.Web.HttpUtility.UrlDecode("%e7%bd%91%e7%bb%9c%e8%b6%85%e6%97%b6%ef%bc%8c%e8%af%b7%e9%87%8d%e6%96%b0%e5%86%8d%e8%af%95").Trim()); } //==================================== GridView1.EditIndex=-1; GridViewBin(); } protectedvoidGridView1_RowDeleting(objectsender,GridViewDeleteEventArgse) { inti_id=int.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString()); cls_f_newsbaseTableObj=(cls_f_news)CTRL.CreateModel(icls_name,i_id); if(CTRL.Delete(baseTableObj)) { JS.alert(System.Web.HttpUtility.UrlDecode("%e8%ae%b0%e5%bd%95%e5%88%a0%e9%99%a4%e6%88%90%e5%8a%9f").Trim()); } else { JS.alert(System.Web.HttpUtility.UrlDecode("%e7%bd%91%e7%bb%9c%e8%b6%85%e6%97%b6%ef%bc%8c%e8%af%b7%e9%87%8d%e6%96%b0%e5%86%8d%e8%af%95").Trim()); } //==================================== GridView1.EditIndex=-1; GridViewBin(); } protectedvoidAspNetPager1_PageChanged(objectsender,EventArgse) { GridView1.EditIndex=-1; GridView1.PageIndex=AspNetPager1.CurrentPageIndex; GridViewBin(); } protectedvoidCheckBox_all_CheckedChanged(objectsender,EventArgse) { CheckBox_opp.Checked=false; for(inti_i=0;i_i<=GridView1.Rows.Count-1;i_i++) { CheckBoxckb=(CheckBox)GridView1.Rows[i_i].FindControl("cb_selBoxs"); if(CheckBox_all.Checked) { ckb.Checked=true; } else { ckb.Checked=false; } } } protectedvoidCheckBox_opp_CheckedChanged(objectsender,EventArgse) { CheckBox_all.Checked=false; for(inti_i=0;i_i<=GridView1.Rows.Count-1;i_i++) { CheckBoxckb=(CheckBox)GridView1.Rows[i_i].FindControl("cb_selBoxs"); if(ckb.Checked) { ckb.Checked=false; } else { ckb.Checked=true; } } } protectedvoidlb_delete_Click(objectsender,EventArgse) { for(inti_i=0;i_i<=GridView1.Rows.Count-1;i_i++) { CheckBoxckb=(CheckBox)GridView1.Rows[i_i].FindControl("cb_selBoxs"); if(ckb.Checked) { inti_id=int.Parse(GridView1.DataKeys[i_i].Value.ToString()); cls_f_newsbaseTableObj=(cls_f_news)CTRL.CreateModel(icls_name,i_id); CTRL.Delete(baseTableObj); } } inti_Pcount=getRecordCount(); if(AspNetPager1.CurrentPageIndex>i_Pcount) { AspNetPagerBin(i_Pcount); } else { AspNetPagerBin(AspNetPager1.CurrentPageIndex); } GridViewBin(); } protectedvoidlb_order_Click(objectsender,EventArgse) { for(inti_i=0;i_i<=GridView1.Rows.Count-1;i_i++) { TextBoxtb=(TextBox)GridView1.Rows[i_i].FindControl("tb_orderid_a"); inti_id=int.Parse(GridView1.DataKeys[i_i].Value.ToString()); cls_f_newsbaseTableObj=(cls_f_news)CTRL.CreateModel(icls_name,i_id); baseTableObj.orderid=int.Parse(tb.Text.ToString()); CTRL.Update(baseTableObj); } GridViewBin(); } protectedvoidbt_search_Click(objectsender,EventArgse) { AspNetPagerBin(1); GridViewBin(); } protectedvoidGridView1_RowCommand(objectsender,GridViewCommandEventArgse) { introwNum; intid_i; } protectedvoidGridView1_RowDataBound(objectsender,GridViewRowEventArgse) { if(e.Row.RowType==DataControlRowType.DataRow) { } } protectedvoidGridView1_Sorting(objectsender,GridViewSortEventArgse) { stringsortExpression=e.SortExpression; ViewState["sortExpression"]=sortExpression; if(ViewState["ASC"].ToString()=="0") { ViewState["ASC"]="1"; } else { ViewState["ASC"]="0"; } AspNetPagerBin(1); GridViewBin(); } protectedvoidGridViewBin() { CheckBox_all.Checked=false; cls_f_newsif_news=(cls_f_news)CTRL.CreateModel(icls_name); if_news.title=soKey.Text; if_news.contents=soKey.Text; if_news.WHERE=iWhere; intRecordCount; intcurP=Convert.ToInt32(AspNetPager1.CurrentPageIndex); List<cls_f_news>iList_f_news=CTRL.getPageList(if_news,"orderbyorderid,iddesc",AspNetPager1.PageSize,curP,outRecordCount).ConvertAll<cls_f_news>(delegate(lwf_MVC.MODEL.baseTables){return(cls_f_news)s;}); if(ViewState["ASC"]==null)ViewState["ASC"]="-1"; if(ViewState["sortExpression"]==null)ViewState["sortExpression"]="orderid"; if(ViewState["ASC"].ToString()=="-1") { iList_f_news.Sort(delegate(cls_f_newsa,cls_f_newsb){return(newCaseInsensitiveComparer()).Compare(a.GetType().GetProperty(ViewState["sortExpression"].ToString()).GetValue(a,null),b.GetType().GetProperty(ViewState["sortExpression"].ToString()).GetValue(b,null));}); } else { if(ViewState["ASC"].ToString()=="1") { iList_f_news.Sort(delegate(cls_f_newsa,cls_f_newsb){return(newCaseInsensitiveComparer()).Compare(a.GetType().GetProperty(ViewState["sortExpression"].ToString()).GetValue(a,null),b.GetType().GetProperty(ViewState["sortExpression"].ToString()).GetValue(b,null));}); } else { iList_f_news.Sort(delegate(cls_f_newsa,cls_f_newsb){return(newCaseInsensitiveComparer()).Compare(b.GetType().GetProperty(ViewState["sortExpression"].ToString()).GetValue(b,null),a.GetType().GetProperty(ViewState["sortExpression"].ToString()).GetValue(a,null));}); } } GridView1.DataSource=iList_f_news; GridView1.DataKeyNames=newstring[]{"id"}; GridView1.DataBind(); } }
关于gridview控件的使用的内容到此结束,希望对大家有所帮助。
本文链接:http://www.xinin56.com/su/12874.html