Posted: 12/3/2011
hi
i have a problem in my code, i am trying to read records from database and beside each record i want to place a button which redirecting me to another page , i want this button to send also the id of the record besides it but the problem is that it sends the id of the last record always.
here is the code
if (!Page.IsPostBack) { string connectionString = WebConfigurationManager.ConnectionStrings["mokattam"].ConnectionString; SqlConnection con = new SqlConnection(connectionString); try { con.Open(); SqlCommand cmd = new SqlCommand("SELECT subject, body, id FROM complains", con); cmd.ExecuteScalar(); SqlDataReader dr = cmd.ExecuteReader(); int i = 0; while (dr.Read()){ AccordionPane ap = new AccordionPane(); Button b = new Button(); ap.ID = "ap" + i; b.ID = "b" + i; b.Text = "Reply"; string url = "reply.aspx?id=" + Session["id"]; b.PostBackUrl = url; ap.HeaderContainer.Controls.Add(new LiteralControl(dr["subject"].ToString())); ap.ContentContainer.Controls.Add(new LiteralControl(dr["body"].ToString())); ap.ContentContainer.Controls.Add(new LiteralControl("</br>")); ap.ContentContainer.Controls.Add(b); Accordion1.Panes.Add(ap); i++; } dr.Close(); } catch (Exception err) { Response.Write(err.Message); } finally { con.Close(); } } }
Posted: 1/10/2012
where did you assign the value for your session?
Posted: 2/20/2012
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click Response.Redirect("DesiredPage.aspx?id=" + Session("UserID")) End Sub
Posted: 3/19/2012
Why u r not using
string url = "reply.aspx?id=" + dr["id"].ToString();
instead of
string url = "reply.aspx?id=" + Session["id"];
I think It will work as u need.