【asp源码栏目提醒】:网学会员为需要asp源码的朋友们搜集整理了repeatdatalist代码 - 讲义教程相关资料,希望对各位网友有所帮助!
repeat 代码1、 前台代码lthtml xmlnsquothttp://www.w3.org/1999/xhtmlquot gtlthead runatquotserverquotgt lttitlegt无标题页lt/titlegtlt/headgtltbodygt ltform idquotform1quot runatquotserverquotgt ltdivgt ltasp:Repeater IDquotRepeater1quot runatquotserverquot OnItemCommandquotRepeater1_ItemCommandquotOnItemDataBoundquotRepeater1_ItemDataBoundquotgt ltHeaderTemplate gt lttable border quot1quot cellpadding quot3quot cellspacing quot2quotgt lttr align quotcenterquot gt lttdgt学号lt/tdgt lttdgt姓名lt/tdgt lttdgt班级lt/tdgt lttdgt年龄lt/tdgt lttdgt修改lt/tdgt lttdgt删除lt/tdgt lt/trgt lt/HeaderTemplategt ltItemTemplate gt ltasp:Panel IDquotpanDelquot runatquotserverquotgt lttr align quotcenterquot gt lttdgtltDataBinder.EvalContainer .DataItemquotstuIdquot gtlt/tdgt lttdgtltDataBinder.EvalContainer .DataItemquotstuNamequotgtlt/tdgt lttdgtltDataBinder.EvalContainer .DataItemquotstuClassquotgtlt/tdgt lttdgtltDataBinder.EvalContainer .DataItemquotstuAgequot gtlt/tdgt lttdgtltasp:LinkButton IDquotdelEditquot CommandName quotdelUpdatequot CommandArgument ltDataBinder.EvalContainer .DataItemquotstuIdquotgt runatquotserverquotgt编辑 lt/asp:LinkButtongtlt/tdgt lttdgtltasp:LinkButton IDquotdelDelquot CommandName quotdelDeletequot CommandArgument ltDataBinder.EvalContainer .DataItemquotstuIdquotgt OnClientClick quotreturn onfirm确认删除吗?quot runatquotserverquotgt删除lt/asp:LinkButtongtlt/tdgt lt/trgt lt/asp:Panelgt ltasp:Panel IDquotpanEditquot runatquotserverquotgt lttr align quotcenterquot gt lttdgtltDataBinder.EvalContainer .DataItemquotstuIdquot gtlt/tdgt lttdgtltasp:TextBox IDquotstuNamequot TextltDataBinder.EvalContainer .DataItemquotstuNamequot gt runatquotserverquot AutoPostBackquotfalsequotgtlt/asp:TextBoxgtlt/tdgt lttdgtltasp:TextBox IDquotstuClassquot Text ltDataBinder.EvalContainer .DataItemquotstuClassquot gt runatquotserverquot AutoPostBackquotfalsequotgtlt/asp:TextBoxgtlt/tdgt lttdgtltasp:TextBox IDquotstuAgequot Text ltDataBinder.EvalContainer .DataItemquotstuAgequot gt runatquotserverquotgtlt/asp:TextBoxgtlt/tdgt lttdgt ltasp:LinkButton IDquotupEditquot CommandName quotediUpdatequot CommandArgument ltDataBinder.EvalContainer .DataItemquotstuIdquotgt runatquotserverquotgt更新 lt/asp:LinkButtongt ltasp:LinkButton IDquotupCancelquot CommandName quotediCancelquot runatquotserverquotgt取消 lt/asp:LinkButtongt lt/tdgt lttdgtltasp:LinkButton IDquotupdelquot CommandName quotediDeletequot CommandArgument ltDataBinder.EvalContainer .DataItemquotstuIdquotgt OnClientClick quotreturn onfirm确认删除吗?quot runatquotserverquotgt删除lt/asp:LinkButtongtlt/tdgt lt/trgt lt/asp:Panelgt lt/ItemTemplategt ltFooterTemplate gt lt/tablegt lt/FooterTemplategt lt/asp:Repeatergt ltbr /gt ampnbspltasp:Label IDquotLabel4quot runatquotserverquot Textquot共quotgtlt/asp:Labelgt ltasp:Label IDquotLabel5quot runatquotserverquot TextquotNquotgtlt/asp:Labelgt ltasp:Label IDquotLabel6quot runatquotserverquot Textquot页quotgtlt/asp:Labelgt ampnbsp ampnbsp ampnbspltasp:Label IDquotLabel1quot runatquotserverquot Textquot第quotgtlt/asp:Labelgt ltasp:Label IDquotLabel2quot runatquotserverquot TextquotNquot Widthquot16pxquotgtlt/asp:Labelgt ltasp:Label IDquotLabel3quot runatquotserverquot Textquot页quotgtlt/asp:Labelgt ampnbsp ampnbsp ampnbspampnbsp ltasp:LinkButton IDquotLinkButton1quot runatquotserverquot OnClickquotLinkButton1_Clickquotgt首页lt/asp:LinkButtongt ltasp:LinkButton IDquotLinkButton2quot runatquotserverquot OnClickquotLinkButton2_Clickquotgt上页lt/asp:LinkButtongt ltasp:LinkButton IDquotLinkButton3quot runatquotserverquot OnClickquotLinkButton3_Clickquotgt下页lt/asp:LinkButtongt ltasp:LinkButton IDquotLinkButton4quot runatquotserverquot OnClickquotLinkButton4_Click1quotgt尾页lt/asp:LinkButtongtlt/divgt lt/formgtlt/bodygt lt/htmlgt2、 后台代码public partial class _Default : System.Web.UI.Page public string id quotquot protected void Page_Loadobject sender EventArgs e if this.IsPostBack Band private void Band SqlConnection conn new SqlConnectionquotData SourceJIA-PCJIAInitial CatalogtestIntegratedSecurityTruequot SqlDataAdapter danew SqlDataAdapter quotselect from studentsquotconn DataSet ds new DataSet da.Fillds PagedDataSource pds new PagedDataSource pds.DataSource ds.Tables0.DefaultView pds.AllowPaging true pds.PageSize 3 int curpage if Request.QueryStringquotpagequot null curpage Convert .ToInt32Request .QueryStringquotpagequot else curpage 1 pds.CurrentPageIndex curpage - 1 Label2.Text curpage.ToString if ds.Tables0.Rows.Count pds.PageSize 0 Label5.Text Convert .ToString ds.Tables0.Rows.Count / pds.PageSize 1 else Label5.Text Convert .ToString ds.Tables0.Rows.Count / pds.PageSize if pds.IsFirstPage LinkButton2.PostBackUrl Request.CurrentExecutionFilePath quotpagequot Convert.ToStringcurpage - 1 LinkButton1.PostBackUrl Request.CurrentExecutionFilePath quotpage1quot if pds.IsLastPage LinkButton3.PostBackUrl Request.CurrentExecutionFilePath quotpagequotConvert.ToStringcurpage 1 LinkButton4.PostBackUrl Request.CurrentExecutionFilePath quotpagequot Label5.Text Repeater1.DataSource pds Repeater1.DataBind protected void Repeater1_ItemCommandobject source RepeaterCommandEventArgs e SqlConnection conn new SqlConnectionquotData SourceJIA-PCJIAInitial CatalogtestIntegratedSecurityTruequot if e.CommandName quotdelDeletequot e.CommandName quotediDeletequot string stuId e.CommandArgument.ToString conn.Open SqlCommand cmd new SqlCommandquotdelete from students where stuIdquotstuIdconn cmd.ExecuteNonQuery conn.Close else ife.CommandName quotdelUpdatequot id e.CommandArgument.ToString else if e.CommandName quotediUpdatequot string stuId e.CommandArgument.ToString string stuName TextBoxthis.Repeater1.Itemse.Item.ItemIndex.FindControlquotstuNamequot.Text.Trim stringstuClassTextBoxthis.Repeater1.Itemse.Item.ItemIndex.FindControlquotstuClassquot.Text.Trim stringstuAgeTextBoxthis.Repeater1.Itemse.Item.ItemIndex.FindControlquotstuAgequot.Text.Trim StringBuilder sbnew StringBuilder sb.Append quotupdate students quot sb.Append quotset stuNamestuNamequot sb.Append quot stuClassstuClassquot sb.Append quot stuAgestuAge quot sb.Append quotwhere stuIdquotstuIdquotquot conn.Open SqlCommand cmd conn.CreateCommand cmd.CommandText sb.ToString cmd.Parameters.Add new SqlParameter quotstuNamequotstuName cmd.Parameters.Addnew SqlParameterquotstuClassquot stuClass cmd.Parameters.Addnew SqlParameterquotstuAgequot int.ParsestuAge cmd.ExecuteNonQuery conn.Close else if e.CommandName quotediCancelquot id quot-1quot Bandprotected void Repeater1_ItemDataBoundobject sender RepeaterItemEventArgs e if e.Item.ItemType ListItemType.Item e.Item.ItemType ListItemType.AlternatingItem DataRowView rowv DataRowViewe.Item.DataItem string userid rowvquotstuIdquot.ToString if userid id.ToString Panele.Item.FindControlquotpanDelquot.Visible true Panele.Item.FindControlquotpanEditquot.Visible false else Panele.Item.FindControlquotpanDelquot.Visible false Panele.Item.FindControlquotpanEditquot.Visible true protected void LinkButton4_Click1object sender EventArgs e Bandprotected void LinkButton1_Clickobject sender EventArgs e Bandprotected void LinkButton2_Clickobject sender EventArgs e Bandprotected void LinkButton3_Clickobject sender EventArgs e Band Datalist嵌套 1、 前台代码: lthtml xmlnsquothttp://www.w3.org/1999/xhtmlquot gtlthead runatquotserverquotgt lttitlegt无标题页lt/titlegtlt/headgtltbodygt ltform idquotform1quot runatquotserverquotgt ltdivgt ltasp:DataList IDquotDataList1quot runatquotserverquot Heightquot199pxquotOnItemDataBoundquotDataList1_ItemDataBoundquot Widthquot188pxquotgt ltItemTemplategt ltasp:HyperLink IDquotHyperLink1quot runatquotserverquot NavigateUrlltquotdetails.aspxtypeidquotDataBinder.EvalContainer.DataItemquottypeidquot gt Textlt DataBinder.EvalContainer.DataItemquottypenamequot gtgtlt/asp:HyperLinkgt ltasp:Label IDquotLabel1quot runatquotserverquot TextltDataBinder.EvalContainer.DataItemquottypeidquot gt VisiblequotFalsequotgtlt/asp:Labelgt ltasp:DataList IDquotDataList2quot runatquotserverquot RepeatColumnsquot2quotgt ltItemTemplategt ltasp:HyperLink IDquotHyperLink2quot runatquotserverquot NavigateUrlltquotdetails.aspxtypeidquotDataBinder.EvalContainer.DataItemquottypeidquot gt TextltDataBinder.EvalContainer.DataItemquottypenamequot gtgtlt/asp:HyperLinkgt lt/ItemTemplategt lt/asp:DataListgt lt/ItemTemplategt lt/asp:DataListgtampnbsp ltasp:DataList IDquotDataList3quot runatquotserverquot OnItemCommandquotDataList3_ItemCommandquotgt ltItemTemplategt ltasp:Label IDquotLabel2quot runatquotserverquot TextltDataBinder.EvalContainer.DataItemquottypenamequot gtgtlt/asp:Labelgt ltasp:Button IDquotButton1quot runatquotserverquot Textquot编辑quot OnClickquotButton1_Clickquot /gt lt/ItemTemplategt ltEditItemTemplategt ltasp:TextBox IDquotTextBox1quot runatquotserverquot TextltDataBinder.EvalContainer.DataItemquottypenamequot gt Widthquot79pxquotgtlt/asp:TextBoxgt ltasp:Button IDquotButton2quot runatquotserverquot OnClickquotButton2_Clickquot Textquot更新quot /gt ltasp:Label IDquotLabel3quot runatquotserverquot TextltDataBinder.EvalContainer.DataItemquottypeidquot gt VisiblequotFalsequotgtlt/asp:Labelgt lt/EditItemTemplategt lt/asp:DataListgt ltpgtlt/pgt ltasp:DataList IDquotDataList4quot runatquotserverquot OnItemCommandquotDataList4_ItemCommandquotgt ltItemTemplategt ltasp:Label IDquotLabel4quot runatquotserverquot TextltDataBinder.EvalContainer.DataItemquottypenamequot gtgtlt/asp:Labelgt ltasp:Button IDquotButton3quot runatquotserverquot Textquot编辑quot /gt lt/ItemTemplategt ltEditItemTemplategt ltasp:DropDownList IDquotDropDownList1quot runatquotserverquotgt lt/asp:DropDownListgt ltasp:TextBox IDquotTextBox2quot runatquotserverquot Widthquot75pxquotgtlt/asp:TextBoxgt ltasp:Button IDquotButton4quot runatquotserverquot Textquot更新quot /gt ltasp:Label IDquotLabel3quot runatquotserverquot TextltDataBinder.EvalContainer.DataItemquottypeidquot gt VisiblequotFalsequotgtlt/asp:Labelgt ltasp:Label IDquotLabel5quot runatquotserverquot TextltDataBinder.EvalContainer.DataItemquotfathertypeidquot gt VisiblequotFalsequotgtlt/asp:Labelgt lt/EditItemTemplategt lt/asp:DataListgt ltasp:Label IDquotLabel6quot runatquotserverquot Textquotfathertypenamequotgtlt/asp:Labelgt ltasp:Label IDquotLabel7quot runatquotserverquot Textquotascquot VisiblequotFalsequotgtlt/asp:Labelgtlt/divgt ltasp:GridView IDquotGridView1quot runatquotserverquot AutoGenerateColumnsquotFalsequot AllowSortingquotTruequotOnSortingquotGridView1_Sortingquotgt ltColumnsgt ltasp:BoundField DataFieldquotfathertypenamequot HeaderTextquot大类名称quotSortExpressionquotfathertypenamequot /gt ltasp:BoundField DataFieldquotchildtypenamequot HeaderTextquot小类名称quotSortExpressionquotchildtypenamequot /gt ltasp:HyperLinkField DataNavigateUrlFieldsquotchildtypeidfathertypeidquotDataNavigateUrlFormatStringquotdetails.aspxchildtypeid0ampfathertypeid1quot DataTextFieldquotchildtypenamequot /gt ltasp:TemplateFieldgt ltItemTemplategt ltasp:HyperLink IDquotHyperLink3quot runatquotserverquot NavigateUrlltquotdetails.aspxchildtypeidquotDataBinder.EvalContainer.DataItemquotchildtypeidquotquotampfathertypeidquotDataBinder.EvalContainer.DataItemquotfathertypeidquot gtgtHyperLinklt/asp:HyperLinkgt lt/ItemTemplategt lt/asp:TemplateFieldgt lt/Columnsgt lt/asp:GridViewgt lt/formgtlt/bodygtlt/htmlgt 2、 后台代码:using System.Web.UI.WebControls.WebPartsusing System.Web.UI.HtmlControlsusing System.Data.SqlClientpublic partial class _Default : System.Web.UI.Page protected void Page_Loadobject sender EventArgs e if this.IsPostBack dataBind dataBind1 dataBind2 private void dataBind SqlConnection conn new SqlConnection conn.ConnectionString quotserver1-112SQLEXPRESSdatabasemydbuidtestpwdtestquot SqlDataAdapter da new SqlDataAdapterquotselect from fathertypequot conn DataSet ds new DataSet da.Fillds DataList1.DataSource ds.Tables0.DefaultView DataList1.DataBind DataList3.DataSource ds.Tables0.DefaultView DataList3.DataBind private void dataBind2 SqlConnection conn new SqlConnection conn.ConnectionString quotserver1-112SQLEXPRESSdatabasemydbuidtestpwdtestquot SqlDataAdapter da new SqlDataAdapterquotselect fathertype.typeid as fathertypeidchildtype.typeid aschildtypeidfathertype.typename as fathertypenamechildtype.typename as childtypename from childtype left joinfathertype on fathertype.typeidchildtype.fathertypeidquot conn DataSet ds new DataSet da.Fillds // ds.Tables0.DefaultView.Sort sortexp quot quot sorttype ds.Tables0.DefaultView.Sort Label6.Text quot quot Label7.Text GridView1.DataSource ds.Tables0.DefaultView GridView1.DataBind private void dataBind1 SqlConnection conn new SqlConnection conn.ConnectionString quotserver1-112SQLEXPRESSdatabasemydbuidtestpwdtestquot SqlDataAdapter da new SqlDataAdapterquotselect from childtypequot conn DataSet ds new DataSet da.Fillds DataList4.DataSource ds.Tables0.DefaultView DataList4.DataBind protected void DataList1_ItemDataBoundobject sender DataListItemEventArgs e try Label lb Labele.Item.FindControlquotLabel1quot SqlConnection conn new SqlConnection .