Click here to Skip to main content
15,892,199 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
hi all
since last a few days i am trying to pass values from from a datalist to panel let me explain a bit more
i have a datalist which contains some initial info of an item and a detail link button which should display values or data of selected id on a panel which is outside the datalist on the same page
i know how to pass values from a datalist to another page which is some thing like this
C#
protected void datalist_ItemCommand(object source, datalistCommandEventArgs e)
    {
        if (e.CommandName == "details")
        {
            Response.Redirect("./Repeater_DataSource.aspx?house_id=" + e.CommandArgument);

        }
    }

but dont know how can i pass values from datalist to panel outside the datalist on same page i will deeply appreciate if some one come up with an exampple
thanks
Posted

C#
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "Select")
        {
            string id = e.CommandArgument.ToString();
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["yourconnection"].ConnectionString);
            con.Open();
            SqlCommand com = new SqlCommand("select * from homes where id=" + id, con);
            SqlDataAdapter da = new SqlDataAdapter(com);
            DataSet ds = new DataSet();
            da.Fill(ds);
            childdatalist.DataSource = ds.Tables[0];
            childdatalist.DataBind();

        }
    }
 
Share this answer
 
Comments
mehdilahori 25-May-12 7:43am    
hi sivasankari
thanks this was the line i was looking for
string id = e.CommandArgument.ToString();
i have not tested this but i think this will solve my problem
i am in lahore so i will be without power from 5 to 6 pm
i will come back to you as soon as possible
thanks once again
mehdilahori 26-May-12 6:35am    
hi sivasankari
i tested your solution which was 100% correct
thanks
C#
if (e.CommandName == "details")
        {
            Response.Redirect("./Repeater_DataSource.aspx?house_id=" + e.CommandArgument.ToString());

        }



And in the next page get the id value from the query string.Then pass this id as a parameter to get the values.
 
Share this answer
 
v2
Comments
mehdilahori 25-May-12 6:46am    
but i do not want to go to next page i want show details of an particular id on another datalist but want to be in same page right now what i am trying in second datalist which shows detailed info it is
select * from homes where e.commandname="details"
but getting an error
what should i put in where clause
thanks
sivasankari ts 25-May-12 6:59am    
Its better to have detailsview for fetching the values.Pls explain your requirements clearly
mehdilahori 25-May-12 7:13am    
ok let me explain once again
i have two datalists on same page
parendl and childdl
parentdl has some initial info of all the records having a view details button when user clicks on view details button of an particular record then all the info of that record clicked should be display on child datalist
i hope this clears some confusion
thanks
HTML
<a href='<%# Eval("house_id","~/foldername/Repeater_DataSource.aspx?house_id={0}")%>'>
"your Iteltem Here Like Imge button "
<a>
 
Share this answer
 
v2

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