Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

XML
<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>
              
&nbsp;<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
C#
protected void HyperLink20_Load(object sender, EventArgs e)
    {
         Session["h1"] = Eval("recipe_name");
        Response.Redirect("receipedesc.aspx");
    }



and on receipe_desc.aspx

HTML
 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
XML
<pre lang="cs">protected void HyperLink20_Load(object sender, EventArgs e)
    {
         Session["h1"] = Eval("recipe_name");
        Response.Redirect(&quot;receipedesc.aspx&quot;);
    }</pre>


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



Pls give your support on this
Posted

1 solution

Try DataBinder.Eval() instead.
 
Share this answer
 
Comments
shivani 2013 17-Apr-12 0:13am    
What should be written in parameters of eval as it is asking about eval(object container,string expression)?????
ZurdoDev 17-Apr-12 7:49am    
DataBinder.Eval (Container.DataItem, "recipe_name")
shivani 2013 17-Apr-12 12:06pm    
nothing working out........
ZurdoDev 17-Apr-12 12:11pm    
What is the error now?
shivani 2013 17-Apr-12 13:09pm    
in DataBinder.Eval (Container.DataItem, "recipe_name")
error is Container does not exist

Have you understood my case...i mean what i want in this code can be done through sessions or can be done through any other means

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