databoundliteralconrtrol
キャストに使用したグリッドビュー内のリテラルからテキストを取得したい。
しかし、私がプログラムを実行すると、例外が発生します
タイプSystem.Web.UI.LiteralControlのオブジェクトをタイプSystem.Web.UI.DataBoundLiteralControlにキャストできません。 .aspxコード:
<Columns>
<asp:TemplateField HeaderText="Selection">
<ItemTemplate>
<asp:CheckBox ID="check1" runat="server"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ID" Visible="true">
<ItemTemplate>
<asp:Label ID="id7" runat="server" Text='<%#Eval("assessid") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Qno" Visible="true">
<ItemTemplate>
<asp:DropDownList AppendDataBoundItems="true" AutoPostBack="true" ID="DropDownList1" runat="server">
<asp:ListItem ></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList AutoPostBack="true" ID="DropDownList2" runat="server">
</asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="TextBox31" runat="server" ></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="description" Visible="true">
<ItemTemplate>
<asp:Literal ID="id6" runat="server" Text='<%#Eval("description") %>' >
</asp:Literal>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" Text='<%#Eval("description") %>' runat="server" ></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="TextBox3" runat="server" ></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Agree" Visible="true">
<ItemTemplate>
<asp:Literal ID="id5" runat="server" Text='<%#Eval("option1") %>' >
</asp:Literal>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox11" Text='<%#Eval("option1") %>' runat="server" ></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="TextBox4" runat="server" ></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Disagree" Visible="true">
<ItemTemplate>
<asp:Literal ID="id4" runat="server" Text='<%#Eval("option2") %>' >
</asp:Literal>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox5" Text='<%#Eval("option2") %>' runat="server" ></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="TextBox6" runat="server" ></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Strong Agree" Visible="true">
<ItemTemplate>
<asp:Literal ID="id3" runat="server" Text='<%#Eval("option3") %>' >
</asp:Literal>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox7" Text='<%#Eval("option3") %>' runat="server" ></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="TextBox8" runat="server" ></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Strong Disagree" Visible="true">
<ItemTemplate>
<asp:Literal ID="id2" runat="server" Text='<%#Eval("option4") %>' >
</asp:Literal>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox9" Text='<%#Eval("option4") %>' runat="server" ></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="TextBox10" runat="server" ></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
-%>
<%-- <EditItemTemplate>
<asp:Literal ID="id3" runat="server" Text='<%#Eval("option1") %>' >
</asp:Literal>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="disagree" Visible="true">
<EditItemTemplate>
<asp:Literal ID="id4" runat="server" Text='<%#Eval("option2") %>' >
</asp:Literal>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="strongagree" Visible="true">
<EditItemTemplate>
<asp:Literal ID="id5" runat="server" Text='<%#Eval("option3") %>' >
</asp:Literal>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="strongdisagree" Visible="true">
<EditItemTemplate>
<asp:Literal ID="id6" runat="server" Text='<%#Eval("option4") %>' >
</asp:Literal>
</EditItemTemplate>
</asp:TemplateField>--%>
<asp:TemplateField HeaderText="Action" Visible="true">
<ItemTemplate>
<asp:LinkButton ID="LinkButton5" Text="Edit" CommandName="edit" runat="server"></asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="LinkButton1" Text="update" CommandName="update" runat="server"></asp:LinkButton>
<asp:LinkButton ID="LinkButton3" Text="cancel" CommandName="cancel" runat="server"></asp:LinkButton>
</EditItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="LinkButton7" Text="DeleteAll" CommandName="delete" runat="server"></asp:LinkButton>
</FooterTemplate>
<asp:TemplateField HeaderText="" Visible="true">
<ItemTemplate>
<asp:LinkButton ID="LinkButton23" Text="delete" CommandName="delete" runat="server"></asp:LinkButton>
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="bdh" Text="insert " CommandName="insert" runat="server" />
</FooterTemplate>
</Columns>
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<SortedAscendingCellStyle BackColor="#FDF5AC" />
<SortedAscendingHeaderStyle BackColor="#4D0000" />
<SortedDescendingCellStyle BackColor="#FCF6C0" />
<SortedDescendingHeaderStyle BackColor="#820000" />
</asp:GridView>
コードビハインド
protected void RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string percentage = ((LiteralControl)e.Row.Cells[4].Controls[0]).Text;
}
}