Click here to Skip to main content
15,918,967 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I use vs2010 and ms sql with (linq to sql) SP to pass p1 p2 p3 and retrieve selected data to repeater The problem is the repeater ignore p1,p2,p3 and just display all data in the movie table I have 3 tables : (Movie , Director, Movie-director)

SQL
ALTER PROCEDURE [dbo].[SelectMovie]

@P1 int ,

@P2 NVARCHAR(255) = NULL,

@P3 NVARCHAR(255) = NULL

AS

SET NOCOUNT ON

SET TRANSACTION ISOLATION LEVEL READ COMMITTED

 

SELECT Movie.Movie_ID

    ,Movie.title

    ,Movie.IMAGE

    ,Movie.actors

    ,Movie.description

    ,Director.NAME

FROM Movie

INNER JOIN Movie - director ON Movie.Movie_ID = Movie - director.Movie_ID

INNER JOIN Director ON Movie - director.Director_ID = Director.Director_ID

WHERE (title LIKE '%' + (@p1) + '%') --title has to be matched

    AND (

           (

                    actors LIKE '%' + (@p2) + '%' AND @p2 IS NOT NULL)     --match only then when @p2 is not null

        OR (

                    cat_ID = @p3 OR @p3 IS NULL          --if @p3 IS NULL then do not filter by @p3

           )

        )




ASPX:


ASP.NET
<asp:Repeater ID="Repeater1" runat="server" >

<HeaderTemplate> </HeaderTemplate>

<ItemTemplate>

    <div style="width:100%;">

        <div class="excerpt">

            <a href="movie_details.aspx?id=<%# DataBinder.Eval(Container.DataItem, "Movie_ID")%>" class="thumb" title="An image">

                <img src="<%# DataBinder.Eval(Container.DataItem, "image")%>" alt="Post" style="opacity: 1; float:left; width:80px ; height:100px; border:3px solid #fff ; margin:5px;">

            </a>

            <a href="movie_details.aspx?id=<%# DataBinder.Eval(Container.DataItem, "Movie_ID")%>" class="header">

                <h6>

                    <%# DataBinder.Eval(Container.DataItem, "title")%>

                    ( <%# DataBinder.Eval(Container.DataItem, "actors")%>)

                </h6>

            </a>

            <div style="padding:5px;">

                <%# DataBinder.Eval(Container.DataItem, "description")%>

            </div> 

            <div style="padding:5px;">

                <%# DataBinder.Eval(Container.DataItem, "name")%>

            </div>

        </div>

    </div>

    <br />

    <hr />

</ItemTemplate>
</asp:Repeater>



C# code

C#
CDTDataContext dc = new CDTDataContext();

protected void Page_Load(object sender, EventArgs e)

{

        if (!IsPostBack){ }

}

protected void Button1_Click(object sender, EventArgs e)

{

    string Cat_ID = DropDownList1.SelectedValue;

    string keyword1 = TextBox2.Text;

    string keyword2 = TextBox3.Text;

    int? cid = int.Parse(cat_id);

    Repeater1.DataSource = dc.SelectMovie(keyword1, keyword2, cid);

    Repeater1.DataBind();

}
Posted
Comments
sky.seaman 10-Apr-13 3:17am    
I used sqldatasurce with repeater and the repeater display the result (but with no image).
but when i use C# code the repeater doesn't display any data??????

so is the problem in the c# code????

1 solution

I mean you must edit parameter in query

SQL
@P1 int ,
 
@P2 NVARCHAR(255) = NULL,
 
@P3 NVARCHAR(255) = NULL



Don't put NULL in Parameter @P2 and @P3

Like this
SQL
@P1 int ,
 
@P2 NVARCHAR(255),
 
@P3 NVARCHAR(255)
 
Share this answer
 
v3

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