excel单元格中的文本框适合?

时间:2013-09-25 13:12:29

标签: c# asp.net .net gridview web

我正在尝试在行数据绑定中的ASP.NET gridView中放置一个文本框。在这里,它没有在cell.to中正确调整以适应它。

在行数据绑定中我正在使用

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onclick", "this.style.backgroundColor='orange'");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='white'");
            e.Row.Cells[2].Width = new Unit("700px");
            TextBox txtAddress = new TextBox();
            txtAddress.ReadOnly = false;
            e.Row.Cells[2].Controls.Add(txtAddress);
            e.Row.Cells[2].Style.Add("text-align", "center");
            txtAddress.Text = e.Row.Cells[2].Text;
            GridView1.Attributes.Add("style", "table-layout:fixed");
        }
    }

如何在网格单元中正确安装。

1 个答案:

答案 0 :(得分:0)

我正在尝试这个并且工作正常......

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onclick", "this.style.backgroundColor='orange'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='white'");
                e.Row.Cells[2].Width = new Unit("700px");
                TextBox txtAddress = new TextBox();
                txtAddress.ReadOnly = false;
                //txtAddress.Style = "width:100%;";
                txtAddress.Style.Add("width", "99%");
                e.Row.Cells[2].Controls.Add(txtAddress);
                e.Row.Cells[2].Style.Add("text-align", "center");
                txtAddress.Text = e.Row.Cells[2].Text;
                GridView1.Attributes.Add("style", "table-layout:fixed");
            }
        }

100%在数学上是准确的,但99为我做了诀窍:)