Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am trying to display Ajax Rating in the DataGrid..error is "
Specified cast is not valid."
.What is the best way to use Ajax Rating in the Gridview?

What I have tried:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:iuploadConnectionString %>" 
        SelectCommand="SELECT * FROM [tb_Gallery]"></asp:SqlDataSource>
    
    <br />
    <cc1:ToolkitScriptManager ID="ToolkitScriptManager2" runat="server">
    </cc1:ToolkitScriptManager>

                <asp:GridView ID="GridView2" runat="server"
                 
                    BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" 
                    CellPadding="4"  
                    Width="69px"  
        
                   >
       
          
        
                    <Columns>
                    <%--here i am using templatefields to for binding the gridview--%>
                        <asp:TemplateField HeaderText="Album_name">
                            <EditItemTemplate>
                           
                     <%--here i am using the textbox in the edititmtemplatefield to upadate the data--%>
                                <asp:TextBox ID="txt_album_name" runat="server"
                                    Text='<%# Eval("album_name") %>'></asp:TextBox>
                                <asp:Label ID="Label4" runat="server" Text='<%# Eval("id") %>' Visible="False"></asp:Label>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%# Eval("album_name") %>'></asp:Label>
                                <asp:Label ID="Label2" runat="server" Text='<%# Eval("id") %>' Visible="False"></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Caption">
                            <EditItemTemplate>
                                <asp:TextBox ID="txt_caption" runat="server" Text='<%# Eval("caption") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label3" runat="server" Text='<%# Eval("caption") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Image">
                        <ItemTemplate>
                        <%--for displaying the image inside the gidview here i'm using the <img>tag
                        and specify the path of the folder where image is stored--%>
                        <img alt ="" src ='images/<%#Eval("image") %>' height="200px" width="200px"/>
                        </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Delete">
                        <%--here i am using the linkbutton to delete the record and specify the command name
                        of this linkbutton is delete--%>
                            <ItemTemplate>
                                <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"
                                    CommandName="Delete"
                                    onclientclick="return confirm('are you sure you want to delet this column')">Delete</asp:LinkButton>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Update">
                            <EditItemTemplate>
                           <%-- here i am using the s linkbuttons to update the record and a  cancel button
                           and set the commandname of update button is update and the cancel button is cancel --%>
                                <asp:LinkButton ID="LinkButton3" runat="server" CausesValidation="False"
                                    CommandName="Update">Update</asp:LinkButton>
                                <asp:LinkButton ID="LinkButton4" runat="server" CausesValidation="False"
                                    CommandName="Cancel">Cancel</asp:LinkButton>
                            </EditItemTemplate>
                            <ItemTemplate>
                                
                               <%--here i am using the linkbutton for edit and specify the command name
                        of this linkbutton is Edit--%>
                                <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False"
                                    CommandName="Edit">Edit</asp:LinkButton>
                            </ItemTemplate>
                        
                        </asp:TemplateField>
        <asp:TemplateField HeaderText="Rating">
            <ItemTemplate>
                <cc1:Rating ID="Rating1" AutoPostBack="true"  runat="server"
                    StarCssClass="Star" WaitingStarCssClass="WaitingStar" EmptyStarCssClass="Star"
                    FilledStarCssClass="FilledStar" CurrentRating='<%# Eval("Rating") %>'>
                </cc1:Rating>
            </ItemTemplate>
        </asp:TemplateField>
                       
                    </Columns>
                    <EditRowStyle BorderWidth="60px" Width="60px" />
                    <FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
                    <HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
                    <PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
                    <RowStyle BackColor="#999999" ForeColor="#003399" Width="70px" />
                    <SelectedRowStyle BackColor="Blue" Font-Bold="True" ForeColor="#CCFF99" 
                        BorderColor="#0066CC" />
                    <SortedAscendingCellStyle BackColor="#EDF6F6" />
                    <SortedAscendingHeaderStyle BackColor="#0D4AC4" />
                    <SortedDescendingCellStyle BackColor="#D6DFDF" />
                    <SortedDescendingHeaderStyle BackColor="#002876" />
                </asp:GridView>
   
    <cc1:Rating ID="Rating2" runat="server">
    </cc1:Rating>
    <cc1:Rating ID="Rating1" runat="server">
    </cc1:Rating>
  
   
    <asp:SqlDataSource ID="SqlDataSource3" runat="server" 
        ConnectionString="<%$ ConnectionStrings:iuploadConnectionString %>" 
        SelectCommand="SELECT * FROM [Ratings]"></asp:SqlDataSource>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900