在ASP.NET环境中,如何用date对象将GridView与数据库绑定(包括一个checkBox)
我用date对象将GrideView控件与数据库绑定之后,又加了一列checkbox之后GridView中显示不出数据,是怎么回事?前台代码:分后台代码:namespac...
我用date对象将GrideView控件与数据库绑定之后,又加了一列checkbox之后GridView中显示不出数据,是怎么回事? 前台代码:分后台代码: namespace Homework.Admin { public partial class ChenJI : System.Web.UI.Page { SqlHelper data = new SqlHelper(); Alert js = new Alert(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Get_Article(); BindClass(); BindKeMu(); BindStudent(); } } private void Get_Article() { try { gvFilms.DataSource = GetCodeBy(0); gvFilms.DataBind(); } catch { } } protected void gvFilms_PageIndexChanging(object sender, GridViewPageEventArgs e) { gvFilms.PageIndex = e.NewPageIndex; Get_Article(); } protected void gvFilms_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#f6f6f6',this.style.fontWeight='';"); e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';"); } if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Attributes.Add("onclick", "this.style.backgroundColor='#f6f6f6'; this.style.color='buttontext';this.style.cursor='default';"); } } public DataSet GetCodeBy(int iCount) { SqlHelper date = new SqlHelper(); string strTop = ""; if (iCount > 1) { strTop = "top " + iCount.ToString(); } string sql = "select " + strTop + " * from [ChengJi] "; SqlConnection con = new SqlConnection(SqlHelper.connstring); SqlCommand cmd = new SqlCommand(sql, con); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = null; try { con.Open(); ds = new DataSet(); da.Fill(ds); } catch (SqlException ex) { throw ex; } catch (Exception ex) { throw ex; } finally { con.Close();} return ds; } } }
展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询