C#中GridView自带的"编辑"按钮!

发布时间:2024-11-02 18:38 发布:上海旅游网

问题描述:

点击"编辑"之后能够进入编辑的状态,但是点"确定"和"取消"都不会调用相应的代码,求大虾出手相助..

前台:

<asp:GridView ID="GridView1" runat="server" BackColor="White"
BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal"

AutoGenerateColumns=False
OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating"
OnRowCancelingEdit="GridView1_RowCancelingEdit">

<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
<Columns>
<asp:BoundField HeaderText="用户ID" DataField="读者ID" />
<asp:BoundField HeaderText="姓名" DataField="姓名" />
<asp:BoundField HeaderText="权限" />
<asp:BoundField HeaderText="邮箱" />
<asp:CommandField HeaderText="编辑" ShowEditButton="True" />
</Columns>

<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
<AlternatingRowStyle BackColor="#F7F7F7" />
</asp:GridView>

后台代码:

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
Label3.Text = "Edit";
GridView1.EditIndex = e.NewEditIndex;
bind();
}

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
Label3.Text = "update";
GridView1.EditIndex = -1;
bind();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
Label3.Text = "Cancel";
GridView1.EditIndex = -1;
bind();
}

跑起来后,点击"编辑"了,label3会显示"Edit",但是点另外两个都没反应..

问题解答:

你使用F11逐行调试一下看看吧....像编程这种东西,需要会调试才行,呵呵...
【在要检查的代码处设置一些断点,按F5启动调试,之后逐次按F11逐行执行,就可以看到你的那段代码具体执行没有了】
呵呵O(∩_∩)O~,希望我的回答对你有所帮助!

用模版能实现。

不给分还想问复杂问题?

热点新闻