Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
2.78/5 (2 votes)
hii.
i am anil. i am new in development.

my problem is:

i want to update data in sql table using asp .net .. the data is present in asp .net webpage.. this page contains textboxes and dropdownlist..

some of dropdown are linked each other using select indexchaged.. when i update only textbox value not these interlinked dropdown.. then the previous value of dropdown is clear from the database
when i does't select the dropdown..some of dropdown which are not interlinked,s data is not clear in database table..

it's my updatechild.aspx.cs

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Data;
using TrackDataLayer;
using TrackBusinessLogic;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.UI.WebControls;

namespace TrackWebApplication
{
    
    public partial class Update_childinfo : System.Web.UI.Page
    {
        TrackBL objTrackBL = new TrackBL();
        
       // SqlConnection connection = new SqlConnection("Data Source=SCJ-454B2938AB1\\SCJ;Integrated Security=true;Initial Catalog=SCJ");

        protected void Page_Load(object sender, EventArgs e)
        {
            //GetData();
            SqlConnection connection = new SqlConnection("Data Source=SCJ-454B2938AB1\\SCJ;Integrated Security=true;Initial Catalog=SCJ");

            // string barcodee='';
            if (!IsPostBack)
            {
                // dvMain.Visible = false;
                ViewState["CurrentPage"] = 1;
                BindAllDist();
                BindHouseholdDetail();
                BindChildDetail();
                ddlBlockName.Items.Insert(0, new ListItem("--ALL--", ""));
                ddlGP.Items.Insert(0, new ListItem("--ALL--", ""));
                ddlVillage.Items.Insert(0, new ListItem("--ALL--", ""));
                ddlHabitation.Items.Insert(0, new ListItem("--ALL--", ""));
               // lbl_barcode.Text = Request.QueryString["barcode"];

                GetData();
               
            }
        }


        private void GetData()
        {
            DataTable dt = new DataTable();
            SqlConnection connection = new SqlConnection("Data Source=SCJ-454B2938AB1\\SCJ;Integrated Security=true;Initial Catalog=SCJ");
            connection.Open();
            SqlCommand Cmd = new SqlCommand();
            // SqlCommand sqlCmd = new SqlCommand("select * from [17Family_D] where barcode=03338058", connection);
            Cmd.Connection = connection;
            Cmd.CommandType = CommandType.StoredProcedure;
            Cmd.CommandText = "spGetCHLDETAIL1";
            ////string v1 = Request.QueryString["CHILDCODE"];
            ////string v2 = Request.QueryString["DIST_ID"];
            ////sqlCmd.Parameters.AddWithValue("@barcode", v1);
            ////sqlCmd.Parameters.AddWithValue("@DistrictID", v2);

            Cmd.Parameters.AddWithValue("@barcode", Request.QueryString["BARCODE"]);
            Cmd.Parameters.AddWithValue("@DistrictID", Request.QueryString["DISTID"]);
            // SqlCommand sqlCmd = new SqlCommand("SELECT * FROM [17Family_D]", connection);


            SqlDataAdapter da = new SqlDataAdapter(Cmd);
            da.Fill(dt);
            if (dt.Rows.Count > 0)
            {

               // ddlDistricNName.Text = dt.Rows[0]["distt"].ToString();
                //lbblcde.Text = dt.Rows[0]["block"].ToString();
                //lbgpcde.Text = dt.Rows[0]["gpmctc"].ToString();
                //lbvlcde.Text = dt.Rows[0]["village"].ToString();
                //lbhbcde.Text = dt.Rows[0]["habitation"].ToString();
                ddlLocation.Text = dt.Rows[0]["location"].ToString();
                Ddlchldrsdng.Text = dt.Rows[0]["residing"].ToString();
                Ddlmthr_ton.Text = dt.Rows[0]["mother_ton"].ToString();

                 txtPINCODE.Text = dt.Rows[0]["pincode"].ToString();

                txt_HOUSE_NO.Text = dt.Rows[0]["hhno"].ToString();

                txt_FATHER.Text = dt.Rows[0]["fname"].ToString();

                txt_MOTHER.Text = dt.Rows[0]["mname"].ToString();

                txt_GUARDIAN.Text = dt.Rows[0]["gname"].ToString();

                Ddl_sclgrp.Text = dt.Rows[0]["social_grp"].ToString();
                Ddl_minority.Text = dt.Rows[0]["minority"].ToString();
                txt_ttlMAle.Text = dt.Rows[0]["total_male"].ToString();
                txt_ttlFEMAle.Text = dt.Rows[0]["total_fema"].ToString();

                Ddl_seasnl_mgrtn.Text = dt.Rows[0]["seasonal_m"].T
plz give me solution

thanks in advance..
Posted
Updated 13-Mar-14 10:44am
v2
Comments
CodeReady 13-Mar-14 8:20am    
will you please share your code.
bindash 13-Mar-14 8:25am    
--content has been moved to the question--

1 solution

I just had similar project. The trick is each time the page is reloaded it has no memory of the class variables and user values. Every time the server gets a request, the program starts again from scratch, that is a whole new instance of your Web form class.

Buttons send data back automatically to the server by default. Whereas controls which are not buttons, by default become static HTML. You need to set these controls to AutoPostBack is true.

Then you can store variables in HiddenFields such as ID number or non-sensitive data so you can look up the previous state of the web page.

snippets from my project:
if (!IsPostBack){
this.HiddenFieldStatus.Value = "no";

}
else{
//reload data using already selected values
     string status = this.HiddenFieldStatus.Value;
     
//and get input field values
     this.user = this.TextBoxUser.Text;
     this.password = this.TextBoxPW.Text;
}
 
Share this answer
 
Comments
bindash 20-Mar-14 0:58am    
please explain in detail... i did't get it..

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