Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8050357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:04:28+00:00 2026-06-05T07:04:28+00:00

I want to get text from literal that is inside a gridview, But when

  • 0

I want to get text from literal that is inside a gridview,

But when i run the program, exception through

Unable to cast object of type System.Web.UI.LiteralControl to type System.Web.UI.DataBoundLiteralControl.

.aspx code:

<asp:GridView ID="gridview3" runat="server" OnRowDataBound="RowDataBound" DataKeyNames="qno" AutoGenerateColumns="false"  ShowFooter="true" OnRowCancelingEdit="cancel"   OnRowCommand="create" OnRowDeleting="delete" OnRowEditing="edit" OnRowUpdating="update">

            <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>



    </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="strongagree" Visible="true">
        <EditItemTemplate>
        =

      <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>

    <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>

</asp:TemplateField>







</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>

code behind

protected void RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
       string percentage = ((LiteralControl)e.Row.Cells[2].Controls[0]).Text;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T07:04:30+00:00Added an answer on June 5, 2026 at 7:04 am

    The literal control you are getting back is probably not the one you want (there could be a Literal matching for a whitespace). Try to get it by id:

    string percentage = ((LiteralControl)e.Row.FindControl("id6").Text; 
    

    or perhaps try another index:

    string percentage = ((LiteralControl)e.Row.Cells[2].Controls[1]).Text; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get text from literal that is inside a gridview, i used
I want to get the Text property from a TextBox that is inside a
From below HTML code I want to get all the text except that in
i just want to get a text from textbox that is betwen two dots
I want to get a text from a PHP file through java j2me ,
I want to get text from elements on a page. I don't want the
I want to get text from current active line (the line where the caret
I want to get the text from an EditText, then get the length of
I want to get some text from a PHP page into an Android application.
i want to get first n words from text stored in my database without

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.