各位大侠,帮我看看,到底是什么状况..
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
OnRowDataBound="GridView1_RowDataBound"
OnPageIndexChanging="GridView1_PageIndexChanging"
OnRowDeleting="GridView1_RowDeleting"
OnRowCancelingEdit="GridView1_RowCancelingEdit"
OnRowEditing="GridView1_RowEditing"
OnRowUpdating="GridView1_RowUpdating" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="ClassifyID" HeaderText="一级主码" ReadOnly="True">
<ItemStyle Width="18%" />
</asp:BoundField>
<asp:BoundField DataField="ParentID" HeaderText="二级子码" >
<ItemStyle Width="18%" />
</asp:BoundField>
<asp:BoundField DataField="ClassifyName" HeaderText="图块类别">
<ItemStyle Width="18%" />
</asp:BoundField>
<asp:BoundField DataField="ClassifyMark" HeaderText="分值" >
<ItemStyle Width="18%" />
</asp:BoundField>
<asp:CommandField HeaderText="编辑" ShowEditButton="True">
<ItemStyle Width="18%" />
</asp:CommandField>
<asp:CommandField HeaderText="删除" ShowDeleteButton="True"><ItemStyle width="10%" /></asp:CommandField>
</Columns>
cs:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bind();
}
}public void Bind()
{
string strsqlcode; strsqlcode = "select ClassifyID ,ParentID ,ClassifyName ,ClassifyMark from Gallery_Dwg_Dir";
conn = new SqlConnection(strcon);
conn.Open();
SqlDataAdapter dpart = new SqlDataAdapter(strsqlcode, conn);
DataSet dset = new DataSet();
dpart.Fill(dset);
GridView1.DataSource = dset.Tables[0];
GridView1.DataBind();
GridView1.DataKeyNames = new string[] { "ClassifyID" };
conn.Close();
} protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
Bind();
} protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string strclsyid = GridView1.DataKeys[e.RowIndex].Value.ToString().Trim();
string strdelcode = "delete from Gallery_Dwg_Dir where ClassifyID=" + strclsyid + "";
conn = new SqlConnection(strcon);
cmd = new SqlCommand(strdelcode, conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
Bind();
} protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if ((e.Row.RowState == (DataControlRowState.Edit | DataControlRowState.Alternate)) || (e.Row.RowState == DataControlRowState.Edit))
{
TextBox curText;
for (int i = 1; i < 4; i++)
{
curText = (TextBox)e.Row.Cells[i].Controls[0];
curText.Width = Unit.Pixel(80);
}
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate && e.Row.RowState != DataControlRowState.Edit)
{
((LinkButton)(e.Row.Cells[5].Controls[0])).Attributes.Add("onclick", "javascript:return confirm('确定删除?')");
}
}
} protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
Bind();
} protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
Bind();
} protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string strParentID;
GridViewRow row = GridView1.Rows[e.RowIndex];
if (((TextBox)(row.Cells[2].Controls[0])).Text.ToString().Trim() == "")
{
strParentID = "0";
}
else
{
strParentID = ((TextBox)(row.Cells[2].Controls[0])).Text.ToString().Trim();
}
string strsqlupdate = "update Gallery_Dwg_Dir set ParentID='" + strParentID + "',
ClassifyName='" + ((TextBox)(row.Cells[3].Controls[0])).Text.ToString().Trim() + "',
ClassifyMark='" + ((TextBox)(row.Cells[4].Controls[0])).Text.ToString().Trim() + "'
where ClassifyID='" + GridView1.DataKeys[e.RowIndex].Value.ToString().Trim() + "'";
try
{
conn = new SqlConnection(strcon);
cmd = new SqlCommand(strsqlupdate, conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
GridView1.EditIndex = -1;
Bind();
}
catch (Exception err)
{
Response.Write(err.Message);
}
}
除了“更新”按钮点下去,一点反应也没有(GridView1_RowUpdating(),都不执行),别的都可以正常使用
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
OnRowDataBound="GridView1_RowDataBound"
OnPageIndexChanging="GridView1_PageIndexChanging"
OnRowDeleting="GridView1_RowDeleting"
OnRowCancelingEdit="GridView1_RowCancelingEdit"
OnRowEditing="GridView1_RowEditing"
OnRowUpdating="GridView1_RowUpdating" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="ClassifyID" HeaderText="一级主码" ReadOnly="True">
<ItemStyle Width="18%" />
</asp:BoundField>
<asp:BoundField DataField="ParentID" HeaderText="二级子码" >
<ItemStyle Width="18%" />
</asp:BoundField>
<asp:BoundField DataField="ClassifyName" HeaderText="图块类别">
<ItemStyle Width="18%" />
</asp:BoundField>
<asp:BoundField DataField="ClassifyMark" HeaderText="分值" >
<ItemStyle Width="18%" />
</asp:BoundField>
<asp:CommandField HeaderText="编辑" ShowEditButton="True">
<ItemStyle Width="18%" />
</asp:CommandField>
<asp:CommandField HeaderText="删除" ShowDeleteButton="True"><ItemStyle width="10%" /></asp:CommandField>
</Columns>
cs:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bind();
}
}public void Bind()
{
string strsqlcode; strsqlcode = "select ClassifyID ,ParentID ,ClassifyName ,ClassifyMark from Gallery_Dwg_Dir";
conn = new SqlConnection(strcon);
conn.Open();
SqlDataAdapter dpart = new SqlDataAdapter(strsqlcode, conn);
DataSet dset = new DataSet();
dpart.Fill(dset);
GridView1.DataSource = dset.Tables[0];
GridView1.DataBind();
GridView1.DataKeyNames = new string[] { "ClassifyID" };
conn.Close();
} protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
Bind();
} protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string strclsyid = GridView1.DataKeys[e.RowIndex].Value.ToString().Trim();
string strdelcode = "delete from Gallery_Dwg_Dir where ClassifyID=" + strclsyid + "";
conn = new SqlConnection(strcon);
cmd = new SqlCommand(strdelcode, conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
Bind();
} protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if ((e.Row.RowState == (DataControlRowState.Edit | DataControlRowState.Alternate)) || (e.Row.RowState == DataControlRowState.Edit))
{
TextBox curText;
for (int i = 1; i < 4; i++)
{
curText = (TextBox)e.Row.Cells[i].Controls[0];
curText.Width = Unit.Pixel(80);
}
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate && e.Row.RowState != DataControlRowState.Edit)
{
((LinkButton)(e.Row.Cells[5].Controls[0])).Attributes.Add("onclick", "javascript:return confirm('确定删除?')");
}
}
} protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
Bind();
} protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
Bind();
} protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string strParentID;
GridViewRow row = GridView1.Rows[e.RowIndex];
if (((TextBox)(row.Cells[2].Controls[0])).Text.ToString().Trim() == "")
{
strParentID = "0";
}
else
{
strParentID = ((TextBox)(row.Cells[2].Controls[0])).Text.ToString().Trim();
}
string strsqlupdate = "update Gallery_Dwg_Dir set ParentID='" + strParentID + "',
ClassifyName='" + ((TextBox)(row.Cells[3].Controls[0])).Text.ToString().Trim() + "',
ClassifyMark='" + ((TextBox)(row.Cells[4].Controls[0])).Text.ToString().Trim() + "'
where ClassifyID='" + GridView1.DataKeys[e.RowIndex].Value.ToString().Trim() + "'";
try
{
conn = new SqlConnection(strcon);
cmd = new SqlCommand(strsqlupdate, conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
GridView1.EditIndex = -1;
Bind();
}
catch (Exception err)
{
Response.Write(err.Message);
}
}
除了“更新”按钮点下去,一点反应也没有(GridView1_RowUpdating(),都不执行),别的都可以正常使用
解决方案 »
- 无法从“social.Web.Controls.logo”转换为“System.Web.UI.Page”
- SqlServer2005开发版安装后找不到本地服务器
- 1 2 2 1 1 2 2 算法问题,有兴趣的来帮帮忙了
- 困扰!如何让.aspx页面通过点击按钮弹出确认取消对话框?
- 关于asp.net中,动态加载ascx控件后页面刷新或回传ascx控件消逝的问题
- 请问asp.net如何调用sql server2000里自定义的函数
- asp.net程序调用cgi接口程序
- 如果让<input type="file" id="myFile" runat="server"> 在点击浏览时只显示需要的文件格式(如:只显示*.jpg,*.gif,*.bmp)
- 小数如何在textbox上呈现为百分比
- 关于datagrid的selecteditem事件
- 如何在母版页中取得当前嵌入的子页面的名字
- asp.net开发商城与asp.net开发类似开心这种社区互动的应用技术有什么差别吗?
public void Bind()
{
string strsqlcode; strsqlcode = "select ClassifyID ,ParentID ,ClassifyName ,ClassifyMark from Gallery_Dwg_Dir";
conn = new SqlConnection(strcon);
conn.Open();
SqlDataAdapter dpart = new SqlDataAdapter(strsqlcode, conn);
DataSet dset = new DataSet();
dpart.Fill(dset);
GridView1.DataSource = dset.Tables[0];
GridView1.DataBind();
GridView1.DataKeyNames = new string[] { "ClassifyID" };
conn.Close();
} 我上面是这样写的 应该怎么改么?
根本没执行
我没用过RowUpdating事件.
如果你调试正常就说明这个事件对UPDATE不起作用。
否则的话你调试方式错了,不太可能吧
我把这句删了 OnRowUpdating="GridView1_RowUpdating" ,就是说,更新,按钮事件没定义。点击“更新”按钮也不会出错,就是没反应
如果,都没有错误,我都不知道怎么调试了你教我下 我学asp.net 不久,都不怎么懂
静待高人吧
经过,把里面的控件 一个个,排除。
终于发现,导致更新按钮的脚本不执行的原因是与“RequiredFieldValidator”验证脚本冲突