0

我正在尝试gridView在行数据绑定的 ASP.NET 中放置一个文本框。在这里,它没有在 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");
        }
    }

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

4

1 回答 1

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 对我有用 :)

于 2013-09-25T16:30:37.180 回答