Skip to content

How to navigate datalist values on second page

Nitin Sharma

Asked Aug 11, 2015, 2:36 AM EDT1 answer
Share
LinkedInX
i have use a datalist in asp.net and c#, it is fatch all value from database, but i wanted when user click any item only those items details navigate to second page , above is my code it is moving only first row value but what about if user select 2nd value
datalise code:
BorderStyle="None" BackColor="White" BorderColor="#E7E7FF" BorderWidth="0px"
DataKeyField="pid" GridLines="Horizontal"
onitemcommand="DataList1_ItemCommand"
onselectedindexchanged="DataList1_SelectedIndexChanged">
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
DynamicServicePath="" Enabled="True" ExtenderControlID=""
TargetControlID="Image1" PopupControlID="Panel3">
Font-Size="XX-Large" Text='<%# Eval("pname") %>' onclick="lbpname4_Click">
 
 
 

Seller's Name 


Contect Details  


Email id  



<SelectedItemStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
and this is logical code :
TypeScript
  protected void lbpname4_Click(object sender, EventArgs e)
    {
        SqlCommand cmd = new SqlCommand("Select * from AddPost", con);
        con.Open();
        SqlDataReader dr = cmd.ExecuteReader();
        while (dr.Read())
        {

                Session["pname"] = dr["pname"];
                Response.Redirect("Cate.aspx");
        }
        con.Close();
    }

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • samba siva
    0
    Hi Nitin, 
    You can get the all values like bellow code.
     
    Java
     protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
            {
                int ID = Convert.ToInt32(e.CommandArgument);
                Label lblCName = (Label)e.Item.FindControl("lblCName");
                Label lblName = (Label)e.Item.FindControl("lblName");
                Label lblCity = (Label)e.Item.FindControl("lblCity");
                var obj = new ArrayList();
                obj.Add(ID);
                obj.Add(lblCName.Text);
                obj.Add(lblName.Text);
                obj.Add(lblCity.Text);
                Session["Obj"] = obj;
                Response.Redirect("Popup.aspx");
            }
     
     
    Popup page load:
     
    C#
    protected void Page_Load(object sender, EventArgs e)
            {
                var obj = Session["Obj"];
            }
    You can get all selected values .
    0