namespace TestWeb
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
BindsData();
}
protected void BindsData()
{
Database cd = DatabaseFactory.CreateDatabase();
DbCommand ds = cd.GetSqlStringCommand("select * from quanxian");
try
{
//
DataTable tb = cd.ExecuteDataSet(ds).Tables[0];
//
this.GridView1.DataSource = tb;
this.GridView1.DataBind();
}
catch (Exception ex)
{
string err = ex.Message;
//
Response.Write(err); }
finally
{
if (ds != null) ds.Dispose();
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
Response.Write("wwww");
CheckBox cb = (CheckBox)e.Row.FindControl("checkbox1");
DataRowView gvr = (DataRowView)e.Row.DataItem;
if (cb != null)
{
Response.Write(gvr["adds"].ToString());
Response.Write("sss");
if (gvr["adds"].ToString() == "1")
{
cb.Checked = true; } }
} }
}
本来是Response.Write("wwww");我是想引起大家注意,加个颜色。没加成。
就是这行代码为什么没有执行。
加个if(!Page。IsPostBack){
BindsData();
}
看看网页源代码的第一行有没有设一个断点调试一下
<asp:GridView ID="GridView1" runat="server" Width="538px"
AutoGenerateColumns="False" OnRowDataBound="GridView1_RowDataBound">OnRowDataBound="GridView1_RowDataBound"这个事件不晓得什么时候去掉了。
结帖 分平分啊。