数据绑定与显示

1,gridview 的数据显示与更新
DataSet ds=new DataSet()…………
this.gridview1.datasource=ds.tables[0].defaultview;

设置DataKeyNames 主键,与数据列名
更新时获得原数据:string str=this.gridview1.DataKeyNames[e.RowIndex][0].tostring();
tb中的数据:string str=((textbox)this.gridview1.Rows[e.index].Cells[0].Controls[0]).Text.tostring();
2,repeater & datalist
     在itemtemplate中获取绑定数据源(DS)的条目:<%# DataBinder.Eval(Container.DataItem,"列名") %>
<%# Eval(" column name")%>
<
     遍历每一项:foreach(datalistItem dli in datalist.items)
                {
                        checkbox cb=(checkbox)dli.findcontrol("控件ID")
                }

点击列中的linkbutton
 添加onclick事件即可
首先<asp:linkbutton id="lbtn" Text="lbtn" command="accept" ></ linkbutton>
    选择事件中的Itemcommand 事件
    protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandSource.GetType() == typeof(LinkButton))
        {
            if(((LinkButton)e.CommandSource).CommandName=="accept")
            {
                Response.Write("accept");
                Response.Write("accept" + ((Label)(e.Item.FindControl("lblID"))).Text);
                //获取当前行的列数获取源表中不连续ID号:
                    ds.Tables[0].Rows[e.Item.ItemIndex]["Id"].ToString();

            }
            if (((LinkButton)e.CommandSource).CommandName== "reject")
            {
                Response.Write("reject");
            }
        }
    }

分页:
        int currentindex = onvert.ToInt32(this.lblcurrentpage.Text);
        pds.DataSource = ds.Tables[0].DefaultView;
        pds.AllowPaging = true;
        pds.PageSize = 3;
        this.lblpagecount.Text = pds.PageCount;
        pds.CurrentPageIndex = currentindex;
    

posted on 2010-06-15 21:14  Henry_Wang  阅读(160)  评论(0编辑  收藏  举报

导航