使Detailview字段不可见和可访问
本文关键字:访问 Detailview 字段 | 更新日期: 2023-09-27 18:06:18
我有一个databounddetailsviewcontrol。用于显示一些问题和答案选项以及正确答案
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px"
CellPadding="3" DataSourceID="SqlDataSource1" GridLines="Vertical"
Height="50px" Width="477px" ForeColor="Black">
<AlternatingRowStyle BackColor="#CCCCCC" />
<EditRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<Fields>
<asp:BoundField DataField="Question" HeaderText="Question"
SortExpression="Question" />
<asp:BoundField DataField="Answer 1" HeaderText="Answer 1"
SortExpression="Answer 1" />
<asp:BoundField DataField="Answer 2" HeaderText="Answer 2"
SortExpression="Answer 2" />
<asp:BoundField DataField="Answer 3" HeaderText="Answer 3"
SortExpression="Answer 3" />
<asp:BoundField DataField="Answer 4" HeaderText="Answer 4"
SortExpression="Answer 4" />
<asp:BoundField DataField="Correct Answer" HeaderText="Correct"
SortExpression="Correct Answer" >
<FooterStyle BorderColor="White" />
</asp:BoundField>
<asp:BoundField DataField="Id" SortExpression="Id" />
</Fields>
<FooterStyle BackColor="#CCCCCC" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
</asp:DetailsView>
但是我想对用户隐藏正确的答案字段,我试图使CorrectAnswer字段对设计师不可见,我成功了,但我的问题是当我试图读取不可见字段
的值时a.CorrectAnswer = DetailsView1.Rows[5].Cells[1].Text;
我从不可见的详细信息视图字段
获得空字符串作为值谁能建议任何方法使一个字段不可见,但保持值可访问的代码后面
设置CssClass
为invisible
CssClass="invisible"
并创建ivisible CSS类:
.invisible {
display:none;
}