//更新
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        strconn = ConfigurationSettings.AppSettings["dsn"];
        con = new SqlConnection(strconn);
        string sqlstr = "update teacher set name='"
            + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim() + "',birthday='"
            + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim() + "',sex='"
            + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString().Trim() + "',faction='"
            + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[5].Controls[0])).Text.ToString().Trim() + "',nation='"
            + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[6].Controls[0])).Text.ToString().Trim() + "' where ID='" 
            + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
        cmd=new SqlCommand(sqlstr,con);
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();
        GridView1.EditIndex = -1;
        bind();
    }

解决方案 »

  1.   

    你调整模板中的Textbox的样式,改成普通的,然后把Textbox都左对齐。把里面Textbox改成能自己调整大小的。
      

  2.   

    我没有设置模板啊,这是编辑时用textbox类来控制的啊,你能说具体点吗
      

  3.   

    我没有设置模板啊,这是编辑时用textbox类来控制的啊,你能说具体点吗
      

  4.   

    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
            AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="ArticleID" 
            DataSourceID="SqlDataSource1" CaptionAlign="Left" Width="740px">
            <Columns>
                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" >
                <ItemStyle HorizontalAlign="Center" Width="50px" />
                </asp:CommandField>
                <asp:BoundField DataField="ArticleTitle" HeaderText="文章标题" 
                    SortExpression="ArticleTitle" Visible="True" />
                <asp:BoundField DataField="ArticleContent" HeaderText="文章内容" 
                    SortExpression="ArticleContent" />
                <asp:BoundField DataField="dateTime" HeaderText="发表时间" 
                    SortExpression="dateTime" />
            </Columns>
        </asp:GridView>
      

  5.   

    直接设置textBox的高和宽就行了
      

  6.   

        if ((e.Row.RowState & DataControlRowState.Edit) != 0)
            {
                TextBox txt1 = e.Row.Cells[1].Controls[0] as TextBox;
                txt1.Width = 50;           
                TextBox txt3 = e.Row.Cells[4].Controls[0] as TextBox;
                txt3.Width = 30;
                TextBox txt4= e.Row.Cells[5].Controls[0] as TextBox;
                txt4.Width = 40;
                TextBox txt5 = e.Row.Cells[6].Controls[0] as TextBox;
                txt5.Width = 50;
            }