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]。只读不正确。