如何做一个含有GridView的用户控件,如何在网页中动态指定其属性。
请详细说明,我是想做好后,在页面中使用这个控件,并且这个控件的列,数据源,数据绑定都要动态指定。谢谢

解决方案 »

  1.   

    可以的,注意把属性序列化到viewstate中,要不然回传之后会丢失
      

  2.   

    GridView g = (GridView)用户控件ID.Controls[0].FindControl("GridView1");
    然后对g操作不就行了?
      

  3.   

    把gridview的sqldatasource和column等属性都作为自定义控件的属性
      

  4.   

    GridView g = (GridView)用户控件ID.Controls[0].FindControl("GridView1");
    然后对g操作不就行了?---------------------------------
    我这样做了,但数据没有显示,我在后台跟踪了SQL,已经执行了SQL与语句,且有数据。
      

  5.   

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;public partial class sysmana_AreaEdit : System.Web.UI.Page
    {    protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Area a = new Area();
                GridView g = (GridView)GridViewForm1.Controls[0].FindControl("GridView1");
                g.DataSource = a.getAreaByGrade(0);
                g.DataBind();
                                      
            }
        }
    }
    --------------------
    其中Area 是我定义的业务逻辑层,a.getAreaByGrade(0);是读取数据,后台跟踪到有数据,但Databind却没有显示数据
      

  6.   

    在OnInit阶段设置,那就没问题了。
      

  7.   

    GridView g = (GridView)用户控件ID.Controls[0].FindControl("GridView1");
    然后对g操作不就行了?
    -----------------------------------------------------------------------
    按此方法,然后再动态添加数据绑定和列,已OK,但新问题出来了,我在页面动态添加了CommandButton cfEditcfEdit.ShowEditButton = true;
    cfEdit.ShowDeleteButton = true;当我点击edit和delete时,提示我激发了未处理的事件“RowEditing”和"RowDeleting"
    但在用护控件中没有这两个事件及其他相关事件,我该如何处理,谢谢!!
      

  8.   

    将GridViewd的接口给包装到你的用户控件接口上。
    如,
    用户控件.方法()
    {
        GridView.方法();
    }
      

  9.   

    wlb854(不倒翁) ( ) ,能不能说得更详细点,我是初学,谢谢
      

  10.   

    XIEWH() :事件不是动态生成,怎么在用户控件里写呢,比如用户控件里的GridView和“RowEditing”和"RowDeleting"事件,谢谢
      

  11.   

    和普通的一样写啊。比如简单的PageIndexChanging吧
    用户控件里:
        DataSet ds;
        public DataSet displaydataset
        {
            set { ds = value; }
            get { return ds; }
        }
        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            GridView1.DataSource = displaydataset;
            GridView1.DataBind();
        }
    aspx里:con = new SqlConnection(连接字符串);
            da = new SqlDataAdapter("sql语句", con);
            ds = new DataSet();
            da.Fill(ds);
            foot1.displaydataset = ds;
            GridView g = (GridView)用户控件ID.Controls[0].FindControl("GridView1");
            g.DataSource = ds;
            g.DataBind();
      

  12.   

    foot1.displaydataset = ds;→用户控件ID.displaydataset=ds;- -!