Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Datalist not rebinding

Datalist not rebinding

Scheduled Pinned Locked Moved ASP.NET
designsecurityhelpworkspace
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    acodman
    wrote on last edited by
    #1

    Hi Guys, can anyone help me with with my code. i have a datalist and some textfield with a button to submit. once submitted, the page should rebind it'self, but it seems not working. see my code below: using System; using System.Data; using System.Data.SqlClient; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class mssgboard_Messageboard : System.Web.UI.Page { SqlConnection datalistconn; SqlDataReader datalistdr; SqlCommand datalistcmd; SqlConnection conn; //SqlDataReader dr; SqlCommand cmd; void Bindata() { try { datalistconn = new SqlConnection(ConfigurationManager.ConnectionStrings["CmsDb"].ConnectionString); datalistcmd = new SqlCommand("SELECT nam,phone_number,email,comments FROM tbl_mssgboard ORDER BY refid DESC", datalistconn); datalistconn.Open(); datalistdr = datalistcmd.ExecuteReader(); if (datalistdr.Read()) { DataList1.DataSource = datalistdr; DataList1.DataBind(); } } catch (Exception exc) { Response.Write(exc.Message); } finally { datalistdr.Close(); datalistconn.Close(); } } protected void Page_Load(object sender, EventArgs e) { Bindata(); } protected void btnsubmit_Click(object sender, EventArgs e) { try { conn = new SqlConnection(ConfigurationManager.ConnectionStrings["CmsDb"].ConnectionString); cmd = new SqlCommand("INSERT INTO tbl_mssgboard(nam,phone_number,email,comments) VALUES(@nam,@phone_number,@email,@comments)", conn); cmd.Parameters.Add("@nam", SqlDbType.VarChar,50); cmd.Parameters.Add("@phone_number", SqlDbType.VarChar, 50); cmd.Parameters.Add("@email", SqlDbType.VarChar, 50); cmd.Parameters.Add("@comments", SqlDbType.VarChar, 50); cmd.Parameters["@nam"].Value = this.txtname.Text; cmd.Parameters["@phone_number"].Value = this.txtphone.Text; cmd.Parameters["@email"].Value = this.txtemail.Text; cmd.Parameters["@comments"].Value = this.txtcomments.Text; conn.Open(); cmd.ExecuteNon

    S 1 Reply Last reply
    0
    • A acodman

      Hi Guys, can anyone help me with with my code. i have a datalist and some textfield with a button to submit. once submitted, the page should rebind it'self, but it seems not working. see my code below: using System; using System.Data; using System.Data.SqlClient; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class mssgboard_Messageboard : System.Web.UI.Page { SqlConnection datalistconn; SqlDataReader datalistdr; SqlCommand datalistcmd; SqlConnection conn; //SqlDataReader dr; SqlCommand cmd; void Bindata() { try { datalistconn = new SqlConnection(ConfigurationManager.ConnectionStrings["CmsDb"].ConnectionString); datalistcmd = new SqlCommand("SELECT nam,phone_number,email,comments FROM tbl_mssgboard ORDER BY refid DESC", datalistconn); datalistconn.Open(); datalistdr = datalistcmd.ExecuteReader(); if (datalistdr.Read()) { DataList1.DataSource = datalistdr; DataList1.DataBind(); } } catch (Exception exc) { Response.Write(exc.Message); } finally { datalistdr.Close(); datalistconn.Close(); } } protected void Page_Load(object sender, EventArgs e) { Bindata(); } protected void btnsubmit_Click(object sender, EventArgs e) { try { conn = new SqlConnection(ConfigurationManager.ConnectionStrings["CmsDb"].ConnectionString); cmd = new SqlCommand("INSERT INTO tbl_mssgboard(nam,phone_number,email,comments) VALUES(@nam,@phone_number,@email,@comments)", conn); cmd.Parameters.Add("@nam", SqlDbType.VarChar,50); cmd.Parameters.Add("@phone_number", SqlDbType.VarChar, 50); cmd.Parameters.Add("@email", SqlDbType.VarChar, 50); cmd.Parameters.Add("@comments", SqlDbType.VarChar, 50); cmd.Parameters["@nam"].Value = this.txtname.Text; cmd.Parameters["@phone_number"].Value = this.txtphone.Text; cmd.Parameters["@email"].Value = this.txtemail.Text; cmd.Parameters["@comments"].Value = this.txtcomments.Text; conn.Open(); cmd.ExecuteNon

      S Offline
      S Offline
      Saksida Bojan
      wrote on last edited by
      #2

      datalistconn is declared as global. When postback, Excepton Occours, becase you can't open SqlConnection if it is already opend

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups