Display Updated values in another View of ASP.Net MultiView control using C# and VB.Net

Last Reply 7 months ago By dharmendr

Posted 7 months ago

I've the web form that when the user selects name from the dropdown list, the values of that name populate in the textboxes and at the same time its values show in the Review section. This part currently is working. If the user makes any edits in those texbox(es), the new edit/value(s) should be appearing in the Review section automacally . Is it possible to do that? If so, would you help how to do that? Thank you very much.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="e_preview_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">

        <asp:ScriptManager runat="server" ID='sm1' EnablePartialRendering="false"></asp:ScriptManager>

        <asp:UpdatePanel runat="server" ID='up1'>
            <ContentTemplate>
                <asp:MultiView ID="mvPeview" runat="server" ActiveViewIndex="0" EnableTheming="True">
                    <asp:View ID="vwSubmit" runat="server">
                        Select Customer Name
                        <asp:DropDownList ID="lstFullName" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
                        </asp:DropDownList>
                        <br />

                        Name: 
                        <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
                        <br />
                        Department:
                        <asp:TextBox ID="txtDepartment" runat="server"></asp:TextBox>
                        <br />                     
                        Phone:
                        <asp:TextBox ID="txtPhone" runat="server"></asp:TextBox>
                        <br />
                        Email:
                        <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
                        <br />
                        Order:
                        <asp:TextBox ID="txtOrder" runat="server"></asp:TextBox>
                        Count: <asp:TextBox ID="txtCount" runat="server"></asp:TextBox>
                        <br />
                        <hr />

                        Name: <asp:Label ID="lblName" runat="server"></asp:Label>
                        <br />                       
                        <asp:Label ID="lblDepartment" runat="server"></asp:Label>
                        <br />
                        <asp:Label ID="lblEmail" runat="server"></asp:Label></a>
                        <br />
                        <asp:Label ID="lblPhone" runat="server"></asp:Label></span>
                        <br />
                         <asp:Label ID="lblOrder" runat="server"></asp:Label> 
                        and <asp:Label ID="lblCount" runat="server"></asp:Label>
                        <br />
                    </asp:View>

                    <asp:View ID="vwResult" runat="server">
                    </asp:View>
                </asp:MultiView>

            </ContentTemplate>
        </asp:UpdatePanel>
    </form>
</body>
</html>

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.Configuration;
using System.Data.SqlClient;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using ConfigurationSettings = System.Configuration.ConfigurationManager;

public partial class e_preview_Default :  System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            lstFullName.Items.Add(new ListItem("Select CustDisplayname", ""));
            lstFullName.AppendDataBoundItems = true;

            String strConnString = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString;


            String strQuery = "SELECT *  FROM CusContactlist";
            SqlConnection con = new SqlConnection(strConnString);
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.Text;

            cmd.CommandText = strQuery;
            cmd.Connection = con;
            try
            {
                con.Open();
                lstFullName.DataSource = cmd.ExecuteReader();
                lstFullName.DataTextField = "CustDisplayname";
                lstFullName.DataValueField = "CustDisplayname";
                lstFullName.DataBind();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                con.Close();
                con.Dispose();
            }
        }
    }

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        String strConnString = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString;
        String strQuery = "SELECT * FROM CusContactlist WHERE CustDisplayname = @CustDisplayname";

        SqlConnection con = new SqlConnection(strConnString);
        SqlCommand cmd = new SqlCommand();

        cmd.Parameters.AddWithValue("@CustDisplayname", lstFullName.SelectedItem.Value);
        cmd.CommandType = CommandType.Text;
        cmd.CommandText = strQuery;
        cmd.Connection = con;
        try
        {
            con.Open();
            SqlDataReader sdr = cmd.ExecuteReader();
            while (sdr.Read())
            {
                txtName.Text = sdr["CustDisplayname"].ToString();
                txtDepartment.Text = sdr["dept_list"].ToString();
                txtEmail.Text = sdr["email"].ToString();
                txtPhone.Text = sdr["telNumber"].ToString();
                txtOrder.Text = sdr["numberOrder"].ToString();
                txtCount.Text = sdr["Count"].ToString();

                lblName.Text = sdr["CustDisplayname"].ToString();
                lblDepartment.Text = sdr["dept_list"].ToString();
                lblEmail.Text = sdr["email"].ToString();
                lblPhone.Text = sdr["telNumber"].ToString();
                txtOrder.Text = sdr["numberOrder"].ToString();
                lblCount.Text = sdr["Count"].ToString();
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            con.Close();
            con.Dispose();
        }
    }


}

 

This question does not have replies that have been liked.