【问题标题】:Fit Text box in excel cell?在excel单元格中适合文本框?
【发布时间】:2013-09-25 13:12:28
【问题描述】:

我正在尝试将文本框放入 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");
        }
    }

如何在网格单元格中正确放置。

【问题讨论】:

  • 1000px? 360 像素?这些都是巨大的尺寸。
  • 实际上它是一个评论字段......并且客户希望在gridview中看到完整的评论
  • 将文本框的文本模式改为多行
  • 完成或仍然没有得到你想要的
  • 无法在 RowDatabound 中做到这一点...请举个例子

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


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-06
    • 2017-07-23
    • 1970-01-01
    • 2021-11-12
    • 1970-01-01
    相关资源
    最近更新 更多