sharanya
sharanya

Reputation: 15

Error: too many characters in character literal asp.net

I'm getting this error while binding data to data list too many characters in character literal asp.net

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="android.aspx.cs" Inherits="finalproject.android" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <style type="text/css">
.style1
{
    width:900px;
}
.style2
{
    width:633px;
    text-align:left;
}
.style4
{
    width:185px;
    text-align:center;
}
</style>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <asp:DataList ID="DataList1" runat="server" DataKeyField="modelid" 
        style="text-align: center; color: #333333;" RepeatColumns="3"
        Width="283px" DataSourceID="SqlDataSource2" CellPadding="3" 
    BackColor="White" BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" 
    CellSpacing="1" >
        <FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
        <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
        <ItemStyle BackColor="#DEDFDE" ForeColor="Black" />
        <ItemTemplate>
            <br />
            <div align="left"></div>
            <table cellspacing="1" class="style4" style="border:1px ridge #9900FF">
                <tr>
                    <td style="border-bottom-style:ridge; border-width: 1px; border-color: #000000">
                        <asp:Label ID="Label1" runat="server" Text="<%# Eval('brand') %>"></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:ImageButton ID="ImageButton1" runat="server" Height="252px"
                            ImageUrl="<%# Image %>" style="margin-left: 0px" />
                    </td>
                </tr>
                <tr>
                    <td>
                        ModelID<asp:Label ID="Label2" runat="server" Text="<%# Eval('modelid') %>"></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" 
                            CommandArgument="<%# Bind('ModelID') %>" Text="Add to Cart" Width="100%" BorderColor="Black" BorderStyle="Inset" BorderWidth="1px" />
                    </td>
                </tr>
            </table>
            <br />
        </ItemTemplate>
        <SelectedItemStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
    </asp:DataList>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
    ConnectionString="<%$ ConnectionStrings:VISHConnectionString2 %>" 
    SelectCommand="SELECT [Image], [modelid], [brand] FROM [adddetails]">
</asp:SqlDataSource>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <table align="left" class="style2">
                <tr>
                    <td>
                        <asp:Label ID="Label3" runat="server" style="color: #333333"></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td>
                        &nbsp;</td>
                </tr>
                <tr>
                    <td>
                        &nbsp;</td>
                </tr>
                <tr>
                    <td>
                        &nbsp;</td>
                </tr>
            </table>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>

I'm getting this error while binding data to data list too many characters in character literal asp.net

Upvotes: 1

Views: 13319

Answers (3)

Anjali
Anjali

Reputation: 1

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="android.aspx.cs" Inherits="finalproject.android" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <style type="text/css">
.style1
{
    width:900px;
}
.style2
{
    width:633px;
    text-align:left;
}
.style4
{
    width:185px;
    text-align:center;
}
</style>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <asp:DataList ID="DataList1" runat="server" DataKeyField="modelid" 
        style="text-align: center; color: #333333;" RepeatColumns="3"
        Width="283px" DataSourceID="SqlDataSource2" CellPadding="3" 
    BackColor="White" BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" 
    CellSpacing="1" >
        <FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
        <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
        <ItemStyle BackColor="#DEDFDE" ForeColor="Black" />
        <ItemTemplate>
            <br />
            <div align="left"></div>
            <table cellspacing="1" class="style4" style="border:1px ridge #9900FF">
                <tr>
                    <td style="border-bottom-style:ridge; border-width: 1px; border-color: #000000">
                        <asp:Label ID="Label1" runat="server" Text="<%# Eval('brand') %>"></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:ImageButton ID="ImageButton1" runat="server" Height="252px"
                            ImageUrl="<%# Image %>" style="margin-left: 0px" />
                    </td>
                </tr>
                <tr>
                    <td>
                        ModelID<asp:Label ID="Label2" runat="server" Text="<%# Eval('modelid') %>"></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" 
                            CommandArgument="<%# Bind('ModelID') %>" Text="Add to Cart" Width="100%" BorderColor="Black" BorderStyle="Inset" BorderWidth="1px" />
                    </td>
                </tr>
            </table>
            <br />
        </ItemTemplate>
        <SelectedItemStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
    </asp:DataList>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
    ConnectionString="<%$ ConnectionStrings:VISHConnectionString2 %>" 
    SelectCommand="SELECT [Image], [modelid], [brand] FROM [adddetails]">
</asp:SqlDataSource>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <table align="left" class="style2">
                <tr>
                    <td>
                        <asp:Label ID="Label3" runat="server" style="color: #333333"></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td>
                        &nbsp;</td>
                </tr>
                <tr>
                    <td>
                        &nbsp;</td>
                </tr>
                <tr>
                    <td>
                        &nbsp;</td>
                </tr>
            </table>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>

Upvotes: 0

mausworks
mausworks

Reputation: 1625

"too many characters in character literal" is caused by having a char-literal with too many characters in it.

You have probably mixed up the '-character and the "-character.

The error probably lies in your "android.aspx.cs"-file rather than the .aspx-file that you have provided.

Could you provide the code for that as well?

Well, your problems are right here:

<%# Bind('ModelID') %>

Replace your single-quotes with double-quotes and you will be golden!

<%# Bind("ModelID") %>

Same goes for all your Evals/Binds

Also see these questions:

Why I'm getting CS1012: "Too many characters in character literal" and CS0019?

Too many characters in character literal?

Upvotes: 5

Tarik
Tarik

Reputation: 11209

I think the origin of the error is:

Eval('brand')

It tries to convert brand to a character and fails with that error.

Upvotes: 1

Related Questions