0

私はこのようにします:

 if (e.Row.Cells[3].Text != null && e.Row.Cells[3].Text != " " 
          && e.Row.Cells[3].Text != "")
 {
     e.Row.Cells[3].Attributes.Add("readonly", "true");
 }

しかし、うまくいきません。セルが空または " " を含む場合、readonly プロパティを true に設定する必要があります。

4

3 に答える 3

0

direct wayに設定Gridview columnするものはありませんreadonly
ただし、Gridivew のイベントでcontrols to readonlyその列にあるものを設定できます。RowDataBound例えば

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowState == DataControlRowState.Edit || e.Row.RowState == DataControlRowState.Alternate)
    {
        TextBox txt = (TextBox)e.Row.FindControl("ControlID");
        txt.ReadOnly = true;
    }
}
于 2013-02-13T05:54:11.727 に答える
-1

これは機能しますか?

if (e.Row.Cells[3].Text != null && e.Row.Cells[3].Text != " " && e.Row.Cells[3].Text != "")
 {
     e.Row.Cells[3].ReadOnly = true;
 }

確かにがプロパティBoundFieldを持っているようです。しかし、がタイプであるかどうかはわかりません。多分あなたはそれをキャストしなければならないかもしれませんReadOnlye.Row.Cells[3]BoundFieldBoundField

于 2013-02-13T05:16:18.640 に答える