使用下拉列表中的上一个值更新sql表中的数据 [英] update data in sql table with previous value in dropdown list

查看:46
本文介绍了使用下拉列表中的上一个值更新sql表中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hii。

我是个好人。我是开发新手。



我的问题是:



i希望使用sql表更新数据asp .net ..数据存在于asp .net网页中..此页面包含文本框和下拉列表..



一些下拉列表使用select indexchaged相互链接..当我只更新文本框值而不是这些相互关联的下拉列表..然后从数据库中清除下一个下拉值

当我没有选择下拉列表时,下拉列表中没有相互关联,数据表中的数据不清楚..



这是我的updatechild.aspx.cs



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

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给我解决方案



提前感谢..

plz give me solution

thanks in advance..

推荐答案

我刚刚有类似的项目。技巧是每次重新加载页面时都没有类变量和用户值的记忆。每次服务器收到请求时,程序都会从​​头开始,这是Web表单类的全新实例。



按钮自动将数据发送回服务器默认。而非按钮的控件默认为静态HTML。您需要将这些控件设置为AutoPostBack为真。



然后您可以将变量存储在HiddenFields中,例如ID号或非敏感数据,这样您就可以查找以前的网页的状态。



来自我的项目的片段:

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;
}


这篇关于使用下拉列表中的上一个值更新sql表中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆