问题描述
我似乎无法在DetailsView模板字段中的多行文本框上设置ReadOnly属性,我想设置只读,直到调用编辑模式,然后在用户退出编辑模式时将其设置回来。
C#函数DetailsView2_ModeChanged被调用,因为我可以装饰DetailsView的标题就好了,我可以在调试模式中读取TextBox的属性就好了,它只是不接受任何更改? br />
任何建议表示赞赏。
I seem unable to set the ReadOnly properties on a multiline text box that I have inside a DetailsView Template field, I would like to set Read Only until Edit Mode is called then set it back when the user is out of edit mode.
The C# function DetailsView2_ModeChanged is getting called as I can decorate the header of the DetailsView just fine, I can read the properties of the TextBox in debug mode just fine, it just will not accept any change?
Any suggestions appreciated.
<form id="form1" runat="server">
<div>
<h2>
Timetable July 4th to September 25th
<asp:Label id="Label1" runat="server"/>
</h2>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetDataBySelectedRec"
TypeName="TimetableListTableAdapters.tblTimetableListTableAdapter"
UpdateMethod="UpdateQueryTimetableList">
<SelectParameters>
<asp:QueryStringParameter DefaultValue="1988" Name="lngIndex"
QueryStringField="lngIndex" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="Hide" Type="Boolean" />
<asp:Parameter Name="Formation" Type="String" />
<asp:Parameter Name="Remarks" Type="String" />
<asp:Parameter Name="Done" Type="Boolean" />
<asp:Parameter Name="Layout" Type="String" />
<asp:Parameter Name="Original_lngIndex" Type="Int32" />
</UpdateParameters>
</asp:ObjectDataSource>
<asp:DetailsView ID="DetailsView2" runat="server" AutoGenerateRows="False"
DataSourceID="ObjectDataSource1" Height="320px" Width="350px"
CssClass="DataWebControlStyle" CellPadding="3"
EmptyDataText="No Records Selected" DataKeyNames="lngIndex"
OnModeChanged="DetailsView2_ModeChanged" >
<AlternatingRowStyle CssClass="AlternatingRowStyle" />
<Fields>
<asp:BoundField DataField="lngIndex" HeaderText="Record ID:"
InsertVisible="False" SortExpression="lngIndex" ReadOnly="True" >
</asp:BoundField>
<asp:TemplateField HeaderText="Test:">
<ItemTemplate>
<asp:TextBox ID="txtTest" runat="server" CssClass="right" TextMode="MultiLine"
Text="Unbound" BorderStyle="None" Height="200px" Width="450px" BackColor="#EFF3FB" Font-Names="arial" Font-Size="8pt" ForeColor="DimGray" />
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
</Fields>
</asp:DetailsView>
</div>
</form>
======================== ==========================
==================================================
public void DetailsView2_ModeChanged(Object sender, EventArgs e)
{
if (DetailsView2.CurrentMode == DetailsViewMode.Edit)
{
DetailsView2.HeaderText = "Edit Mode";
DetailsView2.HeaderStyle.ForeColor = System.Drawing.Color.Red;
DetailsView2.HeaderStyle.BackColor = System.Drawing.Color.LightGray;
TextBox tb = DetailsView2.FindControl("txtTest") as TextBox;
String str1 = tb.Text.ToString();
((TextBox)DetailsView2.FindControl("txtTest")).BackColor = System.Drawing.Color.Red;
((TextBox)DetailsView2.FindControl("txtTest")).ReadOnly = false;
}
if (DetailsView2.CurrentMode == DetailsViewMode.ReadOnly)
{
DetailsView2.HeaderText = "Read-Only Mode";
DetailsView2.HeaderStyle.ForeColor = System.Drawing.Color.Blue;
DetailsView2.HeaderStyle.BackColor = System.Drawing.Color.White;
((TextBox)DetailsView2.FindControl("txtTest")).BackColor = System.Drawing.Color.Blue;
((TextBox)DetailsView2.FindControl("txtTest")).ReadOnly = true;
}
}
推荐答案
这篇关于我无法在DetailsView TemplateField中设置子TextBox属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!