Gridview控件在rowdatabound中被禁用,但以后不显示相同的设置
我正在根据某些条件禁用gridview中的Gridview控件在rowdatabound中被禁用,但以后不显示相同的设置,gridview,textbox,c#-2.0,Gridview,Textbox,C# 2.0,我正在根据某些条件禁用gridview中的文本框 稍后,当我遍历griview时,当我选中TextBox.Enabled属性时,它显示为true。然而,对于那一行,我将其设置为false 此代码在rowdatabound事件中 我只是发布了与问题相关的代码 TextBox txt_location = (TextBox)e.Row.Cells[htDGV_Map["Trailer's Last Location"]].FindControl("txt_location"); string
文本框
稍后,当我遍历griview
时,当我选中TextBox.Enabled属性时,它显示为true。然而,对于那一行,我将其设置为false
此代码在rowdatabound事件中
我只是发布了与问题相关的代码
TextBox txt_location = (TextBox)e.Row.Cells[htDGV_Map["Trailer's Last Location"]].FindControl("txt_location");
string remark_status = "";
string status = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "SHIP_TRAIL_STATUS"));
if (status.Equals("L"))
remark_status = "REMARK_POSTMARCH";
else
remark_status = "REMARK_REACH";
if (remark_status.Equals("REMARK_REACH"))
{
txt_location.ReadOnly = true;
}
TextBox txt_location=(TextBox)e.Row.Cells[htDGV_Map[“拖车的最后位置”].FindControl(“txt_位置”)
字符串备注_status=“”;
字符串状态=Convert.ToString(datainder.Eval(例如Row.DataItem,“SHIP\u TRAIL\u status”)
如果(状态等于(“L”))
备注_status=“备注_POSTMARCH”;
其他的
备注_status=“备注_REACH”
如果(备注:状态等于(“备注:到达”))
{
txt_location.ReadOnly=true;
}
稍后,我将尝试访问此属性的值
文本框txt_loc=
(文本框)Gridrow.Cells[htDGV_Map[“跟踪拖车
位置”].FindControl(“txt_位置”)
如果(txt_loc.ReadOnly==true)
{
//其他代码
}
这里的属性是假的,尽管我希望它是真的。
我试图使用TextBox
的ReadOnly
属性,但即使在这里,当我期望它为真时,也发现ReadOnly
属性为假。在RowDataBound事件中为控件应用自定义设置时,需要注意的一点是,如果页面进行回发,除非重新绑定GridView,否则自定义设置将丢失
可能的解决方法是,确保每次回发时始终重新绑定GridView,或者在PreRender事件中应用Enabled/ReadOnly设置,迭代数据行,但随后还需要将SHIP_TRAIL_状态存储在某个位置(隐藏字段)在RowDataBound期间,以便您可以在PreRender中访问它-ViewState将确保存储的值在回发期间保持静态。您可以在此处发布代码吗?
TextBox txt_loc =
(TextBox)Gridrow.Cells[htDGV_Map["Tracking Trailers
Locations"]].FindControl("txt_location");
if(txt_loc.ReadOnly == true)
{
// other code
}
Here the property comes as false, although I am expecting it to be true.