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();
}
samba sivaRank #2,921 · 488 pointsPosted Aug 13, 2015, 10:34 PM EDT
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"); }protected void Page_Load(object sender, EventArgs e) { var obj = Session["Obj"]; }