首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

一个很奇怪的有关问题,GridView修改出现文本框

2013-01-11 
一个很奇怪的问题,GridView修改出现文本框在一个页面有一个GridView绑定数据,GridView里有一修改列asp:Bu

一个很奇怪的问题,GridView修改出现文本框
在一个页面有一个GridView绑定数据,GridView里有一修改列<asp:ButtonField HeaderText="修改" Text="修改" CommandName="Edit" ItemStyle-Width= "40px" /> ,点击”修改“ 在本页的TextBox里显示当前列的名字,如下图:

一个很奇怪的有关问题,GridView修改出现文本框

问题是,如果我点完修改(GridView里的修改),在点下修改(GridView里的修改),在GridView列里会出现文本框 - -!如下图

一个很奇怪的有关问题,GridView修改出现文本框

下面是代码只是GridView的代码
.aspx


                                    CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"
                                    Text="删除"></asp:LinkButton>
                            </ItemTemplate>
                            <HeaderStyle Width="10%" />
                        </asp:TemplateField> 
        </Columns>
        <RowStyle CssClass="RowStyle" HorizontalAlign="Center" />
        <SelectedRowStyle HorizontalAlign="Center" />
        <HeaderStyle  CssClass="HeaderStyle" />
        <AlternatingRowStyle CssClass="AlternatingRowStyle" />
    </asp:GridView>



.aspx.cs

   protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
       int index = int.Parse(e.CommandArgument.ToString());
        int id = int.Parse(this.GridView1.DataKeys[index].Value.ToString());
        Label3.Text = id.ToString();
        if (e.CommandName == "Edit")
        {
            SqlConnection conn = new SqlConnection(ConnectionString);
            Button1.Text = "修改";
            Button1.Enabled = true;
            DataSet ds = cl.select_x(id, "product_sort2");//根据id和表名查询数据(方法)
            TextBox1.Text = ds.Tables[0].Rows[0]["name"].ToString().Trim();
        }
    }
    //序列号
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowIndex >= 0)
        {
            if (Label1.Text == "1")
            {
                e.Row.Cells[0].Text = Convert.ToString(e.Row.DataItemIndex + 1);
            }
            else


            {
                e.Row.Cells[0].Text = Convert.ToString(e.Row.DataItemIndex + 1 + int.Parse(Label1.Text.ToString()) * 10 - 10);
            }
        }
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {

    }



在线等,求指点一个很奇怪的有关问题,GridView修改出现文本框
[解决办法]
查看后台的GridView1_RowEditing这个事件。
[解决办法]
修改如下代码:
if (e.CommandName == "Edit")        {            SqlConnection conn = new SqlConnection(ConnectionString);            Button1.Text = "修改";            Button1.Enabled = true;            DataSet ds = cl.select_x(id, "product_sort2");//根据id和表名查询数据(方法)            TextBox1.Text = ds.Tables[0].Rows[0]["name"].ToString().Trim();        }

[解决办法]
编辑完后 刷新下 界面 
[解决办法]
 onrowediting="GridView1_RowEditing" 这个事件去掉
[解决办法]
onrowediting="GridView1_RowEditing" 这个事件去掉 
[解决办法]
e.Cancel=true;好像是这样。。。

热点排行