为什么vs2008中gridview控件的id属性不能在cs中调用
在a.aspx中拖了一个gridview控件,在a.cs中写gridview1.时显示没有gridview1属性(gridview1是gridview控件的id),是否缺...
在a.aspx中拖了一个gridview控件,在a.cs中写gridview1.时显示没有gridview1属性(gridview1是gridview控件的id),是否缺少引用。
展开
5个回答
展开全部
这个问题很很简单的。。。
把你刚刚脱的这个GridView控件删掉,然后去后台进行.cs的数据绑定。。。。及其各种操作
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using DAL;
namespace UI.Admin
{
public partial class selectZhiG : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
selectbind();
}
}
private void selectbind()
{
gvzhigong.DataSource = workerBLL.Find();
gvzhigong.DataBind();
}
protected void gvzhigong_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvzhigong.PageIndex = e.NewPageIndex;
selectbind();
}
protected void gvzhigong_RowEditing(object sender, GridViewEditEventArgs e)
{
gvzhigong.PageIndex = e.NewEditIndex;
selectbind();
}
protected void gvzhigong_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
try
{
int index = e.RowIndex;
string workerId = gvzhigong.DataKeys[index].Value.ToString();
Worker a = new Worker();
a = workerBLL.Find(workerId);
a.WorkName = ((TextBox)(gvzhigong.Rows[index].Cells[2].Controls[0])).Text.Trim();
a.WorkerSex = ((TextBox)(gvzhigong.Rows[index].Cells[3].Controls[0])).Text.Trim();
a.Workermoney = Convert.ToDecimal(((TextBox)(gvzhigong.Rows[index].Cells[4].Controls[0])).Text.Trim());
a.CangkuHao = ((TextBox)(gvzhigong.Rows[index].Cells[1].Controls[0])).Text.Trim();
a.WorkNum = ((TextBox)(gvzhigong.Rows[index].Cells[0].Controls[0])).Text.Trim();
bool i = workerBLL.Update(a);
if (i == true)
{
Response.Write("<script>alert('更新成功')</script>");
}
else
{
Response.Write("<script>alert('更新失败')</script>");
}
gvzhigong.EditIndex = -1;
selectbind();
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this,GetType(),"mgs", "alert('更新失败,情检查输入数据格式是否正确');", true);
}
}
protected void gvzhigong_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int index = e.RowIndex;
string st = gvzhigong.DataKeys[index].Value.ToString();
Label1.Text = st;
Worker a = new Worker();
a.WorkNum = st;
bool i =workerBLL.Del(st);
if (i == true)
{
Response.Write("<script>alert('删除成功')</script>");
}
else
{
Response.Write("<script>alert('此员工不能删除,因为此员工有处理订单存在')</script>");
}
selectbind();
}
protected void gvzhigong_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
gvzhigong.EditIndex = -1;
selectbind();
}
protected void Button1_Click(object sender, EventArgs e)
{
string strName = TextBox2.Text.Trim();
gvzhigong.DataSource = workerBLL.FindSearch(strName);
gvzhigong.DataBind();
}
}
}
把你刚刚脱的这个GridView控件删掉,然后去后台进行.cs的数据绑定。。。。及其各种操作
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using DAL;
namespace UI.Admin
{
public partial class selectZhiG : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
selectbind();
}
}
private void selectbind()
{
gvzhigong.DataSource = workerBLL.Find();
gvzhigong.DataBind();
}
protected void gvzhigong_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvzhigong.PageIndex = e.NewPageIndex;
selectbind();
}
protected void gvzhigong_RowEditing(object sender, GridViewEditEventArgs e)
{
gvzhigong.PageIndex = e.NewEditIndex;
selectbind();
}
protected void gvzhigong_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
try
{
int index = e.RowIndex;
string workerId = gvzhigong.DataKeys[index].Value.ToString();
Worker a = new Worker();
a = workerBLL.Find(workerId);
a.WorkName = ((TextBox)(gvzhigong.Rows[index].Cells[2].Controls[0])).Text.Trim();
a.WorkerSex = ((TextBox)(gvzhigong.Rows[index].Cells[3].Controls[0])).Text.Trim();
a.Workermoney = Convert.ToDecimal(((TextBox)(gvzhigong.Rows[index].Cells[4].Controls[0])).Text.Trim());
a.CangkuHao = ((TextBox)(gvzhigong.Rows[index].Cells[1].Controls[0])).Text.Trim();
a.WorkNum = ((TextBox)(gvzhigong.Rows[index].Cells[0].Controls[0])).Text.Trim();
bool i = workerBLL.Update(a);
if (i == true)
{
Response.Write("<script>alert('更新成功')</script>");
}
else
{
Response.Write("<script>alert('更新失败')</script>");
}
gvzhigong.EditIndex = -1;
selectbind();
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this,GetType(),"mgs", "alert('更新失败,情检查输入数据格式是否正确');", true);
}
}
protected void gvzhigong_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int index = e.RowIndex;
string st = gvzhigong.DataKeys[index].Value.ToString();
Label1.Text = st;
Worker a = new Worker();
a.WorkNum = st;
bool i =workerBLL.Del(st);
if (i == true)
{
Response.Write("<script>alert('删除成功')</script>");
}
else
{
Response.Write("<script>alert('此员工不能删除,因为此员工有处理订单存在')</script>");
}
selectbind();
}
protected void gvzhigong_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
gvzhigong.EditIndex = -1;
selectbind();
}
protected void Button1_Click(object sender, EventArgs e)
{
string strName = TextBox2.Text.Trim();
gvzhigong.DataSource = workerBLL.FindSearch(strName);
gvzhigong.DataBind();
}
}
}
展开全部
说清楚点
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你按F6系统会提示你错误
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
删掉重新拖个,生成解决方案等。。。是gridview1点不出属性?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询