Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 如何将BoundField单元格中的readonly属性设置为true?_Asp.net_Gridview_Boundfield - Fatal编程技术网

Asp.net 如何将BoundField单元格中的readonly属性设置为true?

Asp.net 如何将BoundField单元格中的readonly属性设置为true?,asp.net,gridview,boundfield,Asp.net,Gridview,Boundfield,我是这样做的: 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。这行吗 if (

我是这样做的:

 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。

这行吗

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

显然,
BoundField
似乎有一个。但我现在不确定
e.Row.Cells[3]
是否为
BoundField
类型。可能您必须将其强制转换为
BoundField
没有
直接方法
Gridview列
设置为
只读

但是您可以将Gridivew的
行数据绑定
事件中该列中的
控件设置为只读。e、 g

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;
    }
}

对于绑定字段,可以假定控件(0)是所需的控件

因此,这项工作:

    Protected Sub DropDownListNoVariation_SelectedIndexChanged(sender As Object, e As EventArgs)
    Dim sourceGridViewRow As GridViewRow
    Dim sourceDropDown As DropDownList
    Dim TargetTextBox As TextBox

    sourceGridViewRow = sender.Parent.Parent
    sourceDropDown = sender
    If sourceDropDown.Text = "True" Then
        TargetTextBox = sourceGridViewRow.Cells(4).Controls(0)
        TargetTextBox.ReadOnly = True
        TargetTextBox = sourceGridViewRow.Cells(5).Controls(0)
        TargetTextBox.ReadOnly = True
    Else
        TargetTextBox = sourceGridViewRow.Cells(4).Controls(0)
        TargetTextBox.ReadOnly = False
        TargetTextBox = sourceGridViewRow.Cells(5).Controls(0)
        TargetTextBox.ReadOnly = False
    End If

End Sub

是的。但是我怎样才能改变它呢。e、 行。单元格[3]。只读不正确。