shivani.corp 0 Newbie Poster

I have created one form named newest_receipe.aspx in which i have various receipes name with respective date and time in a data list and receipe names are displayed using hyperlink.

<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1"
        onselectedindexchanged="DataList1_SelectedIndexChanged">
        <ItemTemplate>
              <asp:HyperLink ID="HyperLink20" runat="server" Font-Underline="True" 
                ForeColor="#0000CC" 
                onload="HyperLink20_Load"> <%# Eval("recipe_name") %>  </asp:HyperLink>

 <asp:Label ID="datetimeLabel" runat="server" Text='<%# Eval("datetime") %>' />
            <br />

        </ItemTemplate>
    </asp:DataList>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
        SelectCommand="SELECT [recipe_name], [datetime] FROM [recipe_details] ORDER BY [datetime] DESC">
    </asp:SqlDataSource>

Now i want that when i click any one receipe name ,its all details(receipe name,ingredients,instructions) should be displayed on another form named receipe_desc.aspx

for this i tried below code
coding on newest_receipe.aspx

protected void HyperLink20_Load(object sender, EventArgs e)
{
Session["h1"] = Eval("recipe_name");
Response.Redirect("receipedesc.aspx");
}

and on receipe_desc.aspx

 SqlCommand comm;
SqlConnection conn;
SqlDataReader reader;
protected void Page_Load(object sender, EventArgs e)
{
    conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=E:\project\App_Data\Receipe.mdf;Integrated Security=True;User Instance=True");


    comm = new SqlCommand("SELECT recipe_name " + "WHERE recipe_name= @recipe_name", conn);
    comm.Parameters.Add("@recipe_name", System.Data.SqlDbType.NVarChar,50);
    comm.Parameters["@recipe_name"].Value = Session["h1"];

        try
        {
            conn.Open();
            reader = comm.ExecuteReader();
            if (reader.Read())
            {

                txtreceipeid.Text = reader["recipe_id"].ToString();
                txtreceipename.Text = reader["recipe_name"].ToString();
            }
            reader.Close();

        }
        catch
        {
        }

}

}

Hope u understood what i actually want

now error i am getting is
databinding methods such as Eval() can only be used in context of databound control..

what should i use instead

receipe_desc.aspx
protected void HyperLink20_Load(object sender, EventArgs e)
{
Session["h1"] = Eval("recipe_name");
Response.Redirect("receipedesc.aspx");
}

even i tried to use coding as
protected void HyperLink20_Load(object sender, EventArgs e)
{
Session["h1"] = HyperLink20.Text;
Response.Redirect("receipedesc.aspx");
}

Pls give your support on this

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.