1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

gridview-Get error when trying to bind, something about idatasource

Discussion in 'C#' started by Lenjaku, Aug 18, 2012.

  1. #1
    I am trying to work with gridview but it gives me the following error (on binding)
    :
    [B]Exception Details: [FONT=Arial]System.Web.HttpException: The DataSourceID of 'GridView1' must be the ID of a control of type IDataSource.  A control with ID 'grade' could not be found.[/FONT]
    [/B]
    Code (markup):
    This is my client code:
    
    <%@ Page Title="" Language="C#" MasterPageFile="~/master.Master" AutoEventWireup="true" CodeBehind="GradesDisplay.aspx.cs" Inherits="Project2012.GradesDisplay" %><asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"></asp:Content><asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">       <asp:GridView ID="GridView1" runat="server"         DataSourceID="JTutor2.grade" Height="128px" Width="305px" AllowPaging="True"         AllowSorting="True" CellPadding="4" ForeColor="#333333" GridLines="None">        <AlternatingRowStyle BackColor="White" />               <EditRowStyle BackColor="#2461BF" />        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />        <RowStyle BackColor="#EFF3FB" />        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />        <SortedAscendingCellStyle BackColor="#F5F7FB" />        <SortedAscendingHeaderStyle BackColor="#6D95E1" />        <SortedDescendingCellStyle BackColor="#E9EBEF" />        <SortedDescendingHeaderStyle BackColor="#4870BE" />    </asp:GridView>       <asp:SqlDataSource ID="SqlDataSource1" runat="server"         ConnectionString="<%$ ConnectionStrings:JTutor2 %>"                  SelectCommand="SELECT grade.User_ID, grade.Grade_date, grade.Grade_grade, Lesson.lesson_name FROM grade INNER JOIN Lesson ON grade.Lesson_ID = Lesson.ID WHERE (grade.User_ID = @user_id)">        <SelectParameters>            <asp:Parameter Name="user_id" />        </SelectParameters>    </asp:SqlDataSource>  </asp:Content>
    HTML:
    And this is my server code:
    SEMrush
    User usr=(User)Session["User"];                      
               SqlDataSource1.SelectParameters["User_id"].DefaultValue = usr.User_ID;
    Code (markup):
     
    Lenjaku, Aug 18, 2012 IP
    SEMrush
  2. alamlinks

    alamlinks Active Member

    Messages:
    982
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    90
    #2
    Check the DataSourceID in your client code. there a is big error
     
    alamlinks, Aug 31, 2012 IP